-
Notifications
You must be signed in to change notification settings - Fork 409
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
Open
bowald
wants to merge
3
commits into
AcademySoftwareFoundation:main
Choose a base branch
from
bowald:gltf-clearcoat-emission-interaction
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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_edfnode instead:https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/documents/Specification/MaterialX.PBRSpec.md#node-generalized-schlick-edf
Uh oh!
There was an error while loading. Please reload this page.
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_edfCwith theemission_coloror pipe theuniform_edfinto the base-input.But there are some implementation details of
generalize_schlickthat 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.
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
mixwith the arguments in another order then expected for clearcoat interaction.According to GLSLangSpec.4.40.pdf, page 146, this is the definition of mix :
to be equalent to glTF implementation the mix should be called with
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).
Uh oh!
There was an error while loading. Please reload this page.
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
clampvsabsas in the spec. It seems like the gltf-sample-renderer usesclamphere as well and notabsas 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 Fresnelin 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 fromgeneralized_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_edfnode 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 ofgltf_pbras well.As a second reference point, here's where we use
generalized_schlick_edfin the definition ofstandard_surfaceto handle a similar situation:https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/libraries/bxdf/standard_surface.mtlx#L399
Uh oh!
There was an error while loading. Please reload this page.
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.
Hej Johan!
Sorry for the late reply.
An explicit implementation of the Fresnel effect using the
viewdirectionis certainly possible, as shown in your PR. However, there are a few important considerations to keep in mind:Portability:
Relying on the view direction explicitly within a graph can introduce portability issues for certain targets. In particular, for bidirectional rendering techniques, using the camera-based view direction becomes problematic, since it may be undefined when tracing paths from a light source (or EDF). This is why the
viewdirectionnode lives in the NPR library rather than the PBR library. Ideally, it should only be used for effects that are strictly camera-dependent, such as facing-ratio adjustments or other NPR-style shading.Performance:
Distribution functions have known analytic shapes that renderers can importance-sample efficiently. When reproducing the same behavior through an explicit graph, this advantage is lost, which can make the result significantly less efficient on some targets.
In general, we should prefer distribution functions whenever possible. In this particular case, I believe the main limitation is that we don’t currently support using a custom normal to steer the distribution, the coat normal in this case. However, since the underlying EDF is diffuse, I suspect this has minimal impact on the visible result.
The proposed setup with
generalized_schlick_edfis already used for both the Standard Surface and OpenPBR graphs in MaterialX, and we haven’t received any reports of issues related to not accounting for the coat normal in the emission. With that in mind, it might make sense to hold off on further changes togeneralized_schlick_edfuntil there is a demonstrated need.Uh oh!
There was an error while loading. Please reload this page.
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.
Hej @niklasharrysson :)
No worries, there is no rush to get this into MaterialX from our part.
I agree that portability and performance is preferred over staying close to the glTF spec.
We should not go forward merging this PR as is.
There was two limitations I couldn't fix using the
generalized_schlick_edfto implement clearcoat interaction.generalized_schlick_edf(as you stated)generalized_schlick_edfto get the correct mix-function for the clearcoat interaction.I think having the limitation to not account for the clearcoat normalmap, and use the surface normalmap, would be a good middle way.
Do you know if there is a way to call the Standard Schlick Fresnel (Without the F90) from the
generalized_schlick_edfor if there is another pbr node that could be used?Where we get this instead:
clearcoat_fresnel = 0.04 + (1 - 0.04) * (1 - abs(VdotN))^5(Using, N = surface normal, skipping the N__clearcoat_ from the glTF clearcoat extension spec)
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.
Just set
F90to 1.0 (white), andexponentto 5. The Generalized Schlick Fresnel is then reduced to the Standard Schlick Fresnel.The generalized equation:
is reduce to:
You can then hardcode F0 to 0.04 if that is desired (this corresponds to an IOR of 1.5, is that always fixed in glTF's coat layer?)
Uh oh!
There was an error while loading. Please reload this page.
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.
You are right. I screwed up the math. The second limitation I listed is not an issue.
Yes, currently IOR of clearcoat is always 1.5, there is a proposal to the glTF spec allowing IOR to be supplied to the coat layer KhronosGroup/glTF#2530 but its not yet part of the glTF spec.
I can update the PR with the
generalized_schlick_edf, I think the limitation with surface normal is better then no interaction.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.
Excellent! :)