Shader uniforms with same name in different shader


I have 2 entities with 2 different but similar scripts attached that make a mesh, shader and material. They use 2 different shaders but the uniform names are identical. In the scripts I’m using
app.graphicsDevice.scope.resolve to then setValue to update the uniforms.

What’s happening now is that when I modify the uniform (via script attribute in the editor), it also affects the uniform with the same name of the shader on the other entity.

I feel like I’m missing a bit of information about the engine… how is it supposed to work when all uniforms are resolved from the same app.graphicsDevice.scope object?

Is there a method I can call to make a shader/material the current one so that a call to setValue is applied to only the right uniform? What am I missing?

Thanks in advance!

If you directly update values in scope, than as you noticed they overwrite each other. This is useful only for global parameters that are constant for the frame.

It sounds like you should just set your value on the material … and before mesh with this material is rendered, the parameters are automatically set on the scope.

material.setParameter("uTime", currentTime);

Ah, yes, makes sense. Thank you!