PDA

View Full Version : Polar coordinates in texture2D



Mukund
08-16-2014, 01:04 AM
Hello All,

I was trying some sample shaders and i understand that we can supply polar coordinates to texture2D() instead of
Cartesian.
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?

Thanks!

Agent D
08-16-2014, 04:01 AM
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.

Mukund
08-16-2014, 04:20 AM
Thanks for the reply. I was just trying some stuff on shadertoy.

Here is the code:
https://www.shadertoy.com/view/XdBSzz

This needs WebGL support. As you can see, it actually samples in a circular fashion.
I don't understand how this is working internally.
Thanks!


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.

Aleksandar
08-16-2014, 05:09 AM
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.

Mukund
08-16-2014, 07:54 AM
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.
Thanks!


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.

Aleksandar
08-20-2014, 12:54 PM
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?

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.
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.