Created
April 4, 2015 21:27
-
-
Save KeyMaster-/70c13961a6ed65b6677d to your computer and use it in GitHub Desktop.
Cartesian to Polar coordinates warp shader, for shadertoy.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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