shader 一步一步 日记累月 ----极坐标
学习shader 就是在考察 数学知识
极坐标
极坐标

复习一下极坐标的点的位置是靠theta(角度)和r(距离)两个信息(二维空间)
shader:
// 直角坐标转极坐标方法
float2 RectToPolar(float2 uv, float2 centerUV) {
uv = uv - centerUV; //改变中心 将中心从UV左下角移到UV中心
float theta = atan2(uv.y, uv.x); // atan()值域[-π/2, π/2]一般不用; atan2()值域[-π, π]确定一个完整的圆
float r = length(uv); //UV上的某一点到我们确定的中心得距离
return float2(theta, r);
}
// 输出结构>>>像素
half4 frag(VertexOutput i) : COLOR {
// 直角坐标转极坐标
float2 thetaR = RectToPolar(i.uv, float2(0.5, 0.5));
// 极坐标转纹理采样UV
float2 polarUV = float2(
thetaR.x / 3.141593 * 0.5 + 0.5, // θ从[-π, π]映射到[0, 1]
thetaR.y + frac(_Time.x * 3.0) // r随时间流动
);
// 采样MainTex
half4 var_MainTex = tex2D(_MainTex, polarUV);
// 处理最终输出
half3 finalRGB = (1 - var_MainTex.rgb) * _Color;
half opacity = (1 - var_MainTex.a) * _Opacity ;
// 返回值
return half4(finalRGB * opacity, opacity);
}
//Alpha 通道是为保存选择区域而专门设计的通道,所以第四个值取1或者0或任意值都没什么变化
//真正让图片变透明的不是Alpha 实际是Alpha所代表的数值和其他数值做了一次运算
https://blog.csdn.net/weixin_43789369/article/details/131710623
浙公网安备 33010602011771号