Hey guys, we’re having a problem with a shader we used in Unity 4.6 and now that we upgraded to Unity 5 it stopped working. I looked around but any of the suggested fixes I found to similar problems didn’t help us. The shader is used as a green screen meaning that the specified color in a video texture should be set transparent but after the upgrade all colors are drawn normally. Any help would be appreciated!
Here’s the shader:
Shader "green_screen" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGBA)", 2D) = "white" {}
_ColorToReplace ("_ColorToReplace", Color) = (0,0.6,0,1)
threshold_sensitivity ("threshold_sensitivity", Range (0.0,1.0)) = 0.21
smoothing ("smoothing", Range (0.0,1.0)) = 0.05
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 200
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma surface surf Lambert
struct Input {
float2 uv_MainTex;
};
sampler2D _MainTex;
fixed4 _Color;
fixed4 _ColorToReplace;
float threshold_sensitivity,smoothing;
void surf (Input IN, inout SurfaceOutput o) {
float2 xy = float2(IN.uv_MainTex.x, IN.uv_MainTex.y);
float4 textureColor = tex2D (_MainTex, xy);
float maskY = 0.2989 * _ColorToReplace.r + 0.5866 * _ColorToReplace.g + 0.1145 * _ColorToReplace.b;
float maskCr = 0.7132 * (_ColorToReplace.r - maskY);
float maskCb = 0.5647 * (_ColorToReplace.b - maskY);
float Y = 0.2989 * textureColor.r + 0.5866 * textureColor.g + 0.1145 * textureColor.b;
float Cr = 0.7132 * (textureColor.r - Y);
float Cb = 0.5647 * (textureColor.b - Y);
float blendValue = smoothstep(threshold_sensitivity, threshold_sensitivity + smoothing, distance(float2(Cr, Cb), float2(maskCr, maskCb)));
o.Albedo = textureColor.rgb * _Color.rgb;
o.Alpha = textureColor.a * blendValue * _Color.a;
}
ENDCG
}
Fallback "Diffuse"
}