Skip to content

fix: include fresnelSchlick chunk when refraction is enabled without specular#8595

Merged
willeastcott merged 1 commit intomainfrom
fix/fresnel-refraction-shader
Apr 13, 2026
Merged

fix: include fresnelSchlick chunk when refraction is enabled without specular#8595
willeastcott merged 1 commit intomainfrom
fix/fresnel-refraction-shader

Conversation

@willeastcott
Copy link
Copy Markdown
Contributor

@willeastcott willeastcott commented Apr 13, 2026

Summary

  • Fixes a shader compilation error ('getFresnel' : no matching overloaded function found) when a material has refraction enabled but specular is effectively disabled (e.g. black specular color with no metalness)

Root Cause

The fresnelSchlickPS chunk — which defines the getFresnel() function — was only included inside the #ifdef LIT_SPECULAR_OR_REFLECTION guard in litForwardPostCode.js. However, the refractionDynamicPS chunk (included under #ifdef LIT_REFRACTION) calls getFresnel() regardless. When LIT_SPECULAR_OR_REFLECTION was false but LIT_REFRACTION was true, the function was called but never defined.

Fix

Moved the fresnelSchlickPS include so it is also triggered when LIT_REFRACTION is defined:

#if defined(LIT_SPECULAR_OR_REFLECTION) || defined(LIT_REFRACTION)
    #if LIT_FRESNEL_MODEL == SCHLICK
        #include "fresnelSchlickPS"
    #endif
#endif

Applied to both the GLSL and WGSL versions of litForwardPostCode.js.

Steps to Reproduce

  1. Create a standard material with specular color set to black
  2. Remove any environment map / skybox
  3. Enable refraction (non-zero value) and enable dynamic refraction
  4. Apply to a mesh — shader compilation fails

Test Plan

  • Verify the above repro steps no longer produce a shader error
  • Verify materials with specular + refraction still render correctly
  • Verify materials with specular only (no refraction) are unaffected

…specular

The fresnelSchlickPS chunk (defining getFresnel) was only included under
LIT_SPECULAR_OR_REFLECTION, but refractionDynamicPS calls getFresnel
regardless. When a material has refraction enabled with specular disabled
(e.g. black specular color, no metalness), the shader fails to compile.

Made-with: Cursor
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a forward-lit shader compilation failure where refraction code can call getFresnel() even when the Fresnel implementation chunk wasn’t being included (notably when refraction is enabled while specular/reflection is effectively disabled).

Changes:

  • Move fresnelSchlickPS inclusion out of the LIT_SPECULAR_OR_REFLECTION-only block.
  • Include fresnelSchlickPS when either LIT_SPECULAR_OR_REFLECTION or LIT_REFRACTION is defined.
  • Apply the same change to both GLSL and WGSL forward-pass post code.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/scene/shader-lib/wgsl/chunks/lit/frag/pass-forward/litForwardPostCode.js Ensures the Fresnel Schlick chunk is available when refraction is enabled in WGSL.
src/scene/shader-lib/glsl/chunks/lit/frag/pass-forward/litForwardPostCode.js Ensures the Fresnel Schlick chunk is available when refraction is enabled in GLSL.

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

@willeastcott willeastcott merged commit 972e95e into main Apr 13, 2026
12 checks passed
@willeastcott willeastcott deleted the fix/fresnel-refraction-shader branch April 13, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: graphics Graphics related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants