Creating a lot of PBR material

HI everyone,

On a huge scene i have to create a lot of PBR materials during loading, and it takes a huge amount of time, and unfortunately i can’t clone materials.
It looks like the much of the time is spend compile the shader over and over, but im not sure about this.

This doesn’t take as much time if i create Standard materials though.

Is there any tips that can speed things up ?

Thank you

Material can be fast to create if they reuse the same underlying shaders. If this is not the case you will have to wait for shaders to compile as we want to compile shaders to really optimize them for their materials.

Can you repro what you are doing in the Playground?

I’m not able to reproduce this in a playground unfortunately.

What it happening it that i create all the PRBMaterial instances, and right after that the next frame start being renderered.

But there is a huge delay caused by calls to PBRBaseMaterial is ready for submesh, which it self depend on the _prepareEffect function.

So it looks like the materials are no yet created, and it takes 3 seconds for Babylonjs to create them all, and bind them to there meshes (177 materials).
But in playground environment it takes less than half a second to create and bind to a mesh the same amount of materials.

After digging even more most of the time is spend processins includes in the shader processor.

Ok I see. there is probably stuff to do but I desperately need a repro

I can’t reproduce it but after some changes (using just a basic new PBRMaterial instead of altered PBRs), it speeds up things a lot.

The performance cost is then due to the fact that materials cannot reuse the same underlying shader as you said above.

Thanks for your help :slight_smile: