Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Desaturation/grayscale shader for iOS?

Discussion in 'Shaders' started by mudloop, Mar 16, 2011.

  1. mudloop

    mudloop

    Joined:
    May 3, 2009
    Posts:
    1,107
    Hi,

    I'm looking for a way to desaturate sprites on iOS (without having to include grayscale versions of my texture atlasses).
    It doesn't have to be fade-able, just something I can turn on or off in the material.

    I know there's a grayscale effect but the way I understand it, this is for the entire camera, and I don't even know if this will work on iOS at all.

    Thanks!
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    fullscreen effects work fine, given they don't use Depth Mode rendertextures (DOF and a few other effects)

    But yes it would be the whole screen.
     
  3. Frank Oz

    Frank Oz

    Joined:
    Oct 13, 2010
    Posts:
    1,560
    You should be able to do that with some combination of color and texture in a custom shader, not sure which thing to use though. Bet you could do it easily with SSE and experimenting with various nodes instead of using multiply or add.
     
  4. mudloop

    mudloop

    Joined:
    May 3, 2009
    Posts:
    1,107

    Would that work on just one camera?
    I'd prefer to do it with a shader, but I guess it might be an option to work with two camera's, and use one for the grayed out stuff.
     
  5. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    would work.

    But for your case a simple diffuse alike shader that gets the hue of the color when assigning it instead of assigning the real color is easier, thats a one liner. (basically o.diffuse = (color.r+color.b+color.g) / 3.0; in its simplest form)

    the only requirement, but thats with fullscreen effect granted anyway, is that its for a platform where real shaders work (desktop, mobile on opengl es 2.0)


    Strumpy Shader Editor might even have a node for this otherwise with above formula its easy to do it yourself :)
     
    GongYooMin likes this.
  6. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    The UnityCG.glslinc includes a Luminance function, which will convert colour to greyscale.

    Shouldn't be hard to plug that into a shader?

    Code (csharp):
    1.  
    2. // Converts color to luminance (grayscale)
    3. float Luminance( vec3 c )
    4. {
    5.     return dot( c, vec3(0.22, 0.707, 0.071) );
    6. }
    7.  
     
  7. mudloop

    mudloop

    Joined:
    May 3, 2009
    Posts:
    1,107
    Thanks for the tips, but I have a really limited knowledge on making shaders... So if anyone can make me one that works on all iOS versions (so not just opengles2) I am willing to paypal you $15 for your efforts :)
     
  8. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    its impossible to make it for OpenGL ES 1.1 / Fixed Function on desktop as you can not impact how the pixel are drawn aside of the blending, there you need to have the graphics in grayscale be it by storing it in grayscale from the start or have a script that takes the texture, modifies the pixel data and applies (-> so no compression and texture must be set to have get / set pixels) after loading
     
  9. mudloop

    mudloop

    Joined:
    May 3, 2009
    Posts:
    1,107
    Ok, too bad. In that case I guess I'll just have to create some extra textures. Thanks!
     
  10. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Don't do that! It works just fine on all iOS hardware; you've just got to finagle the numbers:

    Code (csharp):
    1. Shader "RGB -> Grey Texture" {
    2.    
    3. Properties {
    4.     _MainTex ("Texture", 2D) = ""
    5. }
    6.  
    7. SubShader {Pass {
    8.     GLSLPROGRAM
    9.     varying mediump vec2 uv;
    10.    
    11.     #ifdef VERTEX
    12.     void main () {
    13.         gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    14.         uv = gl_MultiTexCoord0.xy;
    15.     }
    16.     #endif
    17.    
    18.     #ifdef FRAGMENT
    19.     uniform lowp sampler2D _MainTex;
    20.     void main () {
    21.         gl_FragColor = vec4(
    22.             vec3(dot(texture2D(_MainTex, uv).rgb, vec3(.222, .707, .071)) ), 1);
    23.     }
    24.     #endif
    25.     ENDGLSL
    26. }}
    27.  
    28. SubShader {Pass {
    29.     Color (.389, .1465, .4645., .5)
    30.     SetTexture[_MainTex] {Combine one - texture * primary alpha}
    31.     SetTexture[_] {Combine previous Dot3 primary}
    32. }}
    33.  
    34. }
     

    Attached Files:

    Last edited: May 16, 2012
    UnityLighting likes this.
  11. rocket5tim

    rocket5tim

    Joined:
    May 19, 2009
    Posts:
    242
    Hey Jessy, this is just what I was looking for. Thanks for posting the shader! :)
     
  12. TedBrown

    TedBrown

    Joined:
    Aug 6, 2011
    Posts:
    16
    Just a late reply from more than a year later... Jessy, this is an amazing productivity coup you've delivered, thank you very much!
     
    Jessy likes this.
  13. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    You probably can do grayscale with fixed function shader simply by putting a second texture into the pipeline. The second texture should contain pixels whose colors match the three grayscale conversion values for red green and blue, then just multiply that texture by a graphical texture. It'll convert to grayscale?
     
  14. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Or, as Jessy has posted, just give it a colour (vector) of those values you can dot3 against ;)
     
  15. zeroc

    zeroc

    Joined:
    Jan 6, 2012
    Posts:
    2
    Hi Jessy,

    Thanks for the shader.
    There is still one question.
    How can we keep the alpha values from the source texture?
     
  16. zeroc

    zeroc

    Joined:
    Jan 6, 2012
    Posts:
    2
    We are making a function that when you can't build something, the items are grayscale masked.
    Is there any easy way to do this?
    Any help is greatly appreciated.
     
  17. pset

    pset

    Joined:
    Jan 9, 2013
    Posts:
    2
    Hi all.

    It's possible to keep the alpha values from the source texture using this shader modification:

    Code (csharp):
    1.  
    2. Shader "RGB -> Grey Texture"
    3. {
    4.     Properties
    5.     {
    6.         _MainTex ("Texture", 2D) = ""
    7.     }
    8.  
    9.     SubShader
    10.     {
    11.         Blend SrcAlpha OneMinusSrcAlpha
    12.  
    13.         Pass
    14.         {
    15.             Color(.389, .1465, .4645, 0.5)
    16.             SetTexture[_MainTex] {Combine one - texture * primary alpha}
    17.             SetTexture[_] {Combine previous Dot3 primary}
    18.             SetTexture[_MainTex] {Combine previous, texture alpha}
    19.         }
    20.     }
    21. }
    22.  
     
  18. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I only used a fixed function subshader for OpenGL ES 1 devices with two texture stages. You should be able to do this shader in two texture stages, but either Unity is buggy or my GPU drivers are, because it won't yield consistent results with only two stages. Fortunately, I think bothering with fixed function is worthless at this point, I'd go Cg. The compiled GLSL is good enough that I wouldn't bother with a handwritten GLSL subshader, for this.

    Code (csharp):
    1. Shader "RGB -> Grey Texture/Alpha Blended" {
    2.  
    3. Properties{
    4.     _MainTex ("Texture", 2D) = ""
    5. }
    6.  
    7. Subshader {
    8.     Tags {"Queue"="Transparent"}
    9.     ZWrite Off
    10.     Blend SrcAlpha OneMinusSrcAlpha
    11.     Pass {
    12.         CGPROGRAM
    13.         #pragma vertex vert
    14.         #pragma fragment frag
    15.         struct v2f {
    16.             float4 position : SV_POSITION;
    17.             float2 uv_mainTex : TEXCOORD;
    18.         };
    19.        
    20.         uniform float4 _MainTex_ST;
    21.         v2f vert(float4 position : POSITION, float2 uv : TEXCOORD0) {
    22.             v2f o;
    23.             o.position = mul(UNITY_MATRIX_MVP, position);
    24.             o.uv_mainTex = uv * _MainTex_ST.xy + _MainTex_ST.zw;
    25.             return o;
    26.         }
    27.        
    28.         uniform sampler2D _MainTex;
    29.         fixed4 frag(float2 uv_mainTex : TEXCOORD) : COLOR {
    30.             fixed4 mainTex = tex2D(_MainTex, uv_mainTex);
    31.             fixed4 fragColor;
    32.             fragColor.rgb = dot(mainTex.rgb, fixed3(.222, .707, .071));
    33.             fragColor.a = mainTex.a;
    34.             return fragColor;
    35.         }
    36.         ENDCG
    37.     }
    38. }
    39.  
    40. }
     
    CarterG81 likes this.
  19. nilesh410451

    nilesh410451

    Joined:
    Aug 22, 2012
    Posts:
    4
    I used the above shader for the ios.Its working find on all the IOS devices,But it is not working on android devices.So please help me to support on android devices
     
  20. pset

    pset

    Joined:
    Jan 9, 2013
    Posts:
    2
    Sorry, my previous modification realy was not good.
    At last was succeeded to get workable subshader for Android GLES 1.x:

    Code (csharp):
    1.  
    2. Shader "RGB -> Grey Texture"
    3. {
    4.     Properties
    5.     {
    6.         _MainTex ("Texture", 2D) = ""
    7.     }
    8.  
    9.     SubShader
    10.     {
    11.         Blend SrcAlpha OneMinusSrcAlpha
    12.  
    13.         Pass
    14.         {
    15.             Color(.389, .1465, .4645, 0.5)
    16.             SetTexture[_MainTex] {Combine one - texture * primary alpha, texture alpha}
    17.             SetTexture[_] {Combine previous Dot3 primary}
    18.         }
    19.     }
    20. }
    21.  
    Thanks for base source!
     
  21. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Like I said, it's not really workable. The result of the alpha channel for a texture stage using Dot3 is buggy and random.
     
  22. nilesh410451

    nilesh410451

    Joined:
    Aug 22, 2012
    Posts:
    4
    Hi pset,
    Thanks for the reply.But the above shader is not working for me.Its showing dark gray color and texture is not visible.I want texture visible with disabled state.The previous shader you have gives was best suited for me and I want the same for android with support for opengles 1.x.

    thanks and regards
    Nilesh
     
  23. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Anyone care to modify the shader so it behaves as follows:

    - An Unlit Transparent Shader that uses meshes colour value to desaturate (i.e. if mesh colour is white full colour if mesh colour is black fully desaturated).
    - Supports iPhone/iPad.
     
  24. panta

    panta

    Joined:
    Aug 10, 2012
    Posts:
    71
  25. GonzoCubFan

    GonzoCubFan

    Joined:
    Oct 21, 2011
    Posts:
    70
    This does NOT work under iOS. I've just tried it and both under iOS and under the Editor, it yields a solid hot pink color to the whole model. I've used the following shader in the Unity Editor and it works fine, but gives me the same hot pink color under iOS. Does anyone have any ideas on this?

    Code (csharp):
    1.  
    2. Shader "Bumped Diffuse Gray" {
    3.     Properties {
    4.         _Color ("Main Color", Color) = (1,1,1,1)
    5.         _MainTex ("Base (RGB)", 2D) = "white" {}
    6.         _BumpMap ("Normalmap", 2D) = "bump" {}
    7.     }
    8.    
    9.     SubShader {
    10.         Tags { "RenderType"="Opaque" }
    11.         LOD 300
    12.    
    13.         CGPROGRAM
    14.         #pragma surface surf Lambert
    15.        
    16.         sampler2D _MainTex;
    17.         sampler2D _BumpMap;
    18.         fixed4 _Color;
    19.        
    20.         struct Input {
    21.             float2 uv_MainTex;
    22.             float2 uv_BumpMap;
    23.         };
    24.        
    25.         void surf (Input IN, inout SurfaceOutput o) {
    26.             fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    27.             o.Albedo = dot(c.rgb, float3(0.3, 0.59, 0.11));
    28.             o.Alpha = c.a;
    29.             o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    30.         }
    31.     ENDCG  
    32.     }
    33.  
    34. FallBack "Diffuse"
    35. }
    36.  
    Thanks in advance for any help you can offer.

    = Ed =
     
  26. GonzoCubFan

    GonzoCubFan

    Joined:
    Oct 21, 2011
    Posts:
    70
    OK, so I was wrong. The shader I'm using works fine. It just appears that you can't dynamically change the shader under iOS the same way that you can under the Unity Editor. Changing to the grayscale shader works fine Under the Editor, but causes the pink problem under iOS. I'm investigating this further.

    = Ed =
     
  27. GonzoCubFan

    GonzoCubFan

    Joined:
    Oct 21, 2011
    Posts:
    70
    OK, so as I said it turns out that for some reason, under iOS, if you try to dynamically change the shader under program control, this will cause some sort of error that results in everything being rendered pink for the object that you try to change the shader on.

    So I've come up with a less-than-ideal workaround. Rather than changing the shader, I created a duplicate material in the Editor, and changed its shader to the grayscale shader that I hacked together. Then, when I need to switch to grayscale, I change the material for the object rather than the shader. In our particular case this causes additional code to be written since we were changing textures as well. Now we use a single grayscale material for all of the characters that we need to do this with. When we switch to grayscale, we have to change the texture and the normal map for that material, but at least it works under iOS.

    The extra material costs about 4K of additional app size.

    I'm going to file a bug report about changing shaders under iOS.

    = Ed =
     
  28. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
  29. u0204909

    u0204909

    Joined:
    Jun 25, 2012
    Posts:
    21
    Hi Jessy, thanks for the great grayscale shader! Could I ask if it's possible for your grayscale shader to be modified to include transparency?
     
  30. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    There's not really such a thing as "transparency" in common realtime graphics, that I know of, but every shader that I know how to write can incorporate blending. You just need to figure out what parameters control the result.
     
  31. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Can you explain the reasoning behind this statement? Perhaps you are using a definition I haven't heard before.
     
  32. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Imagine a Light, colored Cellophane, and some reflective Surface.

    Shine a light through the cellophane onto the surface:
    L --> C --> S

    Now imagine we want to model the photonic result, reflected back to the light's position:
    L <-- C <-- S

    That light isn't going to be properly modeled. Rendering "surfaces" is a hack which doesn't handle transmission of light through surfaces. Non-programmable blending doesn't provide for an appropriate single-pass rendering of the cellophane, even if you did calculate the correct light reflected off the surface.

    Now, if you're talking about the definition of transparent that involves no filtering of light, then that is misrepresented as well. Because all screens are too low-pixel-density to create proper illusions otherwise, we use alpha blending to soften up edges. That leads to confusion. Many posts on this forum, for example, are related to the misuse of concepts in realtime 3D. If you're presented with the idea that an alpha channel defines the opacity of your surface, then it makes no sense that you can't have it render properly from all angles.
     
    Marrt likes this.
  33. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    If I understand you correctly, then I think you are setting unreasonably high standards for your use of optics terms in real-time rendering.

    You're right that Unity's shadow system doesn't do partial transmission of light. Do you actually think that the word "transparent" is not applicable because blending alone does not model optical transparency 100% correctly?

    If you turn off projected shadows, are your objects no longer "opaque" because they don't actually block the "light" they "reflect" and "absorb"?
     
  34. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    If my standards were unreasonable, then offline rendering wouldn't exist. Hardware has not reached the "good enough" point, where something you put into a 3D scene will react the way a meatspace material would.

    I think it's not applicable, not because it's not 100% accurate, but because I don't consider it a model of transparency at all.

    They are never opaque. I've seen a lot of threads about that problem, too. That said, the concept of "pay us more money to get realtime shadows" is more easily comprehensible than "order-dependent blending".

    Having to understand the backing technology is a waste of time for most people, and it impedes their creative process. Some of us have fun with it anyway, but there's no reason to get protective of the primitive hacks that we have to deal with, due to computers being so ridiculously slow that we can't run the simulations we actually would like to.
     
  35. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    It is difficult to tell whether you are being deliberately obtuse, or you sincerely believe that alpha blending is not a model of optical transparency in real-time rendering.

    Either way, your desire to use the terminology of the underlying hardware is admirable, but that doesn't invalidate the use of real-world terms to describe the effects we create. Telling someone that there is no such thing as transparency in real-time rendering just because Unity's shadow system doesn't support partial transmission of light is unhelpful at best, and quite disingenuous if you don't disclose your personal standards for terminology.
     
  36. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Correct. As I alluded to, it's a compositing hack. The term wouldn't have come about if we hadn't also needed antialiasing. It doesn't model any real-world phenomenon when used in 3D.

    While I think it's important that people understand what's going on at the hardware level, in order to make better creative predictions, that importance is a fault of the state of hardware technology, and it won't last. Someday, we'll have transparency in 3D, but until then, calling blending colors together, based on previously-rendered pixels, "transparency", is a simplification that is proven to lead to confusion.

    The model works in 2D image manipulation apps, which clearly present the user with the fact that rendering happens in a prescribed order via prescribed operations.
     
    Last edited: Apr 10, 2013
    Marrt likes this.
  37. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    I'm curious what you would consider to be the features of a bare-minimum implementation of transparency in a 3D application. Similarly, I wonder what you would say qualifies as opaque.
     
  38. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I don't think I'm qualified to make those assessments for anyone other than myself, and that self is not constant, so I don't think it's worth putting much thought into. I have an idea about what would create enough of an illusion for me to consider 3D simulated objects transparent or opaque, but, I assume that an optical physicist would find a lot more wrong with any simulation than I would. What seems "wrong" to someone, in this context, is dependent on what they have observed, and what theories they understand well enough to make predictions and criticize shortcomings of simulations.

    I know that in the past, for example, I haven't understood why 3D "transparency" rendering wouldn't act as I expected it to, and nobody in my local game development meetup group could tell me either. I feel that the concept of transparency is misrepresented, and it's detrimental to the development of anyone working in realtime 3D to tell them that transparency is achievable. I felt lied to, but now, knowing what is going on in many cases, I feel empowered and useful. If you feel differently about the dishonesty, that's fine. I value your opinion and I'm generally pretty intolerant of what I feel is the spreading of disinformation; it could be that you're the same way, and you think that's what I'm doing.
     
  39. Essential

    Essential

    Joined:
    Sep 8, 2011
    Posts:
    265
    This works perfect Jessy, but is there a way—despite the technical argument on whether transparency is possible or not–to give this shader an opacity slider?
     
  40. Essential

    Essential

    Joined:
    Sep 8, 2011
    Posts:
    265
    Ah, I solved that myself! :) This shader has an opacity slider:

    Code (csharp):
    1.  
    2. Shader "Mobile/Unlit/Grayscale Transparent" {
    3.  
    4.     Properties {
    5.         _Opacity ("Opacity", Range(0,1)) = 1
    6.         _MainTex ("Texture", 2D) = ""
    7.     }
    8.    
    9.     SubShader {
    10.         Tags { "Queue"="Transparent" }
    11.         ZWrite Off
    12.         Blend SrcAlpha OneMinusSrcAlpha
    13.         Pass {
    14.             CGPROGRAM
    15.             #pragma vertex vert
    16.             #pragma fragment frag
    17.             struct v2f {
    18.                 float4 position : SV_POSITION;
    19.                 float2 uv_mainTex : TEXCOORD;
    20.             };
    21.            
    22.             float _Opacity;
    23.            
    24.             uniform float4 _MainTex_ST;
    25.             v2f vert (float4 position : POSITION, float2 uv : TEXCOORD0) {
    26.                 v2f o;
    27.                 o.position = mul (UNITY_MATRIX_MVP, position);
    28.                 o.uv_mainTex = uv * _MainTex_ST.xy + _MainTex_ST.zw;
    29.                 return o;
    30.             }
    31.            
    32.             uniform sampler2D _MainTex;
    33.             fixed4 frag(float2 uv_mainTex : TEXCOORD) : COLOR {
    34.                 fixed4 mainTex = tex2D (_MainTex, uv_mainTex);
    35.                 fixed4 fragColor;
    36.                 fragColor.rgb = dot (mainTex.rgb, fixed3 (.222, .707, .071));
    37.                 fragColor.a = mainTex.a * _Opacity;
    38.                 return fragColor;
    39.             }
    40.             ENDCG
    41.         }
    42.     }
    43. }
     
  41. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    You all should be aware that you can actually do a greyscale post effect without using render textures. The problem is, you can't preview this in the Editor; it only works on tile-based deferred rendering GPUs. Still cool though; you might use render textures in the Editor and then use this method for performance / battery on iOS:
    Code (csharp):
    1. Shader "Greyscale Post Effect" {
    2.    
    3. Properties {
    4.     _Opacity ( "Opacity", Range(0,1) ) = 1
    5. }
    6.  
    7. SubShader {
    8.     Tags { "Queue" = "Overlay" }
    9.     ZWrite Off
    10.     Pass {
    11.         GLSLPROGRAM
    12.         #extension GL_EXT_shader_framebuffer_fetch : require
    13.                
    14.         #ifdef VERTEX
    15.         void main() {
    16.             gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    17.         }
    18.         #endif
    19.        
    20.         #ifdef FRAGMENT
    21.         uniform lowp float _Opacity;
    22.         void main() {
    23.             lowp float greyscale = dot( gl_LastFragData[0].rgb, vec3(.222, .707, .071) );
    24.             gl_FragColor.rgb = mix(gl_LastFragData[0].rgb, vec3(greyscale), _Opacity);
    25.         }
    26.         #endif     
    27.         ENDGLSL
    28.     }
    29. }
    30.  
    31. }
     
    BelfegnarInc likes this.
  42. NateJC

    NateJC

    Joined:
    Apr 10, 2012
    Posts:
    58
    Hey Jessy, I'm trying to find an option that will work on iOS 6.x (or later) and Android. Will that last shader you posted work on both?
     
  43. BelfegnarInc

    BelfegnarInc

    Joined:
    Jun 29, 2014
    Posts:
    32
    Got pink plane on nexus5 :(
     
  44. BelfegnarInc

    BelfegnarInc

    Joined:
    Jun 29, 2014
    Posts:
    32
    It's a bit strange, considering that we have:
    for tegra GL_NV_shader_framebuffer_fetch,
    for mali GL_ARM_shader_framebuffer_fetch (theoretically, not tested),
    for everything else, there is GL_EXT_shader_framebuffer_fetch (for ios <6 it's GL_APPLE_shader_framebuffer_fetch).
    But for me, none of the extensions is not suitable. For Adreno 330 (adb logcat):
    D/Unity ( 8781): GL_AMD_compressed_ATC_texture GL_AMD_performance_monitor GL_AMD_program_binary_Z400 GL_EXT_debug_label GL_EXT_debug_marker GL_EXT_discard_framebuffer GL_EXT_robustness GL_EXT_texture_format_BGRA8888 GL_EXT_texture_type_2_10_10_10_REV GL_NV_fence GL_OES_compressed_ETC1_RGB8_texture GL_OES_depth_texture GL_OES_depth24 GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_element_index_uint GL_OES_fbo_render_mipmap GL_OES_fragment_precision_high GL_OES_get_program_binary GL_OES_packed_depth_stencil GL_OES_depth_texture_cube_map GL_OES_rgb8_rgba8 GL_OES_standard_derivatives GL_OES_texture_3D GL_OES_texture_float GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_texture_npot GL_OES_vertex_half_float GL_OES_vertex_type_10_10_10_2 GL_OES_vertex_array_object GL_QCOM_alpha_test GL_QCOM_binning_control GL_QCOM_driver_control GL_QCOM_perfmon_global_mode GL_QCOM_extended_get GL_QCOM_extended_get2 GL_QCOM_tiled_rendering GL_QCOM_writeonly_rendering GL_EXT_sRGB GL_EXT_texture_filter_anisotropic GL_EXT_color_buffer_float GL_EXT_color_buffer_half_float GL_EXT_disjoint_timer_query

    Is there any adreno's similar extension?
     
    Last edited: Jul 28, 2014
  45. giulio-pierucci

    giulio-pierucci

    Joined:
    Sep 4, 2012
    Posts:
    8
    First: Thanks Jessy, you are enlightening for me!
    Second: i wrote this right now, for fun. I hope it is useful to someone.


    Code (CSharp):
    1. Shader "Custom/Progressive Desaturation" {
    2.     Properties {
    3.         _MainTex ("Base (RGB)", 2D) = "white" {}
    4.         _Saturation("Saturation (0,1)", Range(0,1)) = 1
    5.     }
    6.     SubShader {
    7.         Tags { "RenderType"="Opaque" }
    8.         LOD 200
    9.        
    10.         CGPROGRAM
    11.         #pragma surface surf Lambert
    12.  
    13.         sampler2D _MainTex;
    14.         float _Saturation;
    15.  
    16.         struct Input {
    17.             float2 uv_MainTex;
    18.         };
    19.  
    20.         // Converts color to luminance (grayscale)
    21.         float Luminance( float3 c )
    22.         {
    23.             return dot( c, float3(0.22, 0.707, 0.071) );
    24.         }
    25.  
    26.         void surf (Input IN, inout SurfaceOutput o) {
    27.             half4 c = tex2D (_MainTex, IN.uv_MainTex);
    28.             half4 g = Luminance(c.rgb);
    29.             o.Albedo = lerp(g.rgb, c.rgb, _Saturation);
    30.             o.Alpha = c.a;
    31.         }
    32.         ENDCG
    33.     }
    34.     FallBack "Diffuse"
    35. }
    36.  
     
    Deleted User and Girish-sruthkia like this.
  46. Deleted User

    Deleted User

    Guest

    Many thanks! It was incredibly helpful for me:)