Same material and different shader uniforms

Hi,
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[0].model.meshInstance[0].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?

Hi @NokFrt,

Yes, you can definitely override the uniforms per mesh instance, independently of the material.

Just use the setParameter method directly on the mesh instance:

entities[0].model.meshInstance[0].setParameter("uColor", [1, 0, 0]);
2 Likes

Hi @Leonidas, thank you very much. I knew I have to set the parameter directly on the mesh instance but I set it on it’s material instead. My mistake.

1 Like