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

Mesh LOD merges flat-shaded vertices together with smooth-shaded vertices #103722

Open
Tracked by #57416
HaroldH76 opened this issue Mar 6, 2025 · 5 comments
Open
Tracked by #57416

Comments

@HaroldH76
Copy link

Tested versions

  • Reproducable in v4.4.stable.mono.official [4c311cb]
  • Not reproducable in v4.3.stable.mono.official [77dcf97]

System information

Windows 11 -Godot v4.4stable -Vulkan(Forward+) -dedicated NVidia 2070 Super (laptop)

Issue description

I have a game in which I like everything flat shaded (low poly design). When I upgrade the game from 4.3 to 4.4 then some models are not flat shaded anymore. I use no special shaders. Just a Blender model and in Blender I set it to flat shading and then I export it as glb file.

See screenshot for the difference in the green model.
See attached zip for a 4.3 and 4.4 project: godot43-44.zip
Also this might be related to this issue: #103675 ?

Image

Steps to reproduce

  • Create model in Blender
  • Make some faces with a slight angle
  • Set material with high metallic
  • Export model as glb
  • Import model in Godot 4.4

Minimal reproduction project (MRP)

See attached zip for a 4.3 and 4.4 project: godot43-44.zip

@Calinou
Copy link
Member

Calinou commented Mar 6, 2025

This is caused by mesh LOD merging vertices together and using smooth shading in the process (presumably for performance reasons).

smooth_shading_lod.mp4

This issue is not present in 4.3, most likely because it uses an older version of meshoptimizer with different optimization. If you disable Meshes > Generate LOD on the Import dock on the 3D scene in question, the issue will go away.

Normal buffer comparison:

4.3 4.4
Image Image

@HaroldH76 Can you try following the same steps on 4.4 dev/beta/RCs to determine when the regression started? You can download them here.

@Calinou Calinou changed the title Flat shading in 4.4 is not as flat as in 4.3 Mesh LOD merges flat-shaded vertices together with smooth-shaded vertices Mar 6, 2025
@HaroldH76
Copy link
Author

@Calinou thx for the quick response!

I tested other versions and:
v4.4.dev4.official [36e6207] => Nok
v4.4.dev3.official [f4af820] => Ok

Also disabling generating LODs on import settings fixed it for my game.

Thx again!

@Calinou
Copy link
Member

Calinou commented Mar 7, 2025

Thanks for the bisecting help 🙂
Changelog between 4.4.dev3 and 4.4.dev4: https://godotengine.github.io/godot-interactive-changelog/#4.4-dev4

This changelog includes #98529, so there's a fair chance it's related. I'll bisect this just to make sure.

Edit: I bisected the regression to #98529. cc @zeux

@Calinou Calinou added this to the 4.5 milestone Mar 7, 2025
@zeux
Copy link
Contributor

zeux commented Mar 7, 2025

The LOD generator in Godot has always (edit: well, since like 4.1? it's been a while) welded vertices with similar normals before simplification before passing it to the simplifier. So I'm surprised this ever worked on 4.3; maybe because the attribute metric was not working as well, the simplifier for some reason was hesitant to merge these specifically. I assume it's just a happenstance, for example maybe the edges of the object were locked and the object is so low-poly that all edge collapses were prevented before the update due to extra topological restrictions that were lifted.

This is controlled by the "normal angle" threshold in import settings. Setting that to 10 (from default 60) fixes this specific example.

I'm not sure it's realistic to expect the simplifier to preserve the facets with the setting set to an angle that exceeds the angle between faceted triangles in a given model, because it's literally instructed to simplify from a welded model, and any collapse around the welded region will effectively change the shading. If faceting needs to be preserved exactly, the setting should be set to a very low value (which obviously limits simplification to only flat areas, but such is life...).

@zeux
Copy link
Contributor

zeux commented Mar 7, 2025

The face normal angle here is about 15 degrees fwiw, so it makes sense that the threshold needs to be set to 10 degrees to work.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants