I have several mesh instances which use the same material. Is it possible to set different shader uniforms for each mesh instance or do I have to use unique material for each mesh instance?
I’m trying to do it as follow, but it doesn’t work.
let entities: pc.Entity;
// Create entities (each entity's model use the same material)
entities.model.meshInstance.material.setParameter("uColor", [1, 0, 0]);
// Unfortunatelly, now all entities use uColor se to [1, 0, 0]
I think I have to set the uniform value for each instance every frame before it’s going to be rendered. But how to do that?
That’s a valid question. Playcanvas will make sure to group all materials that share the same parameters into a single compiled shader. So you can have multiple materials that share the same properties, and with the convenience that brings without any significant performance hit.
Additional materials only increase slightly the loading time (since they are a separate .json file), though its size is very small.