Shader not being affected by Unity 5's Fog

Hi there,

According to the update guide here: [Official] Changing how Fog is done in Unity shaders? - Unity Engine - Unity Discussions

They say that in order for shaders to properly support Unity 5’s fog, you need to add the fog macros. The problem with this shader is that it has multiple textures. The guide only covers 1. The shader I’m using also has alpha channels that mask the other textures

Could someone steer me in the right direction on how to add fog support for a shader with multiple textures and alpha masking?

I’ve tried following the guide, but it doesn’t seem to work with this kind of shader. I’ve looked through every post using google and haven’t found a solution. Any help would be greatly appreciated. To mention, I’m not much of a shader programmer, but I’m trying to learn.

I believe it would be this portion of the shader where fog would be added.

Note: This only seems to be affected by Unity 5.2+

void surf (Input IN, inout SurfaceOutput o) {
    fixed4 c1 = tex2D(_MainTex1, IN.uv_MainTex1);
    fixed4 c2 = tex2D(_MainTex2, IN.uv_MainTex2);
    fixed4 c3 = tex2D(_MainTex3, IN.uv_MainTex3);
    o.Albedo = c1.rgb;
    o.Alpha = c1.a*c2.a*c3.a;
}

Vert / frag style shaders need special fog handling. Surface shaders (which is what you’re using) should have fog enabled by default.

Yes, but not with Unity 5.2+. I’m not sure what has been updated since then, but it no longer works after I have updated. I checked the update notes for 5.2 and couldn’t find any major changes with fog.

Post the full shader then.

Alright. Any idea how fog would be added to this? I double checked and it works with Unity 5.0 but not Unity 5.2. I’m not sure why though. Fog should be applied automatically to surface shaders.

Shader "Mask Over Texture" {
Properties {
    _MainTex1 ("Mask", 2D) = "white" {}
    _MainTex2 ("Texture A", 2D) = "white" {}
    _MainTex3 ("Texture B", 2D) = "white" {}
}
SubShader {
    Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
    LOD 200

CGPROGRAM
#pragma surface surf Lambert alpha

sampler2D _MainTex1;
sampler2D _MainTex2;
sampler2D _MainTex3;

struct Input {
    float2 uv_MainTex1;
    float2 uv_MainTex2;
    float2 uv_MainTex3;
};
void surf (Input IN, inout SurfaceOutput o) {
    fixed4 c1 = tex2D(_MainTex1, IN.uv_MainTex1);
    fixed4 c2 = tex2D(_MainTex2, IN.uv_MainTex2);
    fixed4 c3 = tex2D(_MainTex3, IN.uv_MainTex3);
    o.Albedo = c1.rgb;
    o.Alpha = c1.a*c2.a*c3.a;
}

Apart from that not being the entire shader (missing a few "}"s and an ENDCG), it gets properly fogged when I use it. I’m not seeing the problems you are.