Advertisement
Guest User

ToonLitSwaying.shader

a guest
Aug 7th, 2017
8,531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. Shader "Toon/Lit Swaying" {
  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.5// y offset, below this is no animation
  10.  
  11. }
  12.  
  13. SubShader {
  14. Tags { "RenderType"="Opaque" "DisableBatching" = "True" }// disable batching lets us keep object space
  15. LOD 200
  16.  
  17.  
  18. CGPROGRAM
  19. #pragma surface surf ToonRamp vertex:vert addshadow // addshadow applies shadow after vertex animation
  20.  
  21. sampler2D _Ramp;
  22.  
  23. // custom lighting function that uses a texture ramp based
  24. // on angle between light direction and normal
  25. #pragma lighting ToonRamp exclude_path:prepass
  26. inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten)
  27. {
  28. #ifndef USING_DIRECTIONAL_LIGHT
  29. lightDir = normalize(lightDir);
  30. #endif
  31.  
  32. half d = dot (s.Normal, lightDir)*0.5 + 0.5;
  33. half3 ramp = tex2D (_Ramp, float2(d,d)).rgb;
  34.  
  35. half4 c;
  36. c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
  37. c.a = 0;
  38. return c;
  39. }
  40.  
  41.  
  42. sampler2D _MainTex;
  43. float4 _Color;
  44.  
  45. float _Speed;
  46. float _SwayMax;
  47. float _YOffset;
  48. float _Rigidness;
  49.  
  50.  
  51. struct Input {
  52. float2 uv_MainTex : TEXCOORD0;
  53. };
  54. void vert(inout appdata_full v)//
  55. {
  56. float3 wpos = mul(unity_ObjectToWorld, v.vertex).xyz;// world position
  57. float x = sin(wpos.x / _Rigidness + (_Time.x * _Speed)) *(v.vertex.y - _YOffset) * 5;// x axis movements
  58. float z = sin(wpos.z / _Rigidness + (_Time.x * _Speed)) *(v.vertex.y - _YOffset) * 5;// z axis movements
  59. v.vertex.x += step(0,v.vertex.y - _YOffset) * x * _SwayMax;// apply the movement if the vertex's y above the YOffset
  60. v.vertex.z += step(0,v.vertex.y - _YOffset) * z * _SwayMax;
  61.  
  62. }
  63.  
  64. void surf (Input IN, inout SurfaceOutput o) {
  65. half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
  66. o.Albedo = c.rgb;
  67. o.Alpha = c.a;
  68. }
  69. ENDCG
  70.  
  71. }
  72.  
  73. Fallback "Diffuse"
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement