Created
May 9, 2017 11:38
-
-
Save nevarman/5a6074a5a54749f05678c4866fda6848 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Original shader by cboe - Mar, 23, 2009 | |
// Enhanced to 3 axis movement by Seon - Jan, 21, 2010 | |
// Added _WaveSpeed - Jan, 26, 2010 | |
// | |
// Requirements: assumes you are using a subdivided plane created with X (width) * Z (height) where Y is flat. | |
// Requirements: assumes UV as: left X (U0) is attatched to pole, and Top Z (V1) is at top of pole. | |
// | |
// Enjoy! | |
Shader "Custom/FlagWave" | |
{ | |
Properties | |
{ | |
_Color("Main Color", Color) = (1,1,1,1) | |
_MainTex("Texture", 2D) = "white" { } | |
_WaveSpeed("Wave Speed", Range(0.0, 150.0)) = 50.0 | |
_Distance("Wawe distance", Vector) = (0.5,0.9,0.2,0.0) | |
} | |
SubShader | |
{ | |
Pass | |
{ | |
Cull Off Lighting On ZWrite On //Ztest Always | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
#include "AutoLight.cginc" | |
float4 _Color; | |
sampler2D _MainTex; | |
float _WaveSpeed; | |
float4 _Distance; | |
// vertex input: position, normal | |
struct appdata { | |
float4 vertex : POSITION; | |
float4 texcoord : TEXCOORD0; | |
}; | |
struct v2f { | |
float4 pos : POSITION; | |
float2 uv: TEXCOORD0; | |
}; | |
v2f vert(appdata v) { | |
v2f o; | |
float sinOff = v.vertex.x + v.vertex.y + v.vertex.z; | |
float t = -_Time*_WaveSpeed; | |
float fx = v.texcoord.x; | |
float fy = v.texcoord.x * v.texcoord.y; | |
v.vertex.x += sin(t*1.45 + sinOff)*fx*_Distance.x; | |
v.vertex.y = sin(t*3.12 + sinOff)*fx*_Distance.x - fy*_Distance.y; | |
v.vertex.z -= sin(t*2.2 + sinOff)*fx*_Distance.z; | |
o.pos = mul(UNITY_MATRIX_MVP, v.vertex); | |
o.uv = v.texcoord; | |
return o; | |
} | |
float4 frag(v2f i) : COLOR | |
{ | |
half4 color = tex2D(_MainTex, i.uv); | |
return color * _Color; | |
} | |
ENDCG | |
SetTexture[_MainTex]{ combine texture } | |
} | |
} | |
Fallback "VertexLit" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment