-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Fix base color and reflectivity calculations for PBR materials #12043
Conversation
Thank you for the pull request, @jjhembd! ✅ We can confirm we have a CLA on file for you. |
CHANGES.md
Outdated
@@ -14,6 +14,7 @@ | |||
|
|||
##### Fixes :wrench: | |||
|
|||
- Fixed diffuse color calculation for PBR materials. Many models will now appear slightly brighter. This also fixes an [issue affecting the KHR_materials_specular extension](https://github.com/CesiumGS/cesium/issues/12041). [#12043](https://github.com/CesiumGS/cesium/pull/12043) |
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.
Even though they were fixed in one PR, I would suggest listing this as two different items. The former (Fixed diffuse color calculation for PBR materials
) can link to the PR. The later (fixes an issue affecting the KHR_materials_specular extension
) can link to the issue.
|
||
material.specular = f0; | ||
|
||
// diffuse only applies to dielectrics. | ||
material.diffuse = material.diffuse * (1.0 - f0) * (1.0 - metalness); | ||
material.diffuse = mix(material.baseColor.rgb, vec3(0), metalness); |
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.
Shouldn't this be?
material.diffuse = mix(material.baseColor.rgb, vec3(0), metalness); | |
material.diffuse = mix(material.baseColor.rgb, vec3(0.0), metalness); |
Thanks @ggetz! I addressed both of those comments. |
All looks good! Thanks @jjhembd! |
For the record: the extra |
Description
Our calculation of the base diffuse color for a material was scaled by the transmission coefficient
(1.0 - f0)
(wheref0
is the specular reflection coefficient at normal incidence):This intuitively seems to make sense at normal incidence. The incident light that actually interacts with the microfacets of the surface (in the diffuse model) will be reduced by the amount of light already reflected specularly.
However, this simple 1D scaling is an oversimplification of something that is already accounted for in the BRDF, so including the scaling results in PBR materials being rendered slightly too dim.
This PR instead computes the base diffuse color using a formula more similar to the glTF Sample Viewer:
Note the new
baseColor
property on theczm_modelMaterial
struct. This helps avoid confusion from overwriting thediffuse
property too many times, and fixes #12041, where theKHR_materials_specular
extension was using thediffuse
property as if it were the raw base color.Issue number and link
Resolves #12041
Testing plan
Author checklist
CONTRIBUTORS.md
CHANGES.md
with a short summary of my change[ ] I have added or updated unit tests to ensure consistent code coverage[ ] I have update the inline documentation, and included code examples where relevant