Skip to content

Commit

Permalink
Merge pull request #12043 from CesiumGS/color-factor
Browse files Browse the repository at this point in the history
Fix base color and reflectivity calculations for PBR materials
  • Loading branch information
ggetz authored Jun 25, 2024
2 parents 4fffc9f + 61681f9 commit 9d7b980
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

##### Fixes :wrench:

- Fixed diffuse color calculation for PBR materials. Many models will now appear slightly brighter. [#12043](https://github.com/CesiumGS/cesium/pull/12043)
- Fixed the calculation of base color in materials using the KHR_materials_specular extension [#12041](https://github.com/CesiumGS/cesium/issues/12041).
- Fixed issue where Entities would not use a custom ellipsoid. [#3543](https://github.com/CesiumGS/cesium/issues/3543)
- Fixed issue where Property 'availability' is missing in type 'CustomHeightmapTerrainProvider' but required in type 'TerrainProvider' when using with typescript

Expand Down
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);
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

0 comments on commit 9d7b980

Please sign in to comment.