Polar coordinates in texture2D
I was trying some sample shaders and i understand that we can supply polar coordinates to texture2D() instead of
So, texture2D(sampler, vec2(r, theta)) actually sampled the texture in a circular way.
Can anyone please let me know how the driver does conversion from polar to cartesian internally?
I've never ever heard/read of something like that and it appears quite strange to me for GLSL to support polar texture coordinates.
I searched the glsl 330 spec as well as the OpenGL(R) 3.3 spec. I can't find the word "polar" anywhere in there. The "texture2D" function
in the GLSL spec (330 with changes marked, page 100) calls the texture2D function deprecated and suggests using the unprefixed functions
on page 93, which does not mention polar coordinates.
What GLSL version are you refering to and where did you read that it supports polar coordinates?
If you want to use polar texture coordinates, I would suggest converting them to cartesian coordinates in the shader.
Thanks for the reply. I was just trying some stuff on shadertoy.
Here is the code:
This needs WebGL support. As you can see, it actually samples in a circular fashion.
I don't understand how this is working internally.
Originally Posted by Agent D
And I don't understand what you don't understand.
There is a full shader code with description of all uniform variables used in the code.
There is no hidden internal work. GL_TEXTURE_WRAP_ is probably set to GL_REPEAT. You could try it by yourself and play with parameters.
I don't understand this part:
texture2D(iChannel0, vec2(r, a));
Should this expect a vec2() in cartesian form? How does it work with polar as well?
That is what i'm not able to follow. Sorry, maybe this is a silly question, but i don't understand that part.
Originally Posted by Aleksandar
Of course! texture2D() samples texture at (r,a), where r is actually x-coordinate and a is y-coordinate in Cartesian coordinate system, starting from the lower left corner of the texture.
Originally Posted by Mukund
But (r,a) is the result of the transformation of the fragment screen-position. The transformation creates an effect of rolling texture around the center of the screen. You can apply texture coordinates anyway you want to achieve desirable effect.