Guest User

ToonInteractiveGrow.shader

a guest
Nov 30th, 2019
849
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Toon/Lit Interactive Grow" {
  2.     Properties{
  3.         _Color("Color Away From Target", Color) = (0.5,0.5,0.5,1)
  4.         _MainTex("Main Texture", 2D) = "white" {}
  5.         _Color2("Color Emis", Color) = (0,0.5,1,1)
  6.         _Mask("Emis Mask (R)", 2D) = "black" {}
  7.         _EmisStrength("Emissive Strength", Range(1, 10)) = 5
  8.         _Speed("Move Speed", Range(1,50)) = 10
  9.         _Rigidness("Rigidness", Range(0,2)) = 10
  10.         _SwayMax("Sway Max", Range(0,10)) = 10
  11.         _YOffset("Y Offset", Range(-2,2)) = 0
  12.         _ShrinkXZ("Shrink Scale XZ Axis", Range(0,1)) = 0.2
  13.         _Shrink("Shrink Scale All", Range(0, 1)) = 0.2
  14.  
  15.     }
  16.  
  17.         SubShader{
  18.             Tags { "RenderType" = "Opaque"  }
  19.             LOD 200
  20.  
  21.  
  22.         CGPROGRAM
  23.         #pragma surface surf ToonRamp vertex:vert addshadow // addshadow applies shadow after vertex animation
  24.  
  25.             // custom lighting function based
  26.             // on angle between light direction and normal
  27.             #pragma lighting ToonRamp exclude_path:prepass
  28.             #pragma multi_compile_instancing
  29.             inline half4 LightingToonRamp(SurfaceOutput s, half3 lightDir, half atten)
  30.             {
  31.                 #ifndef USING_DIRECTIONAL_LIGHT
  32.                 lightDir = normalize(lightDir);
  33.                 #endif
  34.  
  35.                 float d = dot(s.Normal, lightDir);
  36.                 float3 ramp = smoothstep(0, d , d) + 0.5f;
  37.                 half4 c;
  38.                 c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
  39.                 c.a = 0;
  40.                 return c;
  41.             }
  42.  
  43.             sampler2D _MainTex,_Mask;
  44.             float4 _Color, _Color2;
  45.             float _Rigidness, _Speed, _SwayMax, _YOffset, _Shrink, _ShrinkXZ, _EmisStrength;
  46.  
  47.             struct Input {
  48.                 float2 uv_MainTex : TEXCOORD0;
  49.             };
  50.  
  51.             //MaterialPropertyBlock stuff
  52.             UNITY_INSTANCING_BUFFER_START(Props)
  53.             UNITY_DEFINE_INSTANCED_PROP(float, _Moved)
  54.             UNITY_INSTANCING_BUFFER_END(Props)
  55.  
  56.  
  57.             void vert(inout appdata_full v, out Input o) {
  58.                 UNITY_INITIALIZE_OUTPUT(Input, o);         
  59.                 float4 wpos = mul(unity_ObjectToWorld, v.vertex);// world position
  60.                
  61.                 // shrink based on proximity to target
  62.                 v.vertex.xz *= saturate(UNITY_ACCESS_INSTANCED_PROP(Props, _Moved) + _ShrinkXZ);
  63.                 v.vertex.xyz *= saturate(UNITY_ACCESS_INSTANCED_PROP(Props, _Moved) + _Shrink);
  64.                
  65.                 // swaying
  66.                 float x = sin(wpos.x / _Rigidness + (_Time.x * _Speed)) *(v.vertex.y - _YOffset);// x axis movements
  67.                 float z = sin(wpos.z / _Rigidness + (_Time.x * _Speed)) *(v.vertex.y - _YOffset);// z axis movements
  68.                 v.vertex.x += (step(0, v.vertex.y - _YOffset) * x * _SwayMax);// apply the movement if the vertex's y above the YOffset
  69.                 v.vertex.z += (step(0, v.vertex.y - _YOffset) * z * _SwayMax);
  70.                 }
  71.  
  72.             void surf(Input IN, inout SurfaceOutput o) {
  73.                 half4 c = tex2D(_MainTex, IN.uv_MainTex);
  74.                 half4 m = tex2D(_Mask, IN.uv_MainTex);
  75.                 o.Albedo = c * _Color;
  76.                 o.Emission = (UNITY_ACCESS_INSTANCED_PROP(Props, _Moved) * _Color2 * c.rgb * _EmisStrength) * m.r ;// emission based on mask and proximity
  77.                 o.Alpha = c.a;
  78.             }
  79.             ENDCG
  80.         }
  81.             Fallback "Diffuse"
  82. }
RAW Paste Data