今天更新一個超簡單的圖片扭曲效果,上圖
微信號: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;
採樣圖片輸出顏色;