Wave effects in Unity using ShaderLabs

Shader "praveenmax/TestWaveShader"
{
	Properties
	{
		_MainTex ("Texture", 2D) = "white" {}
		_MyColor ("MyColor", Color) = (0,0,1,1)
		_StartVertexShader("StartVertexShader", int) = 0
		_StartFragmentShader("StartFragmentShader", int) = 0
	    _WaveStrengthX("WaveStrength X", float) = 2
		_WaveStrengthY("WaveStrength Y", float) = 2
	}
	SubShader
	{
		Tags { "RenderType"="Opaque" }
		LOD 100

		Pass
		{
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag

			
			#include "UnityCG.cginc"

			struct appdata
			{
				float4 vertex : POSITION;
				float2 uv : TEXCOORD0;
			};

			struct v2f
			{
				float2 uv : TEXCOORD0;
				UNITY_FOG_COORDS(1)
				float4 vertex : SV_POSITION;
			};

			sampler2D _MainTex;
			float4 _MainTex_ST;
			float4 _MyColor;
			int _StartVertexShader, _StartFragmentShader;
			int _WaveStrengthX, _WaveStrengthY;
			
			v2f vert (appdata v)
			{
				v2f o;
				o.vertex = UnityObjectToClipPos(v.vertex);

				//get the world coords 
				float worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
				//o.vertex.y += sin(worldPos.y + _Time.w);

				if (_StartVertexShader == 1)
				{
					o.vertex.y += sin(worldPos.x * _WaveStrengthX + _Time.w) / 2;
					o.vertex.x += sin(worldPos.x * _WaveStrengthY + _Time.z) / 4;
				}

				o.uv = TRANSFORM_TEX(v.uv, _MainTex);
				return o;
			}
			
			fixed4 frag (v2f i) : SV_Target
			{
				// sample the texture
				fixed4 col = tex2D(_MainTex, i.uv);
				
				if (_StartFragmentShader == 1)
				{
					col.x += sin(col.x + _Time.w) /2;
					col.y += sin(col.x + _Time.w) /2;
					col.z += sin(col.x + _Time.w) /2;

				}

				return col;
			}
			ENDCG
		}
	}

	Fallback "VertexLit"
}

About Max
My Interests: ------------------ Programming

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: