Shader "Custom/Wave" {
Properties
{
_scope("scope", range(0, 2)) = 0.2
_frequency("frequency",range(0, 2)) = 0.2
_speed("speed", range(0, 5)) = 5.0
}
SubShader
{
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "unitycg.cginc"
float _scope;
float _frequency;
float _speed;
struct v2f
{
float4 pos : POSITION;
float4 color : COLOR0;
};
v2f vert(appdata_base v)
{
// y = A * Sin(w * x + t)
v.vertex.y += _scope * sin(v.vertex.x / _frequency + _Time.y * _speed);
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.color = fixed4(v.vertex.y, v.vertex.y, v.vertex.y, 1);
return o;
}
fixed4 frag(v2f IN) : COLOR
{
return fixed4(0, 1, 1, 1);
}
ENDCG
}
}
FallBack "Diffuse"
}
运行效果图
继续修改代码,添加一行:、
v.vertex.y += _scope * sin(v.vertex.z / _frequency + _Time.y * _speed);
使其在 Z 方向也有力的作用,这样效果就会好很多了。