# Is it possible to create specular glossiness workflow PBR material in NodeMaterial?

**URL:** <https://forum.babylonjs.com/t/is-it-possible-to-create-specular-glossiness-workflow-pbr-material-in-nodematerial/29749>\
**Category:** Questions\
**Created:** [April 26, 2022, 8:46pm UTC](https://forum.babylonjs.com/t/is-it-possible-to-create-specular-glossiness-workflow-pbr-material-in-nodematerial/29749 "2022-04-26T20:46:22Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![MiikaH](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/miikah/32/23054_2.png) [@MiikaH](https://forum.babylonjs.com/u/MiikaH)\
**Post date:** [April 26, 2022, 8:46pm UTC](https://forum.babylonjs.com/t/is-it-possible-to-create-specular-glossiness-workflow-pbr-material-in-nodematerial/29749/1 "2022-04-26T20:46:22Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![thomlucc](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/thomlucc/32/4046_2.png) [@thomlucc](https://forum.babylonjs.com/u/thomlucc)\
**Post date:** [April 26, 2022, 9:39pm UTC](https://forum.babylonjs.com/t/is-it-possible-to-create-specular-glossiness-workflow-pbr-material-in-nodematerial/29749/2 "2022-04-26T21:39:41Z")

</div>

Hi @MiikaH - pinging @Evgeni_Popov, who is behind the implementation of PBR material in NME.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [April 26, 2022, 9:41pm UTC](https://forum.babylonjs.com/t/is-it-possible-to-create-specular-glossiness-workflow-pbr-material-in-nodematerial/29749/3 "2022-04-26T21:41:25Z")

</div>

Nope, it is not possible thus far.

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 ???

---

<div class="post-metadata">

**Author:** ![MiikaH](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/miikah/32/23054_2.png) [@MiikaH](https://forum.babylonjs.com/u/MiikaH)\
**Post date:** [April 26, 2022, 10:17pm UTC](https://forum.babylonjs.com/t/is-it-possible-to-create-specular-glossiness-workflow-pbr-material-in-nodematerial/29749/4 "2022-04-26T22:17:42Z")

</div>

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. 😟

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [April 26, 2022, 10:31pm UTC](https://forum.babylonjs.com/t/is-it-possible-to-create-specular-glossiness-workflow-pbr-material-in-nodematerial/29749/5 "2022-04-26T22:31:41Z")

</div>

> [@sebavan](#):
>
> 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 ???

[glTF/babylon.pbrUtilities.js at main · KhronosGroup/glTF (github.com)](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Archived/KHR_materials_pbrSpecularGlossiness/examples/convert-between-workflows-bjs/js/babylon.pbrUtilities.js#L33-L64)

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](https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_specular) which sits on top of metallic roughness model and can directly translate from specular/glossiness?

---

<div class="post-metadata">

**Author:** ![MiikaH](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/miikah/32/23054_2.png) [@MiikaH](https://forum.babylonjs.com/u/MiikaH)\
**Post date:** [April 26, 2022, 10:45pm UTC](https://forum.babylonjs.com/t/is-it-possible-to-create-specular-glossiness-workflow-pbr-material-in-nodematerial/29749/6 "2022-04-26T22:45:39Z")

</div>

> [@bghgary](#):
>
> @sebavan Maybe we can add something to NME similar to [KHR\_materials\_specular](https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/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. 😲

---

<div class="post-metadata">

**Author:** ![MiikaH](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/miikah/32/23054_2.png) [@MiikaH](https://forum.babylonjs.com/u/MiikaH)\
**Post date:** [April 27, 2022, 9:53am UTC](https://forum.babylonjs.com/t/is-it-possible-to-create-specular-glossiness-workflow-pbr-material-in-nodematerial/29749/7 "2022-04-27T09:53:07Z")

</div>

> [@bghgary](#):
>
> [glTF/babylon.pbrUtilities.js at main · KhronosGroup/glTF (github.com)](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Archived/KHR_materials_pbrSpecularGlossiness/examples/convert-between-workflows-bjs/js/babylon.pbrUtilities.js#L33-L64)
> 
> You can try something like this, but I don’t really recommend it in this situation.

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: 🙂

 ![babylonjs-nme-spec-gloss-2](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/e/d/ed7f60e521b2390b4ba973cc1f0cef870d683bb3.png)  
 ![babylonjs-nme-spec-gloss](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/5/8/58486d9b440103e0cc232fe1255dbe5d711170e7.png)

So I guess this is good enough workaround for now. Although I’m not sure if the conversion method has some shortcomings that I’m not aware of.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [April 27, 2022, 2:25pm UTC](https://forum.babylonjs.com/t/is-it-possible-to-create-specular-glossiness-workflow-pbr-material-in-nodematerial/29749/8 "2022-04-27T14:25:17Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [April 27, 2022, 3:46pm UTC](https://forum.babylonjs.com/t/is-it-possible-to-create-specular-glossiness-workflow-pbr-material-in-nodematerial/29749/9 "2022-04-27T15:46:47Z")

</div>

> [@MiikaH](#):
>
> Although I’m not sure if the conversion method has some shortcomings that I’m not aware of.

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).

You can test it with different values here and see how it performs: [glTF PBR Conversion (BabylonJS) (bghgary.github.io)](https://bghgary.github.io/glTF/convert-between-workflows-bjs/)

For example, if you use different diffuse and specular colors, the conversion will try to make it work, but it won’t be perfect.

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/5/7/577258fe7597a08035c96ab1233f1bb6869d32dc.png)

---

<div class="post-metadata">

**Author:** ![MiikaH](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/miikah/32/23054_2.png) [@MiikaH](https://forum.babylonjs.com/u/MiikaH)\
**Post date:** [April 27, 2022, 4:02pm UTC](https://forum.babylonjs.com/t/is-it-possible-to-create-specular-glossiness-workflow-pbr-material-in-nodematerial/29749/10 "2022-04-27T16:02:11Z")

</div>

Hmm, so I suppose for perfect support PBR node would have to expose the reflectance factors used here?: [Babylon.js/KHR\_materials\_specular.ts at 1067ed5a09919d4e16ad8c4b9eb59dcae426aff0 · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/blob/1067ed5a09919d4e16ad8c4b9eb59dcae426aff0/packages/dev/loaders/src/glTF/2.0/Extensions/KHR_materials_specular.ts#L71-L77)

And with help of those properties it would be possible to create perfect conversion?

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [April 27, 2022, 10:37pm UTC](https://forum.babylonjs.com/t/is-it-possible-to-create-specular-glossiness-workflow-pbr-material-in-nodematerial/29749/11 "2022-04-27T22:37:41Z")

</div>

That sounds right to me, but @sebavan would know better.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [April 28, 2022, 12:33am UTC](https://forum.babylonjs.com/t/is-it-possible-to-create-specular-glossiness-workflow-pbr-material-in-nodematerial/29749/12 "2022-04-28T00:33:10Z")

</div>

should be closer but I do not thing there would always be a possible solution.

---

<div class="post-metadata">

**Author:** ![MiikaH](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/miikah/32/23054_2.png) [@MiikaH](https://forum.babylonjs.com/u/MiikaH)\
**Post date:** [April 28, 2022, 9:14am UTC](https://forum.babylonjs.com/t/is-it-possible-to-create-specular-glossiness-workflow-pbr-material-in-nodematerial/29749/13 "2022-04-28T09:14:32Z")

</div>

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.
