在 shader 里判断圆范围的方法

因为总忘,所以做下笔记

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);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值