Advertisement
Guest User

Cartesian to polar coordinate shader

a guest
Dec 23rd, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. // cartesian to polar CG screen shader
  2.  
  3. CGPROGRAM
  4.  
  5. uniform float _CenterX;
  6. uniform float _CenterY;
  7. uniform float _Angle;
  8. uniform float _AngleOffset;
  9. uniform sampler2D _MainTex;
  10.  
  11. float4 frag (v2f i) : COLOR
  12. {
  13.     // normalised screen-space pixel coords are taken from the input struct v2f
  14.     float2 uv = i.uvOrig;
  15.     // the angle between the centre point and the pixel coordinate is calculated
  16.     float angle = atan2(uv.x - _CenterX, uv.y + _CenterY);
  17.     // the distance between the centre point and the pixel coordinate is calculated
  18.     float radius = sqrt(pow(uv.x - _CenterX, 2) + pow(uv.y + _CenterY, 2));
  19.     // the pixel coordinates are reassigned
  20.     uv.x = angle / _Angle + _AngleOffset;
  21.     uv.y = radius - _CenterY;
  22.    
  23.     return tex2D(_MainTex, uv);
  24. }
  25.  
  26. ENDCG
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement