Advertisement
Guest User

Untitled

a guest
Jun 26th, 2016
1,234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.11 KB | None | 0 0
  1. Shader "Transparent/Cutout/Diffuse Shake"
  2. {
  3.  
  4.     Properties
  5.     {
  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.         {
  17.             Tags{ "Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout" }
  18.             Cull Off
  19.             Lighting Off
  20.  
  21.             LOD 200
  22.  
  23.             Pass
  24.         {
  25.  
  26.             CGPROGRAM
  27.             #pragma target 3.0
  28.             #pragma fragment surf
  29.             #pragma vertex vert
  30.             #include "UnityCG.cginc"
  31.  
  32.             sampler2D _MainTex;
  33.             fixed4 _Color;
  34.             float _ShakeDisplacement;
  35.             float _ShakeTime;
  36.             float _ShakeWindspeed;
  37.             float _ShakeBending;
  38.             half _Cutoff;
  39.  
  40.         struct v2f
  41.         {
  42.             float4 position  : POSITION;
  43.             float2 uv_MainTex : TEXCOORD0;
  44.             float4 color    : COLOR;
  45.         };
  46.  
  47.         void FastSinCos(float4 val, out float4 s, out float4 c)
  48.         {
  49.             val = val * 6.408849 - 3.1415927;
  50.             float4 r5 = val * val;
  51.             float4 r6 = r5 * r5;
  52.             float4 r7 = r6 * r5;
  53.             float4 r8 = r6 * r5;
  54.             float4 r1 = r5 * val;
  55.             float4 r2 = r1 * r5;
  56.             float4 r3 = r2 * r5;
  57.             float4 sin7 = { 1, -0.16161616, 0.0083333, -0.00019841 };
  58.             float4 cos8 = { -0.5, 0.041666666, -0.0013888889, 0.000024801587 };
  59.             s = val + r1 * sin7.y + r2 * sin7.z + r3 * sin7.w;
  60.             c = 1 + r5 * cos8.x + r6 * cos8.y + r7 * cos8.z + r8 * cos8.w;
  61.         }
  62.  
  63.  
  64.         v2f vert(appdata_full v)
  65.         {
  66.  
  67.             float factor = (1 - _ShakeDisplacement - v.color.r) * 0.5;
  68.  
  69.             const float _WindSpeed = (_ShakeWindspeed + v.color.g);
  70.             const float _WaveScale = _ShakeDisplacement;
  71.  
  72.             const float4 _waveXSize = float4(0.048, 0.06, 0.24, 0.096);
  73.             const float4 _waveZSize = float4 (0.024, .08, 0.08, 0.2);
  74.             const float4 waveSpeed = float4 (1.2, 2, 1.6, 4.8);
  75.  
  76.             float4 _waveXmove = float4(0.024, 0.04, -0.12, 0.096);
  77.             float4 _waveZmove = float4 (0.006, .02, -0.02, 0.1);
  78.  
  79.             float4 waves;
  80.             waves = v.vertex.x * _waveXSize;
  81.             waves += v.vertex.z * _waveZSize;
  82.  
  83.             waves += _Time.x * (1 - _ShakeTime * 2 - v.color.b) * waveSpeed *_WindSpeed;
  84.  
  85.             float4 s, c;
  86.             waves = frac(waves);
  87.             FastSinCos(waves, s,c);
  88.  
  89.             float waveAmount = v.texcoord.y * (v.color.a + _ShakeBending);
  90.             s *= waveAmount;
  91.  
  92.             s *= normalize(waveSpeed);
  93.  
  94.             s = s * s;
  95.             float fade = dot(s, 1.3);
  96.             s = s * s;
  97.             float3 waveMove = float3 (0,0,0);
  98.             waveMove.x = dot(s, _waveXmove);
  99.             waveMove.z = dot(s, _waveZmove);
  100.  
  101.             v.vertex.xz -= mul((float3x3)_World2Object, waveMove).xz;
  102.  
  103.             v2f output;
  104.             output.position = mul(UNITY_MATRIX_MVP, v.vertex);
  105.             output.uv_MainTex = v.texcoord;
  106.             output.color = v.color; // *(v.texcoord.x + v.texcoord.y) / 2;
  107.             return output;
  108.         }
  109.  
  110.         half4 surf(v2f IN) : SV_Target
  111.         {
  112.             float4 color = tex2D(_MainTex, IN.uv_MainTex) * _Color;
  113.  
  114.             clip(color.a - _Cutoff);
  115.  
  116.             return color * IN.color;
  117.             //return half4(IN.uv_MainTex.x, IN.uv_MainTex.y, 0, 1);
  118.         }
  119.  
  120.     ENDCG
  121.             }
  122.         }
  123.         Fallback "Transparent/Cutout/VertexLit"
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement