Hi, I’ve been trying to draw some vertices and pick them. I noticed that BatchedMesh has a setVisibleAt method, which makes it convenient to change the visibility property. However, InstancedMesh doesn’t have this feature. Should I prioritize using InstancedMesh ? Does InstancedMesh offer better performance than BatchedMesh ? I know both can merge draw calls, but I’m curious about the trade-offs.
And I found that when instances of an InstancedMesh overlap in position, the setColorAt method fails to change the color properly. Could someone explain why this happens? The example I referenced is this.
Both InstancedMesh and BatchedMesh support a single material and render all instances in a single draw call. Where they differ is in how they handle multiple geometries:
-
If you’re using a single geometry, always use
InstancedMesh. -
If you have a few geometries (2–4) and many instances, you can still manage separate
InstancedMeshfor each geometry. -
If you’re dealing with many geometries,
BatchedMeshbecomes the most efficient solution.
If you need more control over the official InstancedMesh, consider using InstancedMesh2, @agargaro did an amazing work at extending its capabilities (Visibility, sorting, frustum culling, LOD…)
Thanks, I’ll take a look.
Do you know why the color cannot change when positions overlap? Is it because of the rendering order?
If you have overlapping instances rendered in the wrong order, the result can appear visually incorrect due to improper depth sorting. You can check out this points particles example to see how particle indices are sorted based on depth:
You can also take a look at how depth sorting is handled in BatchedMesh for both opaque and transparent objects:
BatchedMesh used to implement a more complex Radix sort algorithm, which could be up to 7x faster for large datasets. I assume it was replaced for the sake of simplicity.
Thanks a lot! I’ll take a look at it.
I’ve included an example with radix sort also for InstancedMesh2 (based on BatchedMesh) ![]()
I’m not sure if my understanding is correct. Suppose I have rocks and trees that need to be rendered. If I use instanceMesh, I need to create instanceMesh for both the rock geometry and the tree geometry. If I use BatchedMesh, I only need to create one and add it to it using addGeometry, right? So what is the difference between the two in terms of performance?
BatchedMesh uses multiDraw while InstancedMesh uses instancedDraw.
MultiDraw performs worse if you render a lot instances (more than 100k), but it is very useful if you need to draw multiple geometries.
If you have many different types of trees and rocks, it may be better to use BatchedMesh, otherwise InstancedMesh performs better.
With InstancedMesh2 you can easily add LODs.
With BatchedMesh, this becomes possible using this extension I wrote.
Most of my work is focused on creating open worlds, if you’re interested (webgl only for now).