因爲總忘,所以做下筆記
fixed4 frag (v2f i) : SV_Target
{
// uv向量
float2 vectorUV = i.texcoord - _OriginUV;
vectorUV.x *= _MainTex_TexelSize.y / _MainTex_TexelSize.x;
// 斜邊長度
float dis = sqrt(pow(vectorUV.x, 2) + pow(vectorUV.y, 2));
// 用0,1來標識是否在規定的範圍內
float isIn = step(_Radius, dis) - step(_Radius + _Width, dis);
// uv方向
float2 direction = normalize(i.texcoord - _OriginUV);
// 餘弦波
half cVal = cos(_Time.y * _WaveSpeed) / _Amplitude;
// 帶方向的uv
float2 noiseUV = i.texcoord + float2(cVal * _NoiseX, cVal * _NoiseY) * direction;
// 用噪聲紋理的採樣當uv
fixed4 noiseCol = tex2D(_NoiseTex, noiseUV);
float2 offset = noiseCol.xy;
// 最終顏色合成
fixed4 softParticleColor = i.color * 2.0f;
fixed4 mainColor = tex2D(_MainTex, i.texcoord + offset * isIn);