Advertisement
Guest User

LitDistanceAppear.shader

a guest
Mar 17th, 2019
2,790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Toon/Lit Distance Appear" {
  2.     Properties{
  3.         _Color("Color Primary", Color) = (0.5,0.5,0.5,1)       
  4.         _MainTex("Main Texture", 2D) = "white" {}
  5.         _Speed("MoveSpeed", Range(1,50)) = 10 // speed of the swaying
  6.         [Toggle(DOWN_ON)] _DOWN("Move Down?", Int) = 0
  7.            
  8.     }
  9.  
  10.         SubShader{
  11.             Tags { "RenderType" = "Opaque"  }
  12.             LOD 200
  13.  
  14.         CGPROGRAM
  15.         #pragma surface surf ToonRamp vertex:vert addshadow // addshadow applies shadow after vertex animation
  16.  
  17.         // custom lighting function based
  18.         // on angle between light direction and normal
  19.         #pragma lighting ToonRamp exclude_path:prepass
  20.         #pragma multi_compile_instancing
  21.          #pragma shader_feature DOWN_ON
  22.         inline half4 LightingToonRamp(SurfaceOutput s, half3 lightDir, half atten)
  23.         {
  24.             #ifndef USING_DIRECTIONAL_LIGHT
  25.             lightDir = normalize(lightDir);
  26.             #endif
  27.            
  28.             float d = dot(s.Normal, lightDir);
  29.             float3 ramp = smoothstep(0, d + 0.06, d) + 0.8f;
  30.             half4 c;
  31.             c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
  32.             c.a = 0;
  33.             return c;
  34.         }
  35.  
  36.         sampler2D _MainTex;
  37.         float _Speed;
  38.         float4 _Color;
  39.  
  40.         struct Input {
  41.             float2 uv_MainTex : TEXCOORD0;
  42.         };
  43.  
  44.         UNITY_INSTANCING_BUFFER_START(Props)
  45.         UNITY_DEFINE_INSTANCED_PROP(float, _Moved)
  46.         UNITY_INSTANCING_BUFFER_END(Props)
  47.  
  48.         void vert(inout appdata_full v)//
  49.         {
  50.             v.vertex.xyz *= UNITY_ACCESS_INSTANCED_PROP(Props, _Moved);
  51.             #if DOWN_ON
  52.             v.vertex.y += _Speed-UNITY_ACCESS_INSTANCED_PROP(Props, _Moved * _Speed);
  53.             #else
  54.             v.vertex.y -= _Speed-UNITY_ACCESS_INSTANCED_PROP(Props, _Moved * _Speed);
  55.             #endif
  56.         }
  57.  
  58.         void surf(Input IN, inout SurfaceOutput o) {
  59.             half4 c = tex2D(_MainTex, IN.uv_MainTex)* _Color;      
  60.             o.Albedo = c.rgb;
  61.             o.Alpha = c.a;
  62.         }
  63.         ENDCG
  64.         }
  65.             Fallback "Diffuse"
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement