[FIX] Fix KHR_materials_specular incorrectly affecting metals and diffuse#8293
Merged
willeastcott merged 1 commit intomainfrom Dec 21, 2025
Merged
[FIX] Fix KHR_materials_specular incorrectly affecting metals and diffuse#8293willeastcott merged 1 commit intomainfrom
willeastcott merged 1 commit intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug in the implementation of the KHR_materials_specular glTF extension where specularityFactor was incorrectly applied to all materials, causing metallic materials with specularFactor: 0 to render completely black. The fix ensures the factor only affects dielectric F0 calculations, not metallic materials.
Key Changes:
- Modified
getSpecularModulate()to incorporatespecularityFactorinto the dielectric F0 calculation rather than applying it as a post-multiplier - Removed incorrect post-multiplication of specular outputs that was affecting all materials including metals
- Added clear inline documentation referencing the KHR_materials_specular glTF specification
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/scene/shader-lib/glsl/chunks/lit/frag/metalnessModulate.js |
Updated getSpecularModulate() function to accept specularityFactor parameter and apply it only to dielectric F0 calculation |
src/scene/shader-lib/wgsl/chunks/lit/frag/metalnessModulate.js |
WGSL version of the same getSpecularModulate() function update |
src/scene/shader-lib/glsl/chunks/lit/frag/pass-forward/litForwardBackend.js |
Updated function calls to pass specularityFactor to getSpecularModulate() and removed incorrect post-multiplication of dSpecularLight and dReflection |
src/scene/shader-lib/wgsl/chunks/lit/frag/pass-forward/litForwardBackend.js |
WGSL version of the same forward rendering backend updates |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
slimbuck
approved these changes
Dec 21, 2025
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR fixes an issue where
specularityFactorfrom theKHR_materials_specularglTF extension was incorrectly applied to all materials, including metals. WhenspecularFactor: 0was set, metallic materials would appear completely black because their specular reflections were incorrectly zeroed out.glTF Sample Viewer (Reference):
Before Fix (PlayCanvas Model Viewer):
After Fix (PlayCanvas Model Viewer):
Changes
getSpecularModulate()to incorporatespecularityFactordirectly into the dielectric F0 calculationdSpecularLightanddReflectionbyspecularityFactorspecularityFactorspecularityFactorTechnical Details
According to the KHR_materials_specular specification:
For metals, F0 should always be the base color regardless of
specularFactor. The previous implementation appliedspecularityFactoras a post-multiplier to all specular outputs, which incorrectly affected metals.Before (incorrect)
After (correct)
Testing
KHR_materials_specularextensionspecularFactor: 0now correctly show their base color as specularspecularFactor: 0now correctly show full diffuse with no specularAPI Changes
None - this is a bugfix with no public API changes.
Fixes #7304
Checklist