Advertisement
Guest User

ToonLitInteractiveGrassAlpha

a guest
Jul 3rd, 2018
7,340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. Shader "Toon/Lit Swaying Interactive" {
  2. Properties {
  3. _Color ("Main Color", Color) = (0.5,0.5,0.5,1)
  4. _MainTex ("Base (RGB)", 2D) = "white" {}
  5. _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {}
  6. _Speed ("MoveSpeed", Range(20,50)) = 25 // speed of the swaying
  7. _Rigidness("Rigidness", Range(1,50)) = 25 // lower makes it look more "liquid" higher makes it look rigid
  8. _SwayMax("Sway Max", Range(0, 0.1)) = .005 // how far the swaying goes
  9. _YOffset("Y offset", float) = 0.0// y offset, below this is no animation
  10. _MaxWidth("Max Displacement Width", Range(0, 2)) = 0.1 // width of the line around the dissolve
  11. _Radius("Radius", Range(0,5)) = 1 // width of the line around the dissolve
  12. }
  13.  
  14. SubShader {
  15. Tags { "RenderType"="Opaque" "DisableBatching" = "True" }// disable batching lets us keep object space
  16. LOD 200
  17. Blend SrcAlpha OneMinusSrcAlpha
  18.  
  19.  
  20. CGPROGRAM
  21. #pragma surface surf ToonRamp vertex:vert addshadow keepalpha // addshadow applies shadow after vertex animation
  22.  
  23. sampler2D _Ramp;
  24.  
  25. // custom lighting function that uses a texture ramp based
  26. // on angle between light direction and normal
  27. #pragma lighting ToonRamp exclude_path:prepass
  28. inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten)
  29. {
  30. #ifndef USING_DIRECTIONAL_LIGHT
  31. lightDir = normalize(lightDir);
  32. #endif
  33.  
  34. half d = dot (s.Normal, lightDir)*0.5 + 0.5;
  35. half3 ramp = tex2D (_Ramp, float2(d,d)).rgb;
  36.  
  37. half4 c;
  38. c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
  39. c.a = s.Alpha;
  40. return c;
  41. }
  42.  
  43. sampler2D _MainTex;
  44. float4 _Color;
  45. float _Radius;
  46.  
  47. float _Speed;
  48. float _SwayMax;
  49. float _YOffset;
  50. float _Rigidness;
  51. float _MaxWidth;
  52.  
  53. uniform float3 _Positions[100];
  54. uniform float _PositionArray;
  55.  
  56. struct Input {
  57. float2 uv_MainTex : TEXCOORD0;
  58. };
  59. void vert(inout appdata_full v)//
  60. {
  61. // basic swaying movement
  62. float3 wpos = mul(unity_ObjectToWorld, v.vertex).xyz;// world position
  63. float x = sin(wpos.x / _Rigidness + (_Time.x * _Speed)) *(v.vertex.y - _YOffset) * 5;// x axis movements
  64. float z = sin(wpos.z / _Rigidness + (_Time.x * _Speed)) *(v.vertex.y - _YOffset) * 5;// z axis movements
  65. v.vertex.x += (step(0,v.vertex.y - _YOffset) * x * _SwayMax);// apply the movement if the vertex's y above the YOffset
  66. v.vertex.z += (step(0,v.vertex.y - _YOffset) * z * _SwayMax);
  67.  
  68. // interaction radius movement for every position in array
  69. for (int i = 0; i < _PositionArray; i++){
  70. float3 dis = distance(_Positions[i], wpos); // distance for radius
  71. float3 radius = 1- saturate(dis /_Radius); // in world radius based on objects interaction radius
  72. float3 sphereDisp = wpos - _Positions[i]; // position comparison
  73. sphereDisp *= radius; // position multiplied by radius for falloff
  74. v.vertex.xz += clamp(sphereDisp.xz * step(_YOffset, v.vertex.y), -_MaxWidth,_MaxWidth);// vertex movement based on falloff and clamped
  75. }
  76. }
  77.  
  78. void surf (Input IN, inout SurfaceOutput o) {
  79. half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
  80. o.Albedo = c.rgb;
  81. o.Alpha = c.a;
  82. }
  83. ENDCG
  84.  
  85. }
  86.  
  87. Fallback "Diffuse"
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement