Skip to content

Conversation

universyu
Copy link

  • Added error checks to ensure all meshes have vertex normals or flat shading
  • Fixed issue where flatShading setting from original material was lost
  • New materials now correctly inherit flatShading from the original material

Related issue: (#31799)

Description

Some models use materials with flatShading = true while their geometries do not contain vertex normals.

In the main scene, these models render correctly because flatShading does not require vertex normals.
In ProgressiveLightMap, however, the material was replaced with an internal uvMat that had flatShading = false. This caused the affected objects to render completely black.
Additionally, when a material had flatShading = false and the geometry had no vertex normals, the code did not throw any warning or error, leading to silent failures.
This fix ensures:

The flatShading value is now correctly inherited from the original material.
If flatShading = false and the geometry has no vertex normals, an error is thrown to prevent silent rendering failures.

- Added error checks to ensure all meshes have vertex normals or flat shading
- Fixed issue where flatShading setting from original material was lost
- New materials now correctly inherit flatShading from the original material
@@ -205,6 +211,10 @@ class ProgressiveLightMap {
// Set each object's material to the UV Unwrapped Surface Mapping Version
for ( let l = 0; l < this.lightMapContainers.length; l ++ ) {

// Ensure the object has correct flatShading
const flatShading = this.lightMapContainers[ l ].basicMat.flatShading;
this.uvMat.flatShading = flatShading;
Copy link
Collaborator

@Mugen87 Mugen87 Sep 2, 2025

Choose a reason for hiding this comment

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

There is only a single uvMat material which is assigned to all objects in the light map container. basicMat represents the original material of each object. So you can't assign a property value which might be different for all original materials to the shared uvMat instance.

@@ -123,6 +123,12 @@ class ProgressiveLightMap {

}

if ( !object.material.flatShading && !object.geometry.hasAttribute( 'normal' ) ) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's change this to:

if ( object.material.flatShading === false && object.geometry.hasAttribute( 'normal' ) === false ) {

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 4, 2025

Closing in favor of #31825.

It's a good addition to implement a check for vertex normals however it is somewhat out of scope to make the uv material compatible with all possible material permutations. Feel free to enhance ProgressiveLightMap according to your use case but it's probably best if the library version just focuses on the common use cases.

@Mugen87 Mugen87 closed this Sep 4, 2025
@Mugen87 Mugen87 added this to the r181 milestone Sep 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants