// 水波纹特效
/**
wave y = A sin(wt+theta)
amount = A/(speed*len)
**/
Shader "Study/05-WaveShader"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {
}
// 震幅
_Amount("Amount",Range(0.0,0.4)) = 0.2
// 频率
_W("W",Range(0,200)) = 100
// 衰减速度
_Speed("Speed",Range(0,1000)) = 500
// _Center("Center",fixed2) = fixed2(0,0)
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
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;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float _Amount;
float _W;
float _Speed;
fixed4 frag (v2f i) : SV_Target
{
//中心点
fixed2 center_uv = {
0.5,0.5};
fixed2 uv = i.uv;
// 到中心距离
float2 dt = center_uv-uv;
float2 len = sqrt(dot(dt,dt));
// 振幅
float amount = _Amount/(0.01+len*_Speed);
if(amount<0.01){
amount = 0;
}
uv.y +=amount*cos(len*_W* UNITY_PI);
fixed4 col = tex2D(_MainTex, uv);
return col;
}
ENDCG
}
}
}
[005-Shader-Water Ripple Special Effect]
Guess you like
Origin blog.csdn.net/qq_18924323/article/details/124863270
Recommended
Ranking