NodeMaterial reuse with different uniform parameters?

Do I need to reconstruct/reload a NodeMaterial each time a mesh uses it with different/separate uniform parameters? (cloning is not more efficient, it does the equivalent of saving and reloading)

Or is there a way for uniform parameters to come from the mesh like how matrices do? This way I can reuse the material and only need to update the mesh.

The system will do it for you actually so no need to rebuild it if you only change uniform values


I don’t think that is an answer to my question, so let me clarify.

How can I have 2 meshes with different uniforms use the same material… it seems like I have to reload/reconstruct the node material for the second mesh to hold a different value for the same uniform.

If I try to reuse a node material and change an InputBlock value, it affects both meshes.

And I am not looking for a way to automatically reconstruct the node material, I’m trying to see if it can be reused instead of reconstructing it with a separate InputBlock.

Sorry I was unclear. If you want the same material to be shared by two meshes but you want each mesh to have specific values for some uniforms you can set the mesh.material to your node material and then add an observer on mesh.onBeforeRender to update the material values

1 Like

a more detailed example of the solution for anyone who stumbles upon this:

mesh.onBeforeRenderObservable.add(() => {
    InputBlock.value = mesh.myValue;

InputBlock was created as part of the original Node Material, and myValue is something added to the mesh that doesn’t conflict with the name of other parameters.

1 Like