-
Notifications
You must be signed in to change notification settings - Fork 407
glTF PBR Clearcoat interaction with Emission #2641
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
base: main
Are you sure you want to change the base?
glTF PBR Clearcoat interaction with Emission #2641
Conversation
|
|
||
| <uniform_edf name="emission" type="EDF"> | ||
| <input name="color" type="color3" nodename="emission_color" /> | ||
| <input name="color" type="color3" nodename="coated_emission" /> |
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.
This looks like a thoughtful implementation of the Fresnel effect of the coating, though I wonder if we could leverage the standard generalized_schlick_edf node instead:
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.
I agree, that was my first idea, and use multiply_edfC with the emission_color or pipe the uniform_edf into the base-input.
But there are some implementation details of generalize_schlick that I think differ from the gltf_spec formula, as well as not allowing me to supply the normal (as it needs to be the clearcoat normal).
This is the fresnel described by the glTF spec, KHR_materials_clearcoat.
clearcoat_fresnel = 0.04 + (1 - 0.04) * (1 - abs(VdotNc))^5
In the mx_generalized_schlick_edf glsl implementation it seems that NdoV is clamped and not the absolute value.
also the mx_fresnel_schlick function in glsl uses mix with the arguments in another order then expected for clearcoat interaction.
float mx_fresnel_schlick(float cosTheta, float F0, float F90, float exponent)
{
float x = clamp(1.0 - cosTheta, 0.0, 1.0);
return mix(F0, F90, pow(x, exponent));
}According to GLSLangSpec.4.40.pdf, page 146, this is the definition of mix :
mix(x,y,a) = x⋅(1−a)+ y⋅a
to be equalent to glTF implementation the mix should be called with
mix(pow(x, exponent), F90, F0) = 0.04 + (1 - 0.04) * (1 - abs(VdotNc))^5
I should say that I havn't tested the code (because I couldn't figure out how to supply the clearcoat normal to the edf func).
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.
Regarding the use of clamp vs abs as in the spec. It seems like the gltf-sample-renderer uses clamp here as well and not abs as in the spec. Code reference. So that may not be an issue.
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 realized that there is a Standard Schlick Fresnel in the mx_microfacet lib. That is what I'm after, it will sort out the "mix"-problem I wrote about in an earlier reply. But I cannot see a way to access it from generalized_schlick_edf, is that possible?
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.
All good points, @bowald, and I'm CC'ing @niklasharrysson for his expertise with the definition and implementation of generalized_schlick_edf.
Our original goal for the generalized_schlick_edf node was to handle the very situation you've encountered here, where the shape of an EDF lobe is influenced by the clearcoat layer above it, so if there are limitations in our current definition I'm hoping we can address them to encompass the needs of gltf_pbr as well.
As a second reference point, here's where we use generalized_schlick_edf in the definition of standard_surface to handle a similar situation:
closes #2592
This PR will darken the emission color by a weighted clearcoat fresnel factor from KHR_materials_clearcoat
Screenshots of a red emissive material with a clearcoat.
Material
Discussion:
I ended up implementing Schlick Fresnel returning floats using nodes. I was planning to use the generalized_schlick node, however they returned distribution functions, is there an option to use the included schlick nodes or is how I have dont it in the PR a good way?