Hello Everyone! I am having a little problem with making fog effect in my Unity game. Have a look at the picture: The effect is achieved by having a shader that applies color gradients to the towers. All looks good, but when I add lights to the scene, it changes to this: Oops. The fog effect disappeared. I am happy with the shading effect on the upper parts of the towers, but the lower part should still get solid blue. My shader looks like this: Code (Boo): Shader "Custom/ColorGradient" { Properties { _ColorA ("ColorA", Color) = (1,1,1,1) _ColorB ("ColorB", Color) = (1,1,1,1) _Start ("Start", Float) = 2.0 _End ("End", Float) = 1.0 } SubShader { Tags { "RenderType"="Opaque" } LOD 200 CGPROGRAM #pragma surface surf Lambert float4 _ColorA; float4 _ColorB; float _Start; float _End; struct Input { float2 uv_MainTex; float3 worldPos; }; void surf (Input IN, inout SurfaceOutput o) { if(IN.worldPos.y>_Start){ o.Albedo = _ColorA.rgb; o.Emission = 0; } if(IN.worldPos.y<=_Start && _End<=IN.worldPos.y) { float d = (IN.worldPos.y-_End)/(_Start-_End); o.Albedo = lerp(_ColorA, _ColorB, 1.0-d).rgb; o.Emission = (1.0-d) * lerp(_ColorA, _ColorB, 1.0-d).rgb; } if(IN.worldPos.y<_End) { o.Albedo = _ColorB.rgb; o.Emission = _ColorB.rgb; } } ENDCG } FallBack "Diffuse" } Does anyone know how to fix this? Thanks a lot in advance for any suggestions.
You should not use emission, implement your own lighting function, pass fog color in it and add to final color with lerp function.