Suppose I have 100 trees of the same model spawned all over the scene in different locations. And these trees are instanced using the InstanceData vertex buffer of the mesh which contains all instances transforms.
AFAIK when instanced, GPU will render all these 100 trees in just one draw call.
Now my question is what if not all of these trees are inside camera view, for example, say only 10 trees are inside camera view. Now does GPU renders only these 10 trees or all of the 100 trees in one draw call?
In other words, is this InstanceData buffer updated each frame based on visible models before sending it to GPU?
Are you using JME’s Instance node stuff or rolling your own buffers. For JME’s InstanceNode or whatever, I’m only reasonably sure (95%). For your own rolled buffers, definitely 1 draw call with all of the instances. That code doesn’t even know what’s in the buffers.
With the current implementation instances are updated every frame anyway. It is possible to implement culling. You’ll have to skip position update for the culled instances and modify the value returned by getActualNumInstances. This will defacto rearrange the entries. No need to resize the buffer.
@RiccardoBlb appreciate your help. Interested to give this a try at some point. Unfortunately, I have not much understanding of underlying stuff so I won’t be able to do it on my own atm.
It seems after calling InstancedNode.instance() method it creates InstancedGeometry and adds instances into it, but it also keeps the original geometries attached to the parent.
Aren’t they going to be rendered twice? Once by instancing and once as a regular geometry?
I wonder why you include the code that has nothing to do with what you are claiming.
You would have to look deeper. As I recall, there is some weird juggling that happens in the instance node/geometry classes. It has to keep the original Geometry around but it swaps it with the instanced one as some critical point.
I could be wrong but that’s what I remember. I don’t use them personally as I always just roll my own buffers without all of the magic.