Skip to content

PBR extension: clearcoat - #33

Open
alemuntoni wants to merge 25 commits into
cnr-isti-vclab:mainfrom
dlupo2:pbr-ext-clearcoat
Open

PBR extension: clearcoat#33
alemuntoni wants to merge 25 commits into
cnr-isti-vclab:mainfrom
dlupo2:pbr-ext-clearcoat

Conversation

@alemuntoni

@alemuntoni alemuntoni commented Mar 20, 2026

Copy link
Copy Markdown
Member

TODO:

  • check ClearCoatCarPaint visualization, that looks very different w.r.t. gltf viewer.
    • could it be the same mipmap normal problem of PBR extension: anisotropy #32? ClearCoatCarPaint uses KHR_texture_transform extension which is (still) not implemented in our viewer.

dlupo2 and others added 11 commits February 7, 2026 21:07
…o pbr-ext-clearcoat

# Conflicts:
#	vclib/render/include/vclib/bgfx/drawable/mesh/mesh_render_buffers_macros.h
#	vclib/render/include/vclib/bgfx/drawable/mesh/pbr_macros.h
#	vclib/render/include/vclib/bgfx/drawable/uniforms/drawable_mesh_uniforms.h
#	vclib/render/include/vclib/bgfx/drawable/uniforms/material_uniforms.h
#	vclib/render/shaders/vclib/bgfx/drawable/drawable_mesh/surface/fs_surface_uber_pbr.sc
#	vclib/render/shaders/vclib/bgfx/drawable/uniforms/drawable_mesh_texture_uniforms.sh
#	vclib/render/shaders/vclib/bgfx/pbr_common.sh
# Conflicts:
#	vclib/render/include/vclib/bgfx/drawable/uniforms/drawable_mesh_uniforms.h

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 20 changed files in this pull request and generated 9 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread vclib/render/shaders/vclib/bgfx/pbr_common.sh Outdated
Comment thread vclib/render/shaders/vclib/bgfx/pbr_common.sh Outdated
Comment thread vclib/core/include/vclib/space/core/material.h Outdated
Comment thread vclib/render/include/vclib/bgfx/drawable/drawable_environment.h
Comment on lines 756 to 760
float NoV = clampedDot(normal, V);
float clearcoatNoV = clampedDot(clearcoatNormal, V);

vec3 clearcoatFresnel = clearcoat * F_Schlick(f0_dielectric, f90, clearcoatNoV);

Copilot AI Mar 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F_Schlick is documented to take VoH, but clearcoat Fresnel is currently computed once using clearcoatNoV and then reused for all lights. This makes the clearcoat response independent of the per-light half-vector and will produce incorrect highlights. Compute clearcoat Fresnel per-light using VoH (or otherwise align the computation with the intended Schlick parameter) and avoid reusing a single value across the loop.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dlupo2 what do you think about this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put clearcoatNoV out of the loop since both the clearcoat N and V are constant w.r.t. the loop, as for the clearcoatFresnel, it is computed this way in the khronos viewer


// Fresnel
vec2 brdf = brdfLutTex(vec2(NoV, roughness)).rg;
vec3 metalFresnel = iblGgxFresnel(brdf, NoV, roughness, baseColor.rgb);
vec3 dielectricFresnel = iblGgxFresnel(brdf, NoV, roughness, f0_dielectric);
vec3 clearcoatFresnel = clearcoat * F_Schlick(f0_dielectric, f90, clearcoatNoV);

Copilot AI Mar 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For IBL, clearcoat Fresnel is computed with F_Schlick(..., clearcoatNoV) and the clearcoat specular term is taken directly from the specular cubemap sample. Unlike the base layer, this doesn’t use the BRDF LUT integration (NoV/roughness) and will diverge noticeably from glTF reference viewers. Consider computing a clearcoat IBL term using the BRDF LUT (e.g., derive a Fresnel/specular response via iblGgxFresnel with clearcoatNoV and clearcoatRoughness) before mixing it into pbrColorIbl.

Suggested change
vec3 clearcoatFresnel = clearcoat * F_Schlick(f0_dielectric, f90, clearcoatNoV);
vec2 brdfClearcoat = brdfLutTex(vec2(clearcoatNoV, clearcoatRoughness)).rg;
vec3 clearcoatFresnel = clearcoat * iblGgxFresnel(brdfClearcoat, clearcoatNoV, clearcoatRoughness, f0_dielectric);

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dlupo2 what do you think about this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this is how the khronos viewer does it, there should be no need to change things

Comment thread vclib/render/include/vclib/bgfx/drawable/uniforms/material_uniforms.h Outdated
@alemuntoni
alemuntoni requested a review from malomo March 25, 2026 08:52
# Conflicts:
#	vclib/render/shaders/vclib/bgfx/drawable/uniforms/drawable_mesh_texture_uniforms.sh
# Conflicts:
#	vclib/render/include/vclib/bgfx/drawable/uniforms/material_uniforms.h
#	vclib/render/shaders/vclib/bgfx/drawable/drawable_mesh/material_uniforms.sh
#	vclib/render/shaders/vclib/bgfx/drawable/drawable_mesh/surface_pbr/fs_surface_pbr.sc
#	vclib/render/shaders/vclib/bgfx/drawable/drawable_mesh/texture_uniforms.sh
#	vclib/render/shaders/vclib/bgfx/pbr_common.sh
# Conflicts:
#	tests/render/006-mesh-pbr-headless/main.cpp
#	vclib/render/include/vclib/bgfx/drawable/uniforms/material_uniforms.h
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.

3 participants