Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/linjf520/article/details/90649382
- Create a shader, paste the following code under
- Create a material, setting Shader: Custom / Wave
- Baidu easily download a water texture mapping, set to the meterial of Tex, (can not set the default white all-white, not so intuitive)
- Create a Plane, the material to drag it (or MeshRender.materials [0] set material created above)
Code
Shader "Custom/Wave"
{
Properties
{
_TintColor ("Tint Color", Color) = (1,1,1,1)
_Tex ("Tex", 2D) = "white" {}
_Speed ("Speed", Float) = 1.0
_Amp ("Amp", Float) = 0.3
}
SubShader
{
Pass
{
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
};
fixed4 _TintColor;
sampler2D _Tex;
float4 _Tex_ST;
float _Speed;
float _Amp;
v2f vert(appdata i)
{
v2f o = (v2f)0;
o.vertex = UnityObjectToClipPos(i.vertex);
o.vertex.y += sin(_Time.y * _Speed + o.vertex.x + o.vertex.y) * _Amp;
o.uv = TRANSFORM_TEX(i.uv, _Tex);
return o;
}
fixed4 frag(v2f i) : SV_TARGET
{
return tex2D(_Tex, i.uv) * _TintColor;
}
ENDCG
}
}
FallBack "Diffuse"
}
Runtime
Under Wireframe, you can clearly see the animation vertices