godotengine / godot

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

[TRACKER] Automatic mesh LOD issues #57416

Open Calinou opened 2 years ago

Calinou commented 2 years ago

This tracker is about issues related to automatic mesh LOD performed at import-time in 4.0. This feature is not present in 3.x.

See also https://github.com/godotengine/godot/issues/70533, which is another common optimization used in 3D rendering.

This tracker does not cover issues related to manual (H)LOD performed using visibility ranges.

### Bugs
- [ ] https://github.com/godotengine/godot/issues/57608
- [ ] https://github.com/godotengine/godot/issues/58242
- [ ] https://github.com/godotengine/godot/issues/70603
- [ ] https://github.com/godotengine/godot/issues/71031
- [ ] https://github.com/godotengine/godot/issues/71141
- [ ] https://github.com/godotengine/godot/issues/71567
- [ ] https://github.com/godotengine/godot/issues/70759
- [ ] https://github.com/godotengine/godot/issues/72998
- [ ] https://github.com/godotengine/godot/issues/74198
- [ ] https://github.com/godotengine/godot/issues/76436
- [ ] https://github.com/godotengine/godot/issues/76892
- [ ] https://github.com/godotengine/godot/issues/77531
- [x] https://github.com/godotengine/godot/issues/53818
- [x] https://github.com/godotengine/godot/issues/54885
- [x] https://github.com/godotengine/godot/issues/57362
- [x] https://github.com/godotengine/godot/issues/57404
- [x] https://github.com/godotengine/godot/issues/57895
- [x] https://github.com/godotengine/godot/issues/59024
- [ ] https://github.com/godotengine/godot/issues/68484
- [ ] https://github.com/godotengine/godot/issues/78664
- [ ] https://github.com/godotengine/godot/issues/88123
- [ ] https://github.com/godotengine/godot/issues/88273
- [ ] https://github.com/godotengine/godot/issues/89394
### Enhancements
- [ ] https://github.com/godotengine/godot-proposals/issues/2600
- [ ] https://github.com/godotengine/godot-proposals/issues/3860
- [ ] https://github.com/godotengine/godot-proposals/issues/3861
- [ ] https://github.com/godotengine/godot/issues/65294
fire commented 2 years ago

Crashes in lod. https://github.com/godotengine/godot/issues/57362

TokisanGames commented 1 year ago

How do we generate lods and enable automatic use on already imported meshes? I have hundreds of assets already, stored in Godot's native resource format and saved in text scenes or as text resource files for git.

Calinou commented 1 year ago

How do we generate lods and enable automatic use on already imported meshes? I have hundreds of assets already, stored in Godot's native resource format and saved in text scenes or as text resource files for git.

Automatic LOD generation on import is only supported when importing 3D scenes (glTF/Collada/FBX), not when loading pre-made .mesh/.res meshes or importing 3D meshes (OBJ). That said, you can choose to import OBJ as a 3D scene in the Import dock if you need LOD generation and lightmap UV2 unwrap for OBJ.

There's a generate_lods() method on some class I forgot the name of, but it's more limited and doesn't seem to be meant for public use.

TokisanGames commented 1 year ago

Thanks for the answer, but you're not supporting core features on your own native format (arraymesh)? There are tons of projects right around the corner from migrating to gd4 that won't be able to use lod without manually reimporting a ton. Many of them have meshes stored in scene files as arraymeshes without realizing they are disconnected from their import file.

How do I know? Because the engine pushes you into the native format, because I've continually seen people on my team not realizing they are disconnecting resources from files which get saved in scene files, and because I've seen people do it on github issues.

They're all expecting autolod to just work and apparently it is not going to unless they first discover it's not working, troubleshoot it, write up an issue, then manually reimport every asset, then the setting up all of the auxiliary components again: physicsbodies, collision, materials, layers, parameters, etc.

There is an unusable surfacetool.generate_lod(), but it says Deprecated. Unused internally and neglects to preserve normals or UVs. There is an ImporterMesh.generate_lods(), and the class can output an arraymesh, but I see no way to pass in an arraymesh.

fire commented 1 year ago

In the godot architecture, many procedures are ran on the raw scene before the final output. I was developing the gltf export code but it currently has a duplication nodes bug. I don’t have a good solution to rerunning the import process. Maybe marking as escn?

fire commented 1 year ago

For clarity.

  1. Import this glb from https://github.com/KhronosGroup/glTF-Sample-Models/raw/master/2.0/Fox/glTF-Binary/Fox.glb
  2. Make local and save as a scn/tscn
  3. Go to the filesystem and rename to be .escn
  4. It will use the import dialog
  5. Noticed that lods are generated.

ESCN Game Project.zip

TokisanGames commented 1 year ago

Thanks for the suggestion. I took one asset, a single MeshInstance, saved it as a tscn, renamed it to escn, brought it back into a scene and saw the import dialog and brought it in w/ Generate LODs. However, no LODs were generated. Moving the camera back and forth, watching w/ Information and Wireframe turned on in the viewport, the mesh and info did not change.

By the way, I probably have 1000 assets. Manually reimporting them one at a time is a very big ask. It's an unreasonable process considering:

fire commented 1 year ago

I would try to get escn to operate on mesh instances instead of the importer mesh instance. It's a bug.

The other proposals don't have any plumbing in place, so it would be some work

https://github.com/godotengine/godot/issues/63498

TokisanGames commented 1 year ago

Thanks I'll follow the issue. If you want to get LOD generation to work on a meshinstance, rather than arraymesh, then workflow-wise, it would be reasonable to right-click the mesh instance and select Generate Lods. Or left-click the MeshInstance, click the Mesh menu, and Generate LODs. That should be the same as saving as escn and reopening, but would save developers a lot of clicks and manual work. Doing it once isn't a big deal, but it adds up if you have to do it hundreds of times.

fire commented 8 months ago

Does anyone know which issue describe lod generation being slow?

Profiles suggest https://share.firefox.dev/3ZY1DSC that:

  1. SurfaceTool::generate_tangents takes 73% of the total runtime