I've got a simple app that draws 3D cubes using instance rendering and I'm implementing Shadow Volume. Each cube's vertex, uv, normal and index data are statically stored in 4 vertex array buffers. On each frame, I draw 10 cubes by uploading 10 world-view-projection matrices (one for each cube) to a 4th dynamic vertex array buffer (using vertex attr divisor) and then calling glDrawElementsInstanced once with 10 as primecount.
All my cubes are render properly in 1 draw call \o/
Now... I want to draw their shadow volumes in one draw call too! (for 1 directional light). I'm on Mac so I've acces to OpenGL 4.1. Here's my progress so far:
- I upload all vertices twice (once with the w attribute to 1 and once to 0). This will help me drawing the extruded silhouette in my vertex shader.
- On the CPU, I find each cube's silhouette (according to their orientation) and I create one list of indices for each cube (so 10 lists total) representing their shadow volume.
- And then I'm stuck...
I can't find a way to upload multiple list of index (one for each instance)... so far my vertex shader can work with each cube's matrix but can only work on 1 index array (the uniq GL_ELEMENT_ARRAY_BUFFER).
I've been googling a lot but could not find a solution. So I'm asking here: does anybody know how to implement Instanced Rendering with multiple indice lists? or does anybody know a better approach to render shadow volumes of multiple instances of the same object in one draw call?