Skip to content

Conversation

@RenaudRohlinger
Copy link
Collaborator

@RenaudRohlinger RenaudRohlinger commented Nov 11, 2025

Description
Add support for direct usage of StorageInstancedBufferAttribute for instanceMatrix of InstancedMesh (or any type of Mesh tagged with mesh.isInstancedMesh.

For example:

const instanceMatrixStorage = new THREE.StorageInstancedBufferAttribute()

const instancedMesh = new THREE.InstancedMesh(geometry, material, count)
instancedMesh.instanceMatrix = instanceMatrixStorage

// -> No need for any tricky patch in positionNode or vertexNode anymore nor buffer duplication and update in InstancedNode

Can be very useful for advanced usage without having to create complex nodes by naturally make use of the InstancedNode and NodeMaterial pipeline.

Alternative would be to expose InstanceNode and patch via prototype the old WebGLRenderer way which I don't recommend.

This contribution is funded by Utsubo & Three.js Blocks

@github-actions
Copy link

github-actions bot commented Nov 11, 2025

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 356.24
86.48
356.24
86.48
+0 B
+0 B
WebGPU 615.49
172.75
615.97
172.86
+476 B
+110 B
WebGPU Nodes 614.1
172.5
614.57
172.61
+476 B
+109 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 488.04
121.25
488.04
121.25
+0 B
+0 B
WebGPU 684.96
188.02
688.25
188.83
+3.29 kB
+803 B
WebGPU Nodes 626.68
171.22
629.97
172.05
+3.29 kB
+827 B

@sunag sunag added this to the r182 milestone Nov 11, 2025
} else {

const buffer = new InstancedInterleavedBuffer( instanceMatrix.array, 16, 1 );
// Both backends have ~64kb UBO limit; fallback to attributes above 1000 matrices.
Copy link
Collaborator

@Mugen87 Mugen87 Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated side note: This comment isn't 100% correct since the WebGL 2 backend has a guaranteed size of only 16KB, see #30560 (comment). 64KB is supported on most platforms though. It would still be safer to set count to a smaller value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants