Require RGB to GRAYScale shader that should work on the Android and IOS devices

Hello Guys,

We Need a RGB to GRAYScale shader that should work on the Android and IOS devices
We have this shader “attached”, It seems to work in the editor but on devices the objects appear to be black, If possible can any one please let me know what is wrong in the shader or if possible please fix the same for me.

Thank you,
Raviraj Vaidya.

2938261–217394–Custom_Gray_Diffuse.shader (1.25 KB)

The platform might not support the branching shader condition? So it skips the branch and just returns the default (0,0,0,0) of your fragColor initialization. I’d look into replacing your conditional there with a shader define instead, and you can simply create two different Frags between #ifdefs that get chosen depending on if the define is set or not.

The other option would be to lerp() between the original color and the black color using your _GrayScale value. This way you can create an animated transition between color and grayscale if you want, or only partly grayscale.

static const fixed3 _GRAY = fixed3(0.222, 0.707, 0.071);

fixed4 frag(float2 uv_mainTex : TEXCOORD) : COLOR {
        fixed4 mainColor = tex2D(_MainTex, uv_mainTex);
        fixed3 grayColor = dot(mainColor.rgb, _GRAY);
        return fixed4( lerp(mainColor.rgb, grayColor, _GrayScale), mainColor.a);
    }

Hello Invertex,

Thank you for the support will try the same.

Thank you,
Raviraj Vaidya.

Cginc has some useful functions you might refer to in future, for example greyColor above is probably calculated the same in the built in Luminance() function. Find out more here: