-
-
Notifications
You must be signed in to change notification settings - Fork 36k
Description
Description
Hi guys,
Regarding BatchedMesh, it was using the multiDraw[Arrays|Elements]Instanced in its earlier versions, but for some reason, this feature was deprecated. The current implementation emulates instancing by repeating the multidraw[Array|Elements] API parameters. Nonetheless, this approach is slower when compared to its instantiated flavor.
To demonstrate this, I've scratched a simple example comparing the performance of multidrawElements, multidrawElementsInstanced, and the regular drawElementsInstanced API. I am using the raw webgl api in all rendering methods to avoid introducing some overhead from the ThreeJS implementation, such as indirection in BatchedMesh rendering. When we switch the rendering API, I only change the rendering API.
My setup:
- Processor: AMD Ryzen 9 7940HS , 4001 Mhz, 8 Core(s), 16 Logical Processor(s)
- RAM: 32 GB
- iGPU: Radeon 780M Graphics. Driver 7.06.02.123
- dGPU: NVIDIA GeForce RTX 4080. Driver 576.88, Jul 2025.
Example: https://codepen.io/andredsm/full/zxrOjrx
In my environment, when comparing multidrawElements vs multidrawElementsInstantiated, the second approach's speedup is ~1.5x in iGPU, while in dGPU is around 2x. The performance is the same when comparing the multidrawElementsInstantiated vs drawElementsInstantiated because my scene has only a single geometry. When the scene has several different geometries instantiated, the multidrawElementsInstantiated produces better results.
I know Firefox lacks support for multidraw*Instantiated API. Still, it would be beneficial if ThreeJS provided this rendering mechanism and a fallback for Firefox users, as the current BatchedMesh already does for regular multidraw calls.
Solution
When using multidraw + instancing, the BatchedMesh should use the multidraw*Instantiated rendering API. In case this API is not available, the rendering could be done using the current approach.
Alternatives
I considered using InstancedMesh for rendering several instanced geometries, but in cases where we have several different geometries, the engine issues 1 draw call/geometry.
Additional context
No response