tonynogo

Demo 76 - Fog

Jul 6th, 2017
10,113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/Fog"
  2. {
  3.     Properties
  4.     {
  5.         [Header(Textures and color)]
  6.         [Space]
  7.         _MainTex ("Fog texture", 2D) = "white" {}
  8.         [NoScaleOffset] _Mask ("Mask", 2D) = "white" {}
  9.         _Color ("Color", color) = (1., 1., 1., 1.)
  10.         [Space(10)]
  11.  
  12.         [Header(Behaviour)]
  13.         [Space]
  14.         _ScrollDirX ("Scroll along X", Range(-1., 1.)) = 1.
  15.         _ScrollDirY ("Scroll along Y", Range(-1., 1.)) = 1.
  16.         _Speed ("Speed", float) = 1.
  17.         _Distance ("Fading distance", Range(1., 10.)) = 1.
  18.     }
  19.  
  20.     SubShader
  21.     {
  22.         Tags { "Queue"="Transparent" "RenderType"="Transparent" }
  23.         Blend SrcAlpha OneMinusSrcAlpha
  24.         ZWrite Off
  25.         Cull Off
  26.  
  27.         Pass
  28.         {
  29.             CGPROGRAM
  30.             #pragma vertex vert
  31.             #pragma fragment frag
  32.            
  33.             #include "UnityCG.cginc"
  34.  
  35.             struct v2f {
  36.                 float4 pos : SV_POSITION;
  37.                 fixed4 vertCol : COLOR0;
  38.                 float2 uv : TEXCOORD0;
  39.                 float2 uv2 : TEXCOORD1;
  40.             };
  41.  
  42.             sampler2D _MainTex;
  43.             float4 _MainTex_ST;
  44.  
  45.             v2f vert(appdata_full v)
  46.             {
  47.                 v2f o;
  48.                 o.pos = UnityObjectToClipPos(v.vertex);
  49.                 o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  50.                 o.uv2 = v.texcoord;
  51.                 o.vertCol = v.color;
  52.                 return o;
  53.             }
  54.  
  55.             float _Distance;
  56.             sampler2D _Mask;
  57.             float _Speed;
  58.             fixed _ScrollDirX;
  59.             fixed _ScrollDirY;
  60.             fixed4 _Color;
  61.  
  62.             fixed4 frag(v2f i) : SV_Target
  63.             {
  64.                 float2 uv = i.uv + fixed2(_ScrollDirX, _ScrollDirY) * _Speed * _Time.x;
  65.                 fixed4 col = tex2D(_MainTex, uv) * _Color * i.vertCol;
  66.                 col.a *= tex2D(_Mask, i.uv2).r;
  67.                 col.a *= 1 - ((i.pos.z / i.pos.w) * _Distance);
  68.                 return col;
  69.             }
  70.             ENDCG
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment