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: Glsl and sampler2D

  1. #1
    Junior Member Newbie
    Join Date
    May 2008
    Posts
    5

    Glsl and sampler2D

    Hello to everybody,
    In the shader i am developing i need to read from a texture another texture id.

    In other word i have a texture where i saved some textures id generated by "glGenTexture" and i need to access to these textures using glsl.
    If i read using textureRect(, ); the returned value will be a float or an int and is not possible to cast it to a sampler2D in order to use again textureRect on the returned value.

    I read about "array of samplers" or "sampler2DArray" but i don't think it can be usefull cause i have to use a lot of texture.

    Do you have any advice? thanks!

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Dec 2000
    Location
    Reutlingen, Germany
    Posts
    2,042

    Re: Glsl and sampler2D

    I'd say that is not possible and GLSL does not intend you to do such things either.

    The only thing that you could do, would be to fetch from ALL the possible textures and then use another texture to mask out, what you really wanted.

    Jan.
    GLIM - Immediate Mode Emulation for GL3

  3. #3
    Junior Member Newbie
    Join Date
    May 2008
    Posts
    5

    Re: Glsl and sampler2D

    Thanks for the answer.
    I do not know if a explain me very well. How do you intend to fetch from all the possible texture? Could you give me an example?
    I send to my shader just a sempler2D texture and the fetched value is supposed to be another sampler2D texture to be fetched again in order to obtain the data i need.

    example of the sampler2D i send to the glsl shader:
    _ _ _ _ _ _ _ _ _ _ _ _ _
    | tex id1 | tex id2 | ... |
    _ _ _ _ _ _ _ _ _ _ _ _ _
    | ...... | ...... | ..... |
    _ _ _ _ _ _ _ _ _ _ _ _ _
    | ...... | ...... | ..... |
    _ _ _ _ _ _ _ _ _ _ _ _ _
    | ...... | ...... | ... ... |
    _ _ _ _ _ _ _ _ _ _ _ _ _
    | ...... | ...... | idn |
    _ _ _ _ _ _ _ _ _ _ _ _ _

  4. #4
    Advanced Member Frequent Contributor scratt's Avatar
    Join Date
    May 2008
    Location
    Thailand
    Posts
    556

    Re: Glsl and sampler2D

    Bear in mind you will be limited by the number of texture units your GPU has.
    8, 16 or perhaps 32 in total.

    That kind of makes your idea a little inefficient.

    As Jan says GLSL does not let you change texture bindings within them, so you are stuck with whatever is setup out of your maximum 8 or 16 once in the shader.

    What you could do is tile big textures with lots of small texture tiles, and then create texture coords based on some kind of data stored in another texture / buffer to access those tiles...

  5. #5
    Junior Member Newbie
    Join Date
    May 2008
    Posts
    5

    Re: Glsl and sampler2D

    Thaks to all! I had to change approach of course.
    I will pass just some a subset of them to a multipass shader...

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Sep 2004
    Location
    Prombaatu
    Posts
    1,386

    Re: Glsl and sampler2D

    How about using a texture to sample an offset (not necessarily a name generated by GL) to index a texture array.

    Something like

    texture2DArray(texSampler, vec3(st, texture2D(indexSampler, st).r ));

    ...

    Or something like that. The whole point of texture arrays is to minimize batch counts by packing as many materials as possible into an array and rendering as much of the scene as is possible in one go. Clever indexing is the name of the game here, or so it would seem.

Posting Permissions

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