Clone a ShaderMaterial and Have Different Uniforms for Different Copies of the Material

const mesh2 = new THREE.Mesh(geometry, material.clone());

You’re cloning the material, they also by default have a custom set of uniforms as they are cloned too when cloning a ShaderMaterial.

You might be interested in this plugin i made for that purpose, to use a single material instance but use different uniform values on the fly derived from the mesh for instance. It saves you from cloning materials and all their properties just to change some parameters.

Recently also added a concept for shader code sharing to avoid having a copy of the shader string of every cloned ShaderMaterial, gonna add it in the next release. It essentially makes ShaderMaterials more lightweight like using in-built materials.

2 Likes