godotengine / godot

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

Vulkan: Incorrect glTF mesh rendering due to automatic LOD kicking in too early with scaled bones #57895

Closed lucidium4 closed 2 years ago

lucidium4 commented 2 years ago

Godot version

4.0 Alpha 2

System information

Windows 11, Vulkan, AMD Radeon RX 5700 XT

Issue description

Screenshot 2022-02-09 175650 Screenshot 2022-02-09 175628

Steps to reproduce

Import a GLTF Mesh into a 3D Scene

Minimal reproduction project

(https://drive.google.com/file/d/1-CfrKX1gIe6pAInUdzXSVZg63TRjLkzU/view?usp=sharing)

fire commented 2 years ago

The Google drive is not public.

mrjustaguy commented 2 years ago

This is Mesh LOD related.

Calinou commented 2 years ago

As a workaround, set rendering/mesh_lod/lod_change/threshold_pixels to 0.0 in the Project Settings to disable the rendering of automatic mesh LOD. To disable LOD temporarily in the editor, click the Perspective menu in the top-left corner of the 3D viewport and select Display Advanced… > Disable LOD. You can also use the Display Wireframe debug draw mode to check how different LOD levels look.

You can also disable LOD generation on specifc imported 3D scenes in the Import dock:

image

Calinou commented 2 years ago

Reopening, as this issue should still be fixed :slightly_smiling_face:

I can confirm this on master a0558b8af. All the LOD settings are at their default, so I don't know why this is happening. Object scales are also set to their defaults, though I don't know if you used a very large (or small) scale in your 3D DCC (such as Blender) for the character model. cc @fire

For easier reproduction, I edited the MRP to only include essential files: Mesh Rendering Bug_1.zip

reduz commented 2 years ago

@JFonS

fire commented 2 years ago

The scale is weird.

editor_screenshot_2022-02-12T034043

The parent node of the skeleton has a 0.01 scale node and then the skins are 100 times bigger.

Zireael07 commented 2 years ago

@fire: I had some meshes like that - I had to manually change scales and/or reexport, a quirk of export/import from Blender maybe? (Besides, Blender export/import could really stand a better documentation so that people don't get those weird size issues)

akien-mga commented 2 years ago

As per https://github.com/godotengine/godot/pull/59147#issuecomment-1072778167 it seems the problem might be a bug in the mesh itself.

Calinou commented 2 years ago

Is there a way to detect such meshes and warn on import that the mesh itself should be fixed?

fire commented 2 years ago

Typically I see this problem happen when the scale is different from Vector(1,1,1). Maybe warn on this. Sign is important too.

The most common case of lod failing is the mesh Ref having Vector3(0.01, 0.01, 0.01).

The global scale of the skeleton node is then set to Vector3(100, 100, 100).

reduz commented 2 years ago

Maybe we could detect a scale in the armature and apply this to the LOD process, or apply the armature before doing the LOD? (since we mostly care about the resulting indices anyway).

mrjustaguy commented 2 years ago

The problem is probably with the AABB being incorrect for skinned meshes when any scaling/rotation/translation is done on the bones, be it rest or pose. This is why it's aggressively scaling, because the AABB it's using to determine scale is tiny compared to the mesh.

I've noticed this when I was working with MakeHuman Rigged meshes with the wrong settings used on export that caused the AABB to be rotated by 90 degrees and 10x smaller compared to what it actually was.. Fixing said settings on export fixed the rig so that it wasn't scaled and rotated anymore, and suddenly ALOD was working fine. the LOD meshes haven't changed, just their sensitivity.

fire commented 2 years ago

May be resolved by https://github.com/godotengine/godot/pull/60115. Importer option for permanent scaling of the scene.

Settings

Scene scale set to 0.01.

Root scale set to 100.

Still has problems > 100m.

https://user-images.githubusercontent.com/32321/173843880-dfdeb67a-7408-4e9d-bb07-f40cd765a7b5.mp4

nathanfranke commented 2 years ago

Was this resolved in https://github.com/godotengine/godot/pull/65493?

clayjohn commented 2 years ago

Was this resolved in https://github.com/godotengine/godot/pull/65493?

@fire says it does in https://github.com/godotengine/godot/pull/65493#issuecomment-1240199556

Closing as fixed by #65493

fire commented 2 years ago

I tested #65493 and manually confirmed it is fixed.