I’m programatically creating NodeMaterials with different node branches depending on desired material settings. This allows creating custom materials that can still integrate with Babylon.js core shader features (PBR, lights, shadows etc) without having to worry about conflicts in GLSL code / uniform names etc.
However, if a model has lots of materials (for example 100) then compiling shaders for that many NodeMaterials can be extremely slow (tens of seconds) especially on browsers that don’t support KHR_parallel_shader_compile extension.
However, there seems to be a buildId
property, so lets say I do this:
nodeMaterial.buildId = *generate hash based on node tree structure*;
const updateBuildId = false;
nodeMaterial.build(false, updateBuildId);
Now the shader is only compiled for unique node tree configurations. So if out of 100 materials only 5 will have unique node tree then only 5 shaders need to be compiled. This seems to work.
Anyway. I’m asking here to get confirmation that this is what the buildId
is intented for? Or am I abusing the system and there may be issues later down the line? Or are there any other things that I need to do to make this work reliably?