Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

How to disable fog in a shader?

Discussion in 'Unity 5 Pre-order Beta' started by Stephen-Lavelle, Oct 27, 2014.

  1. Stephen-Lavelle

    Stephen-Lavelle

    Joined:
    Apr 17, 2013
    Posts:
    41
    Upgraded to U5, and everything's super foggy.

    Fog { Mode Off }

    doesn't seem to work?

    Code (CSharp):
    1. Shader "Toon/Basic" {
    2.     Properties {
    3.         _Color ("Main Color", Color) = (.5,.5,.5,1)
    4.         _MainTex ("Base (RGB)", 2D) = "white" {}
    5.         _ToonShade ("ToonShader Cubemap(RGB)", CUBE) = "" { }
    6.     }
    7.  
    8.  
    9.     SubShader {
    10.         Tags { "RenderType"="Opaque" }
    11.         Pass {
    12.             Name "BASE"
    13.             Cull Off
    14.             Fog {Mode Off}
    15.             CGPROGRAM
    16.             #pragma nofog
    17.             #pragma vertex vert
    18.             #pragma fragment frag
    19.             #pragma multi_compile_fog
    20.  
    21.             #include "UnityCG.cginc"
    22.  
    23.             sampler2D _MainTex;
    24.             samplerCUBE _ToonShade;
    25.             float4 _MainTex_ST;
    26.             float4 _Color;
    27.  
    28.             struct appdata {
    29.                 float4 vertex : POSITION;
    30.                 float2 texcoord : TEXCOORD0;
    31.                 float3 normal : NORMAL;
    32.             };
    33.          
    34.             struct v2f {
    35.                 float4 pos : SV_POSITION;
    36.                 float2 texcoord : TEXCOORD0;
    37.                 float3 cubenormal : TEXCOORD1;
    38.                 UNITY_FOG_COORDS(2)
    39.             };
    40.  
    41.             v2f vert (appdata v)
    42.             {
    43.                 v2f o;
    44.                 o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    45.                 o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
    46.                 o.cubenormal = mul (UNITY_MATRIX_MV, float4(v.normal,0));
    47.                 UNITY_TRANSFER_FOG(o,o.pos);
    48.                 return o;
    49.             }
    50.  
    51.             fixed4 frag (v2f i) : SV_Target
    52.             {
    53.                 fixed4 col = _Color * tex2D(_MainTex, i.texcoord);
    54.                 fixed4 cube = texCUBE(_ToonShade, i.cubenormal);
    55.                 fixed4 c = fixed4(2.0f * cube.rgb * col.rgb, col.a);
    56.                 UNITY_APPLY_FOG(i.fogCoord, c);
    57.                 return c;
    58.             }
    59.             ENDCG
    60.         }
    61.     }
    62.  
    63.     Fallback "VertexLit"
    64. }
    65.  
    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!
     
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    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
     
  3. Stephen-Lavelle

    Stephen-Lavelle

    Joined:
    Apr 17, 2013
    Posts:
    41
    Oooh the upgrade procedure added that fog stuff to lots of shaders - I didn't even notice that. haha :'(

    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 :)
     
  4. Stephen-Lavelle

    Stephen-Lavelle

    Joined:
    Apr 17, 2013
    Posts:
    41
    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!