Which is more performant?
I expect to have up to thousands of boxes in my scene, but they’re all the same material. I don’t need to change the position after setting it when I create the box.
Just from trying it out, it seems like merging them all together is better for performance.
It depends on the situation But usually instances are more performant if you’re GPU bound, as it greatly reduces the amount of memory transferred. Merged meshes would be easier on the CPU as we only check one mesh for occlusion. Thin instances are a great “combination” of both, as they only have one occlusion check AND transfer less memory to GPU: Thin Instances | Babylon.js Documentation (babylonjs.com)
So I just discovered the Inspector, and from looking at the values in the realtime performance viewer, the two methods don’t really have a big difference in FPS.
I’ll have to check out thin instances and see how that performs in my case, but thanks a lot for mentioning them. They seem like the perfect fit for my scene, but it seems like scaling and position is a bit more complicated than with normal instances.
Edit: Thank you so much for suggesting thin instances. I replaced the two types of meshes that I have repeated over and over in my scene with thin instances, and my FPS just doubled!
So I’m back again with a very similar question: I have an imported mesh that I have in my scene over and over again. Those meshes all start out with the same texture, but when the user clicks one of them, that mesh takes on a different material and all others become semi-transparent by changing the alpha of their current material. So the material of those meshes needs to be able to change and not all of them will have the same material at all times.
I create those meshes by importing it once and then cloning them as many times as I need. This allows me to set their materials freely. But now I’m running into performance problems. Is there anything that would/could perform better in these circumstances (different materials, can change dynamically) than clones?
In principle, all instanced/thin instanced meshes have to have the same material, but you can change that material’s properties per instance by using custom buffers: Instances | Babylon.js Documentation
Yeah, I saw that you can change the color of the mesh, but can you also change it to a completely different material? I have 2 different materials, both using a different texture imported from a file, and I need to be able to switch between those
Edit: Sry I’m too dumb to read your answer before replying. Since I can’t change the material of instances, is there anything else that might be a better solution than using clones, given my circumstances? If not, is it possible to change the emissiveColor and alpha of the instances? After looking at VertexBuffer, I can only find one for ColorKind.
You can’t change the materials, but you can simulate different materials by changing some property per-instance and then using that to control the material. One example would be having different alpha values per instance: Thin instances simple example | Babylon.js Playground (babylonjs.com)
And you can go even further by changing things like textures using a custom shader: Thin instances simple example with Shader | Babylon.js Playground (babylonjs.com)
Oh great, thanks a lot. The second example with using a custom shader seems a bit too advanced for me at the moment. The first example seems like it could work for me, I’ll have to try it out and see.
Thanks a lot for the answer!