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