Skip to content
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

Merged
merged 5 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @name czm_modelMaterial
* @glslStruct
*
* @property {vec4} baseColor The base color of the material.
* @property {vec3} diffuse Incoming light that scatters evenly in all directions.
* @property {float} alpha Alpha of this material. 0.0 is completely transparent; 1.0 is completely opaque.
* @property {vec3} specular Color of reflected light at normal incidence in PBR materials. This is sometimes referred to as f0 in the literature.
Expand All @@ -19,6 +20,7 @@
* @property {vec3} emissive Light emitted by the material equally in all directions. The default is vec3(0.0), which emits no light.
*/
struct czm_modelMaterial {
vec4 baseColor;
vec3 diffuse;
float alpha;
vec3 specular;
Expand Down
7 changes: 4 additions & 3 deletions packages/engine/Source/Shaders/Model/MaterialStageFS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,12 @@ float setMetallicRoughness(inout czm_modelMaterial material)

// dielectrics use f0 = 0.04, metals use albedo as f0
const vec3 REFLECTANCE_DIELECTRIC = vec3(0.04);
vec3 f0 = mix(REFLECTANCE_DIELECTRIC, material.diffuse, metalness);
vec3 f0 = mix(REFLECTANCE_DIELECTRIC, material.baseColor.rgb, metalness);

material.specular = f0;

// diffuse only applies to dielectrics.
material.diffuse = material.diffuse * (1.0 - f0) * (1.0 - metalness);
jjhembd marked this conversation as resolved.
Show resolved Hide resolved
material.diffuse = mix(material.baseColor.rgb, vec3(0), metalness);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be?

Suggested change
material.diffuse = mix(material.baseColor.rgb, vec3(0), metalness);
material.diffuse = mix(material.baseColor.rgb, vec3(0.0), metalness);


// roughness is authored as perceptual roughness
// square it to get material roughness
Expand Down Expand Up @@ -349,7 +349,7 @@ void setSpecular(inout czm_modelMaterial material, in float metalness)
material.specularWeight = specularWeight;
vec3 f0 = material.specular;
vec3 dielectricSpecularF0 = min(f0 * specularColorFactor, vec3(1.0));
material.specular = mix(dielectricSpecularF0, material.diffuse, metalness);
material.specular = mix(dielectricSpecularF0, material.baseColor.rgb, metalness);
}
#endif
#ifdef USE_ANISOTROPY
Expand Down Expand Up @@ -458,6 +458,7 @@ void materialStage(inout czm_modelMaterial material, ProcessedAttributes attribu
baseColorWithAlpha *= color;
#endif

material.baseColor = baseColorWithAlpha;
material.diffuse = baseColorWithAlpha.rgb;
material.alpha = baseColorWithAlpha.a;

Expand Down