Advertisement
tonynogo

Demo 27 - Moss on rock

Jul 6th, 2017
6,884
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/Moss" {
  2.     Properties {
  3.         _MainTex ("Main texture", 2D) = "white" {}
  4.         _MossTex ("Moss texture", 2D) = "gray" {}
  5.         _Direction ("Direction", Vector) = (0, 1, 0)
  6.         _Amount ("Amount", Range(0, 1)) = 1
  7.     }
  8.     SubShader {
  9.         Pass {
  10.             Tags { "RenderType"="Opaque" }
  11.        
  12.             CGPROGRAM
  13.             #pragma vertex vert
  14.             #pragma fragment frag
  15.             #include "UnityCG.cginc"
  16.  
  17.             struct v2f {
  18.                 float4 pos : SV_POSITION;
  19.                 float3 normal : NORMAL;
  20.                 float2 uv_Main : TEXCOORD0;
  21.                 float2 uv_Moss : TEXCOORD1;
  22.             };
  23.  
  24.             sampler2D _MainTex;
  25.             float4 _MainTex_ST;
  26.             sampler2D _MossTex;
  27.             float4 _MossTex_ST;
  28.  
  29.             v2f vert(appdata_full v) {
  30.                 v2f o;
  31.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  32.                 o.uv_Main = TRANSFORM_TEX(v.texcoord, _MainTex);
  33.                 o.uv_Moss = TRANSFORM_TEX(v.texcoord, _MossTex);
  34.                 o.normal = mul(_Object2World, v.normal);
  35.                 return o;
  36.             }
  37.  
  38.            
  39.             float3 _Direction;
  40.             fixed _Amount;
  41.  
  42.             fixed4 frag(v2f i) : COLOR {
  43.                 fixed val = dot(normalize(i.normal), _Direction);
  44.  
  45.                 if(val < 1 - _Amount)
  46.                     val = 0;
  47.  
  48.                 fixed4 tex1 = tex2D(_MainTex, i.uv_Main);
  49.                 fixed4 tex2 = tex2D(_MossTex, i.uv_Moss);
  50.                 return lerp(tex1, tex2, val);
  51.             }
  52.  
  53.             ENDCG
  54.         }
  55.     }
  56.     FallBack "Diffuse"
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement