PDA

View Full Version : GLSL fragment texturing with instancing



error17
03-03-2014, 11:28 PM
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.

mhagain
03-04-2014, 12:32 AM
You could do this with a texture array, letting the instance id (or some other per-instance attribute) specify which array slice to use.

skynet
03-04-2014, 02:29 AM
http://www.opengl.org/registry/specs/ARB/bindless_texture.txt might be what you're looking for.

error17
03-04-2014, 03:04 AM
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.

Dark Photon
03-04-2014, 06:00 AM
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.

skynet
03-04-2014, 11:15 AM
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.