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!

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.

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 |


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…

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

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.