instanced rendering?

benblobenblo Posts: 29
edited January 10 in Extensions

We're developing a scattering tool, a typical scene has 250k instances (comes to 10-20m triangles), which the canvas viewport can't really handle, we're down to non-interactive framerates (< 1 fps).

After drilling down deep inside InlineDrawing I figured out that drawPolygonMeshInstances actually doesn't really use GL instancing at all, it just stores xfos and uniforms per-instance in KL structures, then does uniform bindings + one render draw call per-instance... 245k draw calls are not ideal for our usecase.

I'm playing around with GL instanced rendering (*), I've created an InlineMeshShapeInstanced and its adaptor, and basically replaced glDrawElements with glDrawElementsInstanced.
This works fine, a test graph with 1m cubes (12m tris) renders at 10-15fps with GL instancing, vs < 1fps with the builtin drawPolygonMeshInstances.

My test so far is super simple, cube positions are computed procedurally in the shader. So now I need to pass data per-instance (xfos, basically, or matrices).

My first instinct was to pass a uniform array... but the InlineUniform API doesn't support arrays (unless I'm missing something), which is a real shame BTW (**). And anyway, on second thought uniforms would be bound each frame: probably not a good idea for big arrays (?).

So another route is to use a texture such as the InlineMatrixArrayTexture, but that sounds like a hack, if I want to pass other types of instance data I'd have to make a new texture type + adaptor every time... meh.

Lastly I saw that OpenGL has the concept of instance attributes, which looks like exactly what I need (?). Does InlineDrawing have any support for those?

Has anyone done instancing before? Am I going the right way at all? Suggestions welcome :) !

(*) Disclaimer: I'm rather new to OpenGL (more of a DX guy), and even more new to instancing.
(**) Seems like it should be feasible to modify the InlineDrawing extension to add support for arrays, but oh boy.

R&D Developer at Dwarf Animation Studio

Sign In or Register to comment.