I am facing an issue with my shader material setup. I have a shader material that is working properly and has a texture attached to it.
Now, I want to create two meshes using this shader material but with different textures for each mesh. However, when I try to render both meshes in the scene, the material of the first object somehow gets overwritten and ends up using the same material as the second object.
var dataShader = VJS.shaders.data;
var uniforms = dataShader.parameters.uniforms;
// Setting texture size (currently 2048)
uniforms.uTextureSize.value = stack._textureSize;
// Array of 16 textures
uniforms.uTextureContainer.value = textures;
// Texture dimensions
uniforms.uDataDimensions.value = new THREE.Vector3(stack._columns, stack._rows, stack._nbFrames);
// World to model transformation
uniforms.uWorldToData.value = stack._lps2IJK;
var sliceMaterial = new THREE.ShaderMaterial({
'side': THREE.DoubleSide,
'transparency': true,
'uniforms': uniforms,
'vertexShader': dataShader.parameters.vertexShader,
'fragmentShader': dataShader.parameters.fragmentShader,
});
var slice = new THREE.Mesh(sliceGeometry, sliceMaterial);
// Adding the mesh object to the scene
this.add(slice);
Is this behavior expected? If so, is there a workaround to prevent the material overwriting issue?
Thank you.