Skip to content

Conversation

@bowald
Copy link
Contributor

@bowald bowald commented Oct 22, 2025

closes #2592

This PR will darken the emission color by a weighted clearcoat fresnel factor from KHR_materials_clearcoat

coated_emission = emission * (1 - clearcoat * clearcoat_fresnel)

Screenshots of a red emissive material with a clearcoat.

MaterialXGraphEditor_djwiexXuWH MaterialXGraphEditor_lBI0QFpkee chrome_XpDlrBBniD
Before PR: No clearcoat fresnel interaction After PR: Emission darken by clearcoat_fresnel Reference rendered using gltf_sample_viewer

Material

  <gltf_pbr name="gltf_pbr_surfaceshader" type="surfaceshader">
    <input name="metallic" type="float" value="0" />
    <input name="emissive" type="color3" value="1, 0, 0" />
    <input name="base_color" type="color3" value="0, 0, 0" />
    <input name="clearcoat" type="float" value="1" />
    <input name="clearcoat_roughness" type="float" value="0" />
  </gltf_pbr>

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?


<uniform_edf name="emission" type="EDF">
<input name="color" type="color3" nodename="emission_color" />
<input name="color" type="color3" nodename="coated_emission" />
Copy link
Member

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:

https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/documents/Specification/MaterialX.PBRSpec.md#node-generalized-schlick-edf

Copy link
Contributor Author

@bowald bowald Oct 24, 2025

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

Copy link
Contributor Author

@bowald bowald Oct 24, 2025

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.

Copy link
Contributor Author

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?

Copy link
Member

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:

https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/libraries/bxdf/standard_surface.mtlx#L399

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emission and Clearcoat interaction in gltf_pbr

2 participants