1.代码
Shader "Custom/Flag2"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
//频率
_FrequencyY("frequency Y", float) = 1
//飘动幅度
_StrengthY("amplitude strengthY", float) = 1
//波长
_WaveLengthY("wave length Y", float) = 1
}
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;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float _FrequencyY;
float _StrengthY;
float _WaveLengthY;
v2f vert(appdata v)
{
v2f o;
o.uv = v.uv;
//y方向的扰动
float y = sin(_Time.y * _FrequencyY + (v.vertex.x + v.vertex.z * 0.6) * _WaveLengthY) * o.uv.y;
float4 offset = float4(0, 0, 0, 0);
offset.y = y * _StrengthY;
o.vertex = UnityObjectToClipPos(v.vertex + offset);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex,i.uv);
return col;
}
ENDCG
}
}
}
效果: