I'm seeing some discrepancy between how shaders apply fog. Most of the objects in my scene use "Mobile/Unlit (Supports Lightmap)". However some use a custom shader (the splat mapped ground, vegetation, animals). For some reason they don't apply fog the same. On the left hand side of the screenshot below I have a plane and cube both with a Mobile/Unlit (Supports Lightmap) shader applied, while on the right hand side I have the exact same scene but with the ground shaded using the custom shader. As you can see the cube stands out a lot more on the right, while on the left it blends into the fog as expected. In my real scene this has the effect of making some objects glow as they are fading to the fog at different distances. Its almost as though the shaders are using different fog parameters. I'm using Unity 5.4.2f2. The exact same scene in Unity 4 works fine, with both types of (equivalent) shader blending together correctly. Here are the two shaders (stripped down for testing). Mobile Unlit (Supports Lightmap): Code (CSharp): Shader "Test/Mobile Unlit (Supports Lightmap)" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} } SubShader { Tags { "RenderType"="Opaque" } LOD 100 // Non-lightmapped Pass { Tags { "LightMode" = "Vertex" } Lighting Off SetTexture [_MainTex] { constantColor (1,1,1,1) combine texture, constant // UNITY_OPAQUE_ALPHA_FFP } } // Lightmapped, encoded as RGBM Pass { Tags { "LightMode" = "VertexLMRGBM" } Lighting Off BindChannels { Bind "Vertex", vertex Bind "texcoord1", texcoord0 // lightmap uses 2nd uv Bind "texcoord", texcoord1 // main uses 1st uv } SetTexture [unity_Lightmap] { matrix [unity_LightmapMatrix] combine texture * texture alpha DOUBLE } SetTexture [_MainTex] { constantColor (1,1,1,1) combine texture * previous QUAD, constant // UNITY_OPAQUE_ALPHA_FFP } } } } Splatmap Custom Shader (Stripped down) Code (CSharp): Shader "Test/Splatmap Test" { Properties { _MainTex ("Layer 1", 2D) = "white" {} } SubShader { Tags { "RenderType" = "Opaque" } Pass { // Disable lighting, we're only using the lightmap Lighting Off CGPROGRAM // Must be a vert/frag shader, not a surface shader: the necessary variables // won't be defined yet for surface shaders. #pragma vertex vert #pragma fragment frag #pragma multi_compile_fog #include "UnityCG.cginc" struct v2f { float4 pos : SV_POSITION; float2 uv_MainTex : TEXCOORD0; float2 uv1 : TEXCOORD1; UNITY_FOG_COORDS(7) }; struct appdata_lightmap { float4 vertex : POSITION; float2 texcoord : TEXCOORD0; float2 texcoord1 : TEXCOORD1; }; sampler2D _MainTex; float4 _MainTex_ST; v2f vert(appdata_lightmap i) { v2f o; UNITY_INITIALIZE_OUTPUT(v2f,o); o.pos = mul(UNITY_MATRIX_MVP, i.vertex); o.uv_MainTex = TRANSFORM_TEX(i.texcoord, _MainTex); o.uv1 = i.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; UNITY_TRANSFER_FOG(o, o.pos); return o; } half4 frag(v2f i) : COLOR { fixed3 tex = tex2D (_MainTex, i.uv_MainTex); float4 col = half4(tex,0); col.rgb *= DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.uv1)); //lightmap UNITY_APPLY_FOG(i.fogCoord * 1.0f, col); return col; } ENDCG } } } I'd be very grateful if someone has any ideas.
As of Unity 5.0 fixed function shaders are no longer supported by the rendering pipeline. Instead fixed function shaders are converted to vertex fragment shaders. However I've found a number of cases where this conversion isn't quite 100% perfect. You may need to make your own version of the "mobile unlit" shader to fix the issues. You can start by putting a copy of the mobile unlit shader in your project, select it, and then click on "Show Generated" to see the resulting shader. You may be able to spot where the two diverge from there.
Fantastic - thanks for the fast reply. As you said I changed the generated code so that it used the same method of fog calculation (UNITY_TRANSFER_FOG(..) etc). They now apply fog identically.