Skip to content

Conversation

@Handmade9485
Copy link

@Handmade9485 Handmade9485 commented Oct 18, 2025

This PR draft adds basic LOD mesh generation.

It works by changing how a mapblock mesh is generated depending on the distance to the player. Only certain node types are included in LOD generation, so for example plantlikes are not rendered. The allowed nodes are then used for a greedy mesher to further reduce vertex counts. The less detailed the LOD, the fewer node samples are used for mesh generation.

After a certain threshold, the mesh is rendered with only one material, without a texture to reduce material swaps.

The threshold after which LODs should be used, the rate at which LOD level increases, and the threshold for textureless mesh generation are configurable in the settings.

The LOD mesh generation is significantly faster than regular mesh generation, especially on less detailed meshes. The meshes also use considerably less RAM, since their vertex count is a lot smaller. The LODs also yield a small performance improvement in my testing.

image These stats were gathered by standing still in a pre-emerged world with 6000 node render and send distance, and a mesh chunk size of 6, for 15 minutes. They show how these system resources change over time or as more chunks get generated. The comparison is between 5.14 and my fork of 5.14. image This is the scene used for those tests. As you can see, the textureless LODs arent affected by the time of day. The more detailed LODs start a lot closer to the player, but dont stick out as much, since they are the correct brightness.

Ive gotten quite a bit in over my head with this one, so any feedback or maybe even advice is greatly appreciated.

To do

This PR is a Work in Progress

  • Fix textureless mesh day/night cycle. The materials used for these meshes currently dont get lighter/darker depending on the time of day.
  • Add a way for games to opt into supporting LODs.
  • Clean up the extremely hacky parts or the code.

To do maybe

  • Add a new kind of vertex. Since the LODs are always exactly grid aligned and are always cuboid, they wouldnt need 9 f32 fields for their position, size, and normal per vertex. The textureless meshes also wouldnt need any uv information.
  • Pre-generate multiple LODs at once, to easily swap between them when a player moves closer to or further away from a certain chunk or uses the zoom function.
  • Persist the meshes client side, so they can be loaded immediately upon loading a world. (Might be impossible due to mesh chunk size possibly changing or when playing on servers.)

How to test

These are not very detailed instructions since there are so many different combinations of nodes and settings.

  1. Set block send distance to a high value.
  2. Try different LOD settings
  3. Try different mesh chunk sizes, minimum vertices and other performance settings
  4. Try different mods and games
  5. Observe mesh gen over and underground and at different times of day

@sfan5 sfan5 changed the title Adding LOD capabilities Mapblock mesh LOD Nov 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

@ Client rendering Feature ✨ PRs that add or enhance a feature Performance Roadmap: supported by core dev PR not adhering to the roadmap, yet some core dev decided to take care of it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants