在 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);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章