In CAD system, we used ‘PBRMaterial’ and enabled ‘forceCompilation’ option. That seemed to help while loading multiple meshes as ‘effects’ (shaders) may be reused internally.
Now, we use a custom NodeMaterial created using NME that’s using PBR blocks internally.
We create & assign it for each mesh the same way we did while using Babylon’s PBR material.
By doing so, we noticed that model loading is slower. I suspect that it may be due to multiple shaders (effects) being created.
So,
Would forceCompilation option have any favorable impact on custom ‘NodeMaterial’ similar to PBRMaterial?
Is there any API to track on how many unique shaders (effects) are actually created?
I don’t think there’s a forceCompilation option (?) There’s a forceCompilation method that you can call to force compiling a material for a given mesh but it won’t make things faster by itself: the compilation will be done straight when calling the method instead of when the mesh needs to be rendered (if it ever needs to), but in the end it takes the same time to create the effect in both cases.
Maybe it takes a little more time in the NME case because the json files need to be parsed? Note that there is a forceCompilation method for the NodeMaterial class has it is extending Material which has this method.
Regarding 2/, there isn’t a public way to do it (I think), but you can look at engine._compiledEffects
Thanks. I’ll check on them. Though we don’t use json import, we used ‘Generate Code’ option from NME.
Either way, I guess it may take some time there.
Also, engine._compiledEffects should help me compare between my old implementation and my new code that’s based on NodeMaterial to see how many shaders (effects) are actually created.
In this playground sample, I’ve created 2 NodeMaterial objects using same NME snippet & also two PBRMaterial objects. In _compiledEffects console log, I noticed 3 effects are being created.
Two are for NodeMaterials and only one for PBRMaterial.
Since code of Vertex & Fragment shaders in both NodeMaterial’s effects are identical, I expected only one effect to be created for the two NodeMaterial objects.
Thanks for sharing the info @br-matt . That fix from @Deltakosh helped. Here’s the modified code sample
Now I see just one effect being created. Further, now it’s possible to set different color to the cloned NodeMaterial. That’s what we wanted!!!