Shader "HeightTest" { Properties { _MainTex ("Base (RGB) Trans (A)", 2D) = "white" { } _Cutoff ("Alpha Cutoff", Range(0,1)) = 0.5 } SubShader { Tags { "QUEUE"="Transparent" "IGNOREPROJECTOR"="true" "RenderType"="Transparent" } LOD 200 ZWrite On // Set up alpha blending Blend SrcAlpha OneMinusSrcAlpha Pass { Cull Back Lighting Off Alphatest Equal [_Cutoff] SetTexture [_MainTex] { combine texture } } CGPROGRAM #pragma surface surf NoLighting fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten) { fixed4 c; c.rgb = s.Albedo; c.a = s.Alpha; return c; } sampler2D _MainTex; uniform float _PlayerY = 0; struct Input { float2 uv_MainTex; float3 worldPos; }; void surf (Input IN, inout SurfaceOutput o) { half4 c = tex2D (_MainTex, IN.uv_MainTex); half junk; half darkMult = IN.worldPos.y - (_PlayerY-1); half darkSmooth = modf(darkMult, junk)*8; //The multiplier here determines the smoothing between layers darkMult = (ceil(darkMult+2)/12)+.67; //Base the layer darkness off the player position and a scalar if(ceil(darkSmooth) == 0) //If near edge of current shading stage darkMult += 0.09 + modf(darkSmooth, junk)/12; //Use the second decimal place as a smoothing value between stages half alpha = (IN.worldPos.y - _PlayerY - 1.5)/3; if(darkMult > 1) darkMult = 1; if(darkMult < 0.15) darkMult = 0.15; if(alpha > 1) alpha = 1; if(alpha < 0) alpha = 0; if (IN.worldPos.y < _PlayerY-1) { o.Albedo = c.rgb * darkMult; } else { o.Albedo = c.rgb * .92; } if (IN.worldPos.y > _PlayerY + 1.5) { o.Alpha = c.a * (1-alpha); } else { o.Alpha = c.a; } } ENDCG } }