godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.19k stars 21.21k forks source link

Flat normals can turn smooth in the distance due to automatic mesh LOD #70603

Open SmartySmart702 opened 1 year ago

SmartySmart702 commented 1 year ago

Godot version

4.0 Beta 10

System information

GTX 1070, forward_plus, mobile, gl_compatibility

Issue description

specular reflection fickering (see video)

https://youtu.be/yaEG7Lg1Luk

Steps to reproduce

Simple scene with a point light and cubes (arranged in a grid for better visibility of the issue) with a dark material (roughness ~0.3). Cube is default Blender cube with bevel modifier, flat shading.

Minimal reproduction project

shading_flickering.zip

SmartySmart702 commented 1 year ago

Oh I forgot to mention that this only happens for cubes with round corners but not for normal cubes.

Calinou commented 1 year ago

I can confirm this on 4.0.beta b6e06038f (Linux, AMD Radeon RX 6900 XT with Mesa RADV).

This is a mesh LOD issue, as disabling mesh LOD generation on the glTF file in the Import dock, clicking Reimport then reassocaiating mesh resources in every MeshInstance3D node to point to the cube.res file rather than making it built-in.

Fixed MRP: shading_flickering_fixed.zip

You can also use the Debug Advanced > Disable Mesh LOD debug draw mode in the Perspective menu to preview what it looks like once it's fixed.

Normals look flat until the specular reflection changes:

image

Then, when moving past the threshold of the first LOD, normals look smooth:

image

This is expected from a performance standpoint, as smooth-shaded meshes require fewer vertices than flat-shaded meshes and are therefore faster to render. I'm not sure if we can do anything about this, other than warning in the documentation that some "corner case" meshes may require disabling LOD generation on import to look good in the distance.

SmartySmart702 commented 1 year ago

Hmm for me it looks like a normal issue (related to auto lod) but idk. I also tried a smooth shaded cube with round corners: ghg34gfh

Calinou commented 1 year ago

Hmm for me it looks like a normal issue (related to auto lod) but idk. I also tried a smooth shaded cube with round corners:

This occurs because the mesh is too simplified in the distance for normals to be accurately represented. The issue is generally not noticeable with diffuse lighting, but intense specular lighting like in your example can make it noticeable.