Search Unity

Fog {Fog Commands}

Discussion in 'Shaders' started by reduktion, Apr 25, 2015.

  1. reduktion

    reduktion

    Joined:
    Sep 27, 2012
    Posts:
    25
    Hi

    With Unity 4 I could use per shader fog settings as documented here: http://docs.unity3d.com/Manual/SL-Fog.html I cannot get this working with Unity 5. For example the following shader simply ignores the line
    Code (CSharp):
    1. Fog {Density [_FogDensity]}
    Any ideas?

    Code (CSharp):
    1. Shader "CS/Only Color Unlit Fog Fader" {
    2.  
    3.     Properties
    4.     {
    5.         _Color ("Main Color", Color) = (1, 1, 1, 1)
    6.           _FogDensity ("Fog Density", Float) = 1
    7.     }
    8.     SubShader
    9.     {
    10.     Tags { "RenderType"="Geometry" "Queue"="Opaque"}
    11.     Fog {Density [_FogDensity]}
    12.     Pass
    13.     {
    14.         CGPROGRAM
    15.         #pragma vertex vert
    16.         #pragma fragment frag
    17.         #include "UnityCG.cginc"
    18.         #pragma multi_compile_fog
    19.      
    20.         fixed4 _Color;
    21.         float _FogDensity;
    22.         struct appdata
    23.         {
    24.             float4 vertex : POSITION;
    25.         };
    26.         struct v2f
    27.         {
    28.             float4 pos : SV_POSITION;
    29.             UNITY_FOG_COORDS(1)
    30.         };
    31.      
    32.         v2f vert (appdata v)
    33.         {
    34.             v2f o;
    35.             o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    36.             UNITY_TRANSFER_FOG(o,o.pos);
    37.             //o.color = v.color;
    38.             return o;
    39.         }
    40.      
    41.         half4 frag(v2f i) : COLOR
    42.         {
    43.             half4 col = _Color;
    44.             UNITY_APPLY_FOG(i.fogCoord, col);
    45.             return col;
    46.         }
    47.      
    48.         ENDCG
    49.         }
    50.     }
    51. }
    52.