How to disable fog in a shader?

Upgraded to U5, and everything’s super foggy.

Fog { Mode Off }

doesn’t seem to work?

Shader "Toon/Basic" {
    Properties {
        _Color ("Main Color", Color) = (.5,.5,.5,1)
        _MainTex ("Base (RGB)", 2D) = "white" {}
        _ToonShade ("ToonShader Cubemap(RGB)", CUBE) = "" { }
    }


    SubShader {
        Tags { "RenderType"="Opaque" }
        Pass {
            Name "BASE"
            Cull Off
            Fog {Mode Off}
            CGPROGRAM
            #pragma nofog
            #pragma vertex vert
            #pragma fragment frag
            #pragma multi_compile_fog

            #include "UnityCG.cginc"

            sampler2D _MainTex;
            samplerCUBE _ToonShade;
            float4 _MainTex_ST;
            float4 _Color;

            struct appdata {
                float4 vertex : POSITION;
                float2 texcoord : TEXCOORD0;
                float3 normal : NORMAL;
            };
          
            struct v2f {
                float4 pos : SV_POSITION;
                float2 texcoord : TEXCOORD0;
                float3 cubenormal : TEXCOORD1;
                UNITY_FOG_COORDS(2)
            };

            v2f vert (appdata v)
            {
                v2f o;
                o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
                o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
                o.cubenormal = mul (UNITY_MATRIX_MV, float4(v.normal,0));
                UNITY_TRANSFER_FOG(o,o.pos);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                fixed4 col = _Color * tex2D(_MainTex, i.texcoord);
                fixed4 cube = texCUBE(_ToonShade, i.cubenormal);
                fixed4 c = fixed4(2.0f * cube.rgb * col.rgb, col.a);
                UNITY_APPLY_FOG(i.fogCoord, c);
                return c;
            }
            ENDCG
        }
    }

    Fallback "VertexLit"
}

is still super foggy

The release notes say

But “#pragma nofog” doesn’t seem to make a difference either.

Also, the documentation recommends to “Check out built-in shader source”, but there isn’t any archive of them available for the current version, is there?

Anyway, rads on releasing a public beta!

Just don’t do any fog calculations in your shader. i.e. remove “#pragma multi_compile_fog”, UNITY_FOG_COORDS, UNITY_TRANSFER_FOG, UNITY_APPLY_FOG

5 Likes

Oooh the upgrade procedure added that fog stuff to lots of shaders - I didn’t even notice that. haha :cry:

I removed the lines you mentioned, but I’m still getting fog (If I enable/disable fog I can see a big difference)

edit: wait, nevermind, see next post. thanks :slight_smile:

Wait, it works now - I had to add/reassign the shader. huh.

Okay, yep, maybe it just wasn’t detecting code changes for a bit. It works fine now if I remove/add the lines in the code it changes immediately in the scene view.

Problem solved. Thanks!