今天更新一个超简单的图片扭曲效果,上图
微信号:ITComputerGraph
如里工程:关注公众号《IT木子李》回复:unity图片旋转扭曲
float center = (0.5, 0.5);
float2 dt = i.uv - center;
float len = length(dt);
float theta = len * _Amount;
float2x2 rot = {cos(theta), -sin(theta),
sin(theta), cos(theta)};
dt = mul(rot, dt) + center;
float4 col = tex2D(_MainTex, dt);
return fixed4(col.rgb, 1);
代码很简单
将UV座标移动到图片中心;
通过计算象素到中心的距离获得要扭曲的程度;
UV和旋转矩阵相乘得到扭曲后的UV;
采样图片输出颜色;