Reputation: 11
I use the librairy three.js to work in WebGL. In my case, I have two objects in my scene, I would like update my objects on the display independtly. I use shaders to modify the color of my objects, I would like modify the value of a uniform parameter of my fragment shader and apply the shader only on one of my objects. I would like apply a "drawElements" on my mesh and draw it with the new parameter. When I do "renderer.render( scene, camera );" I update all objects, and it's not what I want. How can I do this ? Could you help me please ?
Upvotes: 1
Views: 171
Reputation: 104823
If you are using a version prior to version r.53, you need to clone your uniforms for your second shader:
shaderB = shaderA.clone();
shaderB.uniforms = THREE.UniformsUtils.clone( shaderA.uniforms );
A better choice is to update to the current version, r.53. In that case, the uniforms cloning is done for you, and the following should be sufficient:
shaderB = shaderA.clone();
Upvotes: 0