DexterAndre

Snow Deformation Shader

Mar 14th, 2018
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Inspired by MinionsArt: https://pastebin.com/LxDYqWBh
  2.  
  3. Shader "Winter/SnowTracking"
  4. {
  5.     Properties
  6.     {
  7.         _Tess ("Tessellation", Range(1, 32)) = 4
  8.         _HighTex ("High Snow (RGB)", 2D) = "white" {}
  9.         _HighColor ("High Snow Color", Color) = (1,1,1,1)
  10.         _LowTex ("Low Snow (RGB)", 2D) = "white" {}
  11.         _LowColor ("Low Snow Color", Color) = (1,1,1,1)
  12.         _SplatMap ("Splat Map", 2D) = "black" {}
  13.         _NormalMap ("Normal Map", 2D) = "bump" {}
  14.         _SnowHeight ("Snow Height", Range(0, 15)) = 1
  15.         _WorldUp ("World Up Vector", Vector) = (0, 1, 0, 0)
  16.         _Displacement ("Displacement", Range(0, 15.0)) = 0.3
  17.         _SpecColor ("Specular Color", color) = (0.5, 0.5, 0.5, 0.5)
  18.     }
  19.     SubShader
  20.     {
  21.         Tags { "RenderType"="Opaque" }
  22.         LOD 200
  23.  
  24.         CGPROGRAM
  25.         // Physically based Standard lighting model, and enable shadows on all light types
  26.         #pragma surface surf BlinnPhong addshadow fullforwardshadows vertex:disp tessellate:tessDistance nolightmap
  27.  
  28.         #pragma target 4.6
  29.  
  30.         #include "Tessellation.cginc"
  31.  
  32.         struct appdata
  33.         {
  34.             float4 vertex : POSITION;
  35.             float4 tangent : TANGENT;
  36.             float3 normal : NORMAL;
  37.             float2 texcoord : TEXCOORD0;
  38.         };
  39.  
  40.         float _Tess;
  41.  
  42.         float4 tessDistance (appdata v0, appdata v1, appdata v2)
  43.         {
  44.             float minDist = 10.0;
  45.             float maxDist = 100.0;
  46.             return UnityDistanceBasedTess(v0.vertex, v1.vertex, v2.vertex, minDist, maxDist, _Tess);
  47.         }
  48.  
  49.         sampler2D _SplatMap;
  50.         float _Displacement;
  51.         float _SnowHeight;
  52.         float4 _WorldUp;
  53.  
  54.         void disp (inout appdata v)
  55.         {
  56.             float d = tex2Dlod(_SplatMap, float4(v.texcoord.xy,0,0)).r * _Displacement;
  57.             v.vertex.xyz -= _WorldUp * d;
  58.             v.vertex.y = v.vertex.y + _SnowHeight;
  59.         }
  60.  
  61.         struct Input
  62.         {
  63.             float2 uv_HighTex;
  64.             float2 uv_LowTex;
  65.             float2 uv_SplatMap;
  66.         };
  67.  
  68.         sampler2D _HighTex;
  69.         fixed4 _HighColor;
  70.         sampler2D _LowTex;
  71.         fixed4 _LowColor;
  72.         sampler2D _NormalMap;
  73.  
  74.         void surf (Input IN, inout SurfaceOutput o)
  75.         {
  76.             half amount = tex2Dlod(_SplatMap, float4(IN.uv_SplatMap, 0, 0)).r;
  77.             half4 c = lerp(tex2D(_HighTex, IN.uv_HighTex) * _HighColor, tex2D(_LowTex, IN.uv_LowTex) * _LowColor, amount);
  78.             o.Albedo = c.rgb;
  79.             o.Specular = 0.2;
  80.             o.Gloss = 1.0;
  81.             o.Normal = UnpackNormal(tex2D(_NormalMap, IN.uv_HighTex));
  82.         }
  83.         ENDCG
  84.     }
  85.     FallBack "Diffuse"
  86. }
Add Comment
Please, Sign In to add comment