Performance advantages of cloning a StandardMaterial for meshes that have different textures

Hello guys!
I have an arbitrary number of planes created during runtime, each plane has a different texture.
So far I’ve created a new StandardMaterial for each plane and assign it its own diffuseTexture.

I was wondering if there are any performance advantages of having a single StandardMaterial and clone it for each new mesh. If I try this in the playground the inspector shows 2 materials anyways, so I’m unsure if doing this has any significant advantage.
https://www.babylonjs-playground.com/#YDO1F#421

Thanks!

Cloning a material is the same thing than recreating a new one, only that you don’t have to copy all the properties, they are copied for you by the cloning method.

You could create a single material and set the right texture depending on which mesh is currently processed, but it’s a bit unsupported and is using internal knowledge of the StandardMaterial implementation:

https://www.babylonjs-playground.com/#YDO1F#423

I looked into this in regards to Draw Calls (partially to further my own knowledge on the matter) and it seemed to make no difference on that front: whether you assigned all boxes to one material, made clones of that material, or created new materials for each.

All On One Material

Cloned Materials

New Material For Each

Hope this helped! :smiley: