GLSL fragment texturing with instancing

In a nut shell: Is there a way to have a specific texture bound depending on what instance is currently processed?

This idea can apply to many uses, for example a cube would only need to be uploaded once and to draw it multiple times you can use instancing and various methods to translate each cube. But my problem is that texturing each cube is a different beast. If the sampler2D has no constructor to let you choose the texture buffer of choice inside the shader, then it seems like you can only bind 1 texture for the entire instancing batch.

I’ve thought about rendering the instances in batches according to what their texture should be, but what if object order is important which could apply to 2D rendering with textured quads.

You could do this with a texture array, letting the instance id (or some other per-instance attribute) specify which array slice to use.

http://www.opengl.org/registry/specs/ARB/bindless_texture.txt might be what you’re looking for.

wow yes that’s great, thanks its working!

I’m just curious, is this only available on Nvidia cards like GTX 680+ because I would like to make my application as compatible as possible.

If pre-Kepler (pre-680) and/or cross-vendor compatibility is important, see mhagain’s reply. This only requires an OpenGL 3.x capable card, and is cross-vendor.

The problem with array textures is that all the textures you put in one array have to match in size and format. That might not be very orthogonal to the input dataset.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.