-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KHR_materials_clearcoat and KHR_materials_specular #1677
Conversation
Added contributers.
About clear coat, I am starting the implementation in Babylon but I wonder if we could enforce that the intensity factor would be stored in the texture R channel and roughness in the G ? This could help packing the clear coat information together and so we would require only one sampler ? Here is how we currently do it in Babylon: https://github.com/BabylonJS/Babylon.js/blob/05c912cc8aa1984c861eeb580e760da0f37a58f1/src/Shaders/pbr.fragment.fx#L621 |
Also I guess the default clear coat factor and roughness should be 1 and not 0 to ensure it multiplies correctly with the texture ? |
Scratch that it is already a normalTextureInfo so all good. |
@sebavan The default factor is by purpose 0, that by default the effect is off. If one wants to have the effect enabled, one has to set the required value. Otherwise, all materials would have per default clear coat on, which is not wanted (e.g. compare with emissive). |
But as long as you have the extension the intent is probably to have it on, hence the proposed value of 1 and if you want it off, why simply not putting the extension ? Yup agreed for the normal, I put out the comment too fast. Now what about using only one texture packing the both clear coat related info ? |
It's already packed in R and G: https://github.com/ux3d/glTF/blob/KHR_materials_pbrClearcoat/extensions/2.0/Khronos/KHR_materials_clearcoat/schema/glTF.KHR_materials_clearcoat.schema.json |
Ok for R and G I was only looking at the table, I wonder if we could precise it in it or if it is redundant info ? |
Oh and by the way @UX3D-nopper do you happen to have a test asset ? |
The schema "rules", but yes, could be explictly mentioned in the markdown document as well. |
My team was getting back to me and they have raised a concern regarding the blending formula in clear coat. The formula is quite nice, if we only have one light. But if we have multiple lights e.g. IBL plus two punctual, the blending formula is not usable. Actually, If You have a look at other engines using clear coat, they do not make such effort and basically - more or less - add the clear coat value. |
Suggest to simplify to:
e.g. Substance Painter from Allegorithmic is doing it like this. |
Taken from Substance Painter Docs.
Babylon follows what Filament does, though we are out-of-date right now. We will update. @romainguy Do you mind reviewing? |
We were still using the squared 1-Fc for specular :-) I ll update ASAP. I think the main diff now is about the Fresnel term where we are relying on VdotH vs the proposed NdotV. @UX3D-nopper I wonder which one it should be ? |
We got rid of the squared Fresnel when blending in clear coat, a while ago. We now do what @UX3D-nopper shows in his last comment (except we don't use |
Agree, cause I always thought the fresnel of the BRDF should be computed from the half vector and not the normal to match with the density probability we are computing in the rest of the equation. |
Let's say you have an image based light plus two punctual lights. When blending together, which L are u using? Obviously L per light, but with the old formula u sum up emssive every time as well. |
Ah so you do this as an optimization. We compute the clear coat BRDF per light and use NdotV for the IBL (and we don't attenuate the emissive bit, it's always added at the end). |
But technically the emissive should be blended as well. |
Depends which layer is emissive :) TBH I don't care that much about an emissive surface with a clear coat layer being off at grazing angles. It seems like it's just one trade-off vs another one. |
|
||
``` | ||
blendFactor = clearcoatFactor * fresnel(0.04, NdotV) | ||
f = (f_emissive + f_diffuse) * (1.0 - blendFactor) + mix(f_specular, f_clearcoat, blendFactor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this formula be simplified as follows? Is this the same formula?
f = mix(f_emissive + f_diffuse + f_specular, f_clearcoat, blendFactor)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The formula I provided is from Substance Painter and they are just blending the specular part, which does makes sense from my point of view.
Where do you have the formula from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the same formula, just refactored. Recall that:
mix(x, y, a) = x * (1.0 - a) + y*a
Given the left side of mix
is already multiplied by 1.0 - blendFactor
, I don't think we need to show it being multiplied separately.
Looking at Substance Painter's code, I see why they did it that way: Their shader needed diffuse, emissive, and specular outputs as separate values, not added together. Perhaps we could show it as separate values too, but if we're showing it all added together then it may as well all go into the mix statement.
|**clearcoatRoughnessTexture** | [`textureInfo`](/specification/2.0/README.md#reference-textureInfo) | The clearcoat layer roughness texture. | No | | ||
|**clearcoatNormalTexture** | [`normalTextureInfo`](/specification/2.0/README.md#reference-normaltextureinfo) | The clearcoat normal map texture. | No | | ||
|
||
The clearcoat formula `f_clearcoat` is the same as the specular term from the Metallic-Roughness material, using F0 equal 0.04. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to specifying F0, perhaps also specify that metallic is zero and roughness comes from the product of clearcoatRoughnessFactor
and clearcoatRoughnessTexture
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also that baseColor is vec3(1.0)
, full white
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For clear coat, no diffuse part is calculated. So baseColor does not have to be specified. The same with metallic.
But I agree, that how the specular part is calculated should be better described.
Hi Tobias(@proog128 ), |
As requested, the pull request for clearcoat. Please note, not final yet.
Also, the "specular" for F0 extension is added as well.