Skip to content

WebGPURenderer/NodeMaterial: material/shader rebuild when adding a second InstancedMesh with identical geometry & material #31805

@AndreyPrakhov

Description

@AndreyPrakhov

Description

Even when using the same material and the same geometry, adding a new Mesh or InstancedMesh causes the node material to be rebuilt and the shader to be recompiled.

This can be clearly seen in the profiler screenshots: as soon as the second object with the same geometry and material is added, a new material build and shader compilation happens, even though the resources are identical.

Reproduction steps

After starting the example, spikes will be visible in the profiler.

Code

// WebGPURenderer({ forceWebGL: true })
const geometry = new THREE.BoxGeometry();
const material = new THREE.MeshStandardNodeMaterial();

setTimeout( () =>{
    const mesh = new THREE.InstancedMesh( geometry, material, 100 );

    for (let i = 0; i < 100; i++) {
      mesh.setMatrixAt(i, new THREE.Matrix4().makeTranslation(i, 0, 0))
    }

    scene.add( mesh );
}, 3000 );

setTimeout( () =>{
    const mesh = new THREE.InstancedMesh( geometry, material, 100 );

    for (let i = 0; i < 100; i++) {
      mesh.setMatrixAt(i, new THREE.Matrix4().makeTranslation(i, 0, 10))
    }

    scene.add( mesh );
}, 3100 );

Live example

https://jsfiddle.net/eqLwa08c/3/

Screenshots

Image

Version

^0.179.1

Device

Desktop

Browser

Chrome

OS

Linux

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions