BufferGeometry: Let indirectOffset accept an array of offsets.#32413
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
|
The use case in our current project is a particle system with lots of different types of particles which are all rendered with different types of geometries & materials, so using a batched mesh wouldn't work. I had this use case before in other non-threejs projects so I dont think it's that uncommon. |
|
On another note, it feels wrong to set this on the BufferGeometry level, shouldn't it rather be part of the Mesh class? |
Oh I see, that was the final solution I was thinking about but thought it was overkill, I guess it's not if we want to accomodate all use cases indeed! |
|
So an API such as adding Multiple: const indirectAttribute = new THREE.IndirectStorageBufferAttribute( new Uint32Array( 5 * 100 ), 5 );
const indirectOffset = new Array( 5 * 100 )
geometry.setIndirect(indirectAttribute, indirectOffset) // <-- indirectOffset being Array or numberSingle: const indirectAttribute = new THREE.IndirectStorageBufferAttribute( new Uint32Array( 5 * 5 ), 5 );
const indirectOffset = 20
geometry.setIndirect(indirectAttribute, indirectOffset) // <-- numberI will update this PR to keep your work, add Array support in addition to single number |
|
Should be good, is this version ok with you @holtsetio? |
|
Looks good to me! |
indirectOffset accept an array of offsets.
Description
Edit: Add array support to indirectOffset which allow to easily batch multiple indirect draw with multiple indirectOffset, allowing to do all sort of super fast batch with WebGPU (notably a real BatchedMesh support command-wise in the future).
Here’s a demonstration of the potential: an indirect port of batched mesh, composed of thousands of geometries, GPU-culled via a compute shader and rendered in 0.5 ms, rendered via a single bundled command of thousands of indirect draw with each different data and indirect offset:

To achieve this with this PR, all that’s required is increasing the size of the indirect buffer:
/cc @holtsetio
This contribution is funded by Utsubo & Three.js Blocks