Advertisement
Guest User

Diffuse Shake (Grass and Foliage) Shaderfor Unity

a guest
Jun 25th, 2018
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. // Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject'
  2.  
  3. Shader "Transparent/Cutout/Diffuse Shake" {
  4.  
  5. Properties {
  6. _Color ("Main Color", Color) = (1,1,1,1)
  7. _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
  8. _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
  9. _ShakeDisplacement ("Displacement", Range (0, 1.0)) = 1.0
  10. _ShakeTime ("Shake Time", Range (0, 1.0)) = 1.0
  11. _ShakeWindspeed ("Shake Windspeed", Range (0, 1.0)) = 1.0
  12. _ShakeBending ("Shake Bending", Range (0, 1.0)) = 1.0
  13. }
  14.  
  15. SubShader {
  16. Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
  17. LOD 200
  18.  
  19. CGPROGRAM
  20. #pragma target 3.0
  21. #pragma surface surf Lambert alphatest:_Cutoff vertex:vert addshadow
  22.  
  23. sampler2D _MainTex;
  24. fixed4 _Color;
  25. float _ShakeDisplacement;
  26. float _ShakeTime;
  27. float _ShakeWindspeed;
  28. float _ShakeBending;
  29.  
  30. struct Input {
  31. float2 uv_MainTex;
  32. };
  33.  
  34. void FastSinCos (float4 val, out float4 s, out float4 c) {
  35. val = val * 6.408849 - 3.1415927;
  36. float4 r5 = val * val;
  37. float4 r6 = r5 * r5;
  38. float4 r7 = r6 * r5;
  39. float4 r8 = r6 * r5;
  40. float4 r1 = r5 * val;
  41. float4 r2 = r1 * r5;
  42. float4 r3 = r2 * r5;
  43. float4 sin7 = {1, -0.16161616, 0.0083333, -0.00019841} ;
  44. float4 cos8 = {-0.5, 0.041666666, -0.0013888889, 0.000024801587} ;
  45. s = val + r1 * sin7.y + r2 * sin7.z + r3 * sin7.w;
  46. c = 1 + r5 * cos8.x + r6 * cos8.y + r7 * cos8.z + r8 * cos8.w;
  47. }
  48.  
  49.  
  50. void vert (inout appdata_full v) {
  51.  
  52. float factor = (1 - _ShakeDisplacement - v.color.r) * 0.5;
  53.  
  54. const float _WindSpeed = (_ShakeWindspeed + v.color.g );
  55. const float _WaveScale = _ShakeDisplacement;
  56.  
  57. const float4 _waveXSize = float4(0.048, 0.06, 0.24, 0.096);
  58. const float4 _waveZSize = float4 (0.024, .08, 0.08, 0.2);
  59. const float4 waveSpeed = float4 (1.2, 2, 1.6, 4.8);
  60.  
  61. float4 _waveXmove = float4(0.024, 0.04, -0.12, 0.096);
  62. float4 _waveZmove = float4 (0.006, .02, -0.02, 0.1);
  63.  
  64. float4 waves;
  65. waves = v.vertex.x * _waveXSize;
  66. waves += v.vertex.z * _waveZSize;
  67.  
  68. waves += _Time.x * (1 - _ShakeTime * 2 - v.color.b ) * waveSpeed *_WindSpeed;
  69.  
  70. float4 s, c;
  71. waves = frac (waves);
  72. FastSinCos (waves, s,c);
  73.  
  74. float waveAmount = v.texcoord.y * (v.color.a + _ShakeBending);
  75. s *= waveAmount;
  76.  
  77. s *= normalize (waveSpeed);
  78.  
  79. s = s * s;
  80. float fade = dot (s, 1.3);
  81. s = s * s;
  82. float3 waveMove = float3 (0,0,0);
  83. waveMove.x = dot (s, _waveXmove);
  84. waveMove.z = dot (s, _waveZmove);
  85. v.vertex.xz -= mul ((float3x3)unity_WorldToObject, waveMove).xz;
  86.  
  87. }
  88.  
  89. void surf (Input IN, inout SurfaceOutput o) {
  90. fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
  91. o.Albedo = c.rgb;
  92. o.Alpha = c.a;
  93. }
  94. ENDCG
  95. }
  96.  
  97. Fallback "Transparent/Cutout/VertexLit"
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement