Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.