Skip to content

Instantly share code, notes, and snippets.

@KeyMaster-
Created April 4, 2015 21:27
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save KeyMaster-/70c13961a6ed65b6677d to your computer and use it in GitHub Desktop.
Save KeyMaster-/70c13961a6ed65b6677d to your computer and use it in GitHub Desktop.
Cartesian to Polar coordinates warp shader, for shadertoy.com
//To be used on shadertoy.com
//Uses the image at iChannel0 and warps it into polar coordinates
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 relativePos = fragCoord.xy - (iResolution.xy / 2.0);
vec2 polar;
polar.y = sqrt(relativePos.x * relativePos.x + relativePos.y * relativePos.y);
polar.y /= iResolution.x / 2.0;
polar.y = 1.0 - polar.y;
polar.x = atan(relativePos.y, relativePos.x);
polar.x -= 1.57079632679;
if(polar.x < 0.0){
polar.x += 6.28318530718;
}
polar.x /= 6.28318530718;
polar.x = 1.0 - polar.x;
vec4 c = texture2D(iChannel0, polar);
fragColor = vec4(c);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment