Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Polar coordinates in texture2D

  1. #1
    Junior Member Regular Contributor
    Join Date
    Mar 2010
    Posts
    211

    Polar coordinates in texture2D

    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!

  2. #2
    Junior Member Regular Contributor Agent D's Avatar
    Join Date
    Sep 2011
    Location
    Innsbruck, Austria
    Posts
    153
    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.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Mar 2010
    Posts
    211
    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!

    Quote Originally Posted by Agent D View Post
    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.

  4. #4
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,162
    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.

  5. #5
    Junior Member Regular Contributor
    Join Date
    Mar 2010
    Posts
    211
    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!

    Quote Originally Posted by Aleksandar View Post
    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.

  6. #6
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,162
    Quote Originally Posted by Mukund View Post
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •