I’m trying to replicate fully GLTF compatible materials in NodeMaterial, including not just the base gltf spec but also the most common GLTF extensions.
Right now I’m trying to replicate KHR_materials_pbrSpecularGlossiness extension behavior but not having much success so far.
From what I have figured out, PBRMaterial switches between metallic workflow and specular-glossiness workflow based on if materia.metallic or material.roughness properties are set to null. This activates some kind of special reflectivity calculation in the shaders.
Is it possible to somehow activate the specular glossines workflow for PBRMetallicRoughnessBlock? Or is it possible to somehow enable the reflectivity behavior and manually pass specularGlossiness derived roughness and metalness values? Anything I have tried so far has failed, but the shaders are so complicated that I may have missed something.
If there currently isn’t any way to do this, would it be possible to expose the related settings somewhere? Perhaps as editable properties of the PBR node block?
It mostly boils down to the fact that some properties are not physically plausible in spec gloss workflows and we chose to limit NME due to the already exisiting overall complexity to metal/rough workflows.
That said, you could create roughness from glossiness with (1. - gloss) and you might try to infer the correct metalness value by using some equations @bghgary was using before ???
Yeah, I was already able to calculate roughness and metalness values.
The main issue proved out to be that with specular glossiness workflow a black baseColor can still produce fully reflective surface. Whereas with metallic workflow a black baseColor will produce a black surface, even if metallic. I believe this is what the reflectivity flag triggers.
This became very apparent when looking at the SpecGlossVsMetalRough GLTF sample model, that has most of the comparison model baseColor black.
I guess I need to see if I can somehow trigger the needed #defines from custom shader blocks… Or maybe if I can figure some way to fake the look “close enough” otherwise. But it doesn’t look promising.
You can try something like this, but I don’t really recommend it in this situation.
@sebavan Maybe we can add something to NME similar to KHR_materials_specular which sits on top of metallic roughness model and can directly translate from specular/glossiness?
Interesting. If those options were exposed in NME that would indeed allow replicating KHR_materials_pbrSpecularGlossiness behavior, while staying within the metallic workflow. And it would also directly allow supporting for the mentioned KHR_materials_specular itself in NME, that I have yet to look at.
Thanks! That actually looks to be working. I made a custom node block that implements the conversion code in glsl as it would be way too complex to add as node tree.
With that in place at least the GLTF sample model looks correct:
I love the overall idea of this node I wonder if it would be a nice addition to the framework despite the limitations @bghgary ? and obviously if @MiikaH is willing to contribute it back ?
My conversion code will work quite well if the model was originally authored with metallic roughness and converted to specular glossiness (which is what happened with the water bottle).
Ok. At least the current conversion code is good enough for my use case for now.
Though not sure if adding “flawed” conversion node as official babylon.js feature makes sense. But if any of you think so I can of course send the source code of my custom node block as reference.