I’m working with a designer who wants to render 10k(ish) trees in our scene. From looking at various instancing examples, it seems like this should be plausible, but in practice, it’s lagging hard.
I’ve created a playground that places 10k instances of our model. My understanding of instancing is that I should be seeing only a handful of draw calls, not the 1.5k+ I get with this scene (as per screenshot below).
I’ve also noticed, that if I leave the scene for some time, eventually the number of draw calls drops to 101. I can’t see any reasoning behind this, but naturally the FPS/performance is smoother once this kicks in.
Have you tried alwaysSelectAsActiveMesh = true on the instances?
My GPU sucks, so my frame-time takes up most of the frame budget, but coming in second is meshes selection
if you scroll down you will notice that the amount of draw calls whether you have 10 or 10000 trees is the same. the issue you are experiencing (reduced performance) is due to the mesh-selection process. There are a few ways to optimize this process, one of them to set the meshes to always be selected (mesh.alwaysSelectAsActiveMesh).
Hmm. Setting scene.freezeActiveMeshes() after instantiating the trees seems to help.
Perhaps there’s a bug preventing instances from shortcutting the culling process?
With spheres it seems to work. Each gltf mesh with a different material is converted into primitives. Check the Inspector. So I believe that one mesh/one material x instances = 1 draw call. Maybe thats the reason. Maybe you could try to populate the scene with two spheres with different materials and check whether id doubles the draw calls.
Ok problem solved
It was acutally a bad design that I implemented in the SceneExplorer. Every time a new mesh was created I recreated the entire scene explorer. That was forcing the CPU to spend 100% of its time in react
The next nightly will come with a fix so you should not see crazy (and wrong) numbers for draw calls anymore
Furthermore, I slightly updated the initial PG to remove picking for the trees and the ground to avoid perf issues when moving the mouse:
I was confused as to why that material freeze would free up so much, but turns out that line hid the ground in your PG, therefore clearing the draw calls: