Advertisement
Guest User

ToonLitSwayingVertexColor.shader

a guest
Aug 29th, 2018
1,038
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. Shader "Toon/Lit Vertex Sway" {
  2. Properties {
  3. [Header(Main)]
  4. _Color ("Main Color", Color) = (0.5,0.5,0.5,1)
  5. _MainTex ("Base (RGB)", 2D) = "white" {}
  6. _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {}
  7. [Space]
  8. [Header(Movement)]
  9. _Speed ("Speed", Range(0,2)) = 1
  10. _Amount ("Wave Amount", Range(0,2)) = 1
  11. _MaxWidth ("Max Width", Range(0,2)) = 1
  12. [MaterialToggle] XZAxis ("XZ Axis? (Otherwise YZ)", Float) = 0
  13. }
  14.  
  15. SubShader {
  16. Tags { "RenderType"="Opaque" }
  17. LOD 200
  18. Cull Off
  19.  
  20. CGPROGRAM
  21. #pragma surface surf ToonRamp vertex:vert addshadow
  22. #pragma multi_compile _ XZAXIS_ON
  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 = 0;
  40. return c;
  41. }
  42.  
  43. sampler2D _MainTex;
  44. float4 _Color;
  45. float _Speed;
  46. float _Amount;
  47. float _MaxWidth;
  48.  
  49. struct appdata{
  50. float4 color: COLOR; // vertex colors
  51. };
  52.  
  53. struct Input {
  54. float2 uv_MainTex : TEXCOORD0;
  55. };
  56.  
  57. void vert( inout appdata_full v )
  58. {
  59. float4 worldSpaceVertex = mul( unity_ObjectToWorld, v.vertex );
  60. #if XZAXIS_ON
  61. v.vertex.xz += sin( _Time.y * _Speed + worldSpaceVertex.y * _Amount ) * _MaxWidth * v.color.r;
  62. #else
  63. v.vertex.yz += sin( _Time.y * _Speed + worldSpaceVertex.y + worldSpaceVertex.x * _Amount ) * _MaxWidth * v.color.r;
  64. #endif
  65. }
  66.  
  67. void surf (Input IN, inout SurfaceOutput o) {
  68. half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
  69. o.Albedo = c.rgb;
  70. o.Alpha = c.a;
  71. }
  72. ENDCG
  73.  
  74. }
  75.  
  76. Fallback "Diffuse"
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement