MarkMaterialAsDirty performance issues with high mesh count and scene loading optimization


#1

Hey, I had a couple questions and was wondering if anyone could help?

  1. I was wondering what causes each material to get marked as dirty. All this occurs before the scene has even loaded. The mesh count is around 2500 and it takes about 10-15 seconds to start up. I was wondering if this was normal or if there was a way to speed this up.
  2. I’m wondering if I could use instances or clones because each mesh contains certain data that is unique to it and it’s mesh material is therefore dependent on it’s data and gets changed frequently. My meshs are all tube like structures and also all have varying sizes and properties so I’m assuming instances are out of the question?
  3. Is there any other way to speed up the initial load? For the actual rendering I am using the scene optimizer which is doing a good job. I have not imported any textures and this is all babylon.js materials.


#2

The isDirty is flagged everytime a property is changed in order to get the shaders updated.
You can avoid doing it during loading time with:

scene.blockMaterialDirtyMechanism = true;

Do not forget to call that at the end

scene.blockMaterialDirtyMechanism = false;

https://doc.babylonjs.com/how_to/optimizing_your_scene#blocking-the-dirty-mechanism


#3

Hmmm I tried doing that before and it actually seemed to increase my time. I ended up swaping the order of creating my meshes and the full screen UI to make the UI first and then load the meshes and markAsDirty ended up being reduced to a negligible amount of time.