tonynogo

Demo 41 - Animated flag

Jul 6th, 2017
9,353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/Flag" {
  2.     Properties {
  3.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
  4.         _Speed ("Speed", Range(0, 5.0)) = 1
  5.         _Frequency ("Frequency", Range(0, 1.3)) = 1
  6.         _Amplitude ("Amplitude", Range(0, 5.0)) = 1
  7.     }
  8.     SubShader {
  9.         Tags { "RenderType"="Opaque" }
  10.         Cull off
  11.        
  12.         Pass {
  13.  
  14.             CGPROGRAM
  15.             #pragma vertex vert
  16.             #pragma fragment frag
  17.             #include "UnityCG.cginc"
  18.  
  19.             sampler2D _MainTex;
  20.             float4 _MainTex_ST;
  21.  
  22.             struct v2f {
  23.                 float4 pos : SV_POSITION;
  24.                 float2 uv : TEXCOORD0;
  25.             };
  26.  
  27.             float _Speed;
  28.             float _Frequency;
  29.             float _Amplitude;
  30.  
  31.             v2f vert(appdata_base v)
  32.             {
  33.                 v2f o;
  34.                 v.vertex.y +=  cos((v.vertex.x + _Time.y * _Speed) * _Frequency) * _Amplitude * (v.vertex.x - 5);
  35.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  36.                 o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  37.                 return o;
  38.             }
  39.  
  40.             fixed4 frag(v2f i) : SV_Target
  41.             {
  42.                 return tex2D(_MainTex, i.uv);
  43.             }
  44.  
  45.             ENDCG
  46.  
  47.         }
  48.     }
  49.     FallBack "Diffuse"
  50. }
Advertisement
Add Comment
Please, Sign In to add comment