How to integrate indirect draw, instanced rendering and gpu occlusion culling in OpenGL

902 Views Asked by At

I am working on a rendering engine that uses draw indirect and instanced rendering to render scene geometry. Some objects are procedurally generated from instanced base shape such as a cube or a sphere, others are mesh objects that are instanced and used all over the scene. Right now instanced geometry is drawn using separate draw calls to glDrawElementsInstanced (efficient now but not good in general) and single objects (in a unified VBO) are drawn using a single call to glMultiDrawElementsIndirect. Since im using lighting and texturing (bindless) in the render pipeline and the scenes are complex with hundreds of thousands of meshes total i am in need to implement gpu occlusion and frustum culling. Its needed for both: taking the load off from fragment shader as well as vertex shader.

The main problem for me is finding a reasonable way to perform these gpu culling operations on instanced geometry. While all the culling stuff is pretty well illustrated by examples when it comes to objects that are rendered only once (using indirect draw), none of them seem to address the culling of instanced meshes. There seems no real obstruction in doing this but how to approach this in optimal manner.

I suggest the following:

  1. use only one draw indirect call for both instanced and non instanced geometry. (no real reason to keep these separate since glMultidrawElementsIndirect provides instancing)
  2. Hold instance data of the meshes in two separate buffers(SSBO). One that has all the instance data of all scene objects, the other that has instance data of visible instances. Draw indirect commands are written in compute shader (after culling) with adjusted instance count and base instance (am i correct here), based on some kind of visibility index?

The question is: is this duplication of instance data (into 2 separate buffers) reasonable or is there more efficient way of doing this?

0

There are 0 best solutions below