Skip to content

Mapblock mesh LOD#16594

Draft
Handmade9485 wants to merge 156 commits intoluanti-org:masterfrom
Handmade9485:convex_hull
Draft

Mapblock mesh LOD#16594
Handmade9485 wants to merge 156 commits intoluanti-org:masterfrom
Handmade9485:convex_hull

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, on less detailed meshes. The meshes also use considerably less RAM, since their vertex count is a lot smaller. The LODs also yield a performance improvement in my testing.

I redid this benchmark now, with 5.15 merged.

These stats were gathered by standing still in a pre-emerged world with 4000 node render and send distance, and a mesh chunk size of 16, for 15 minutes. They show how these system resources change over time or as more chunks get generated. The lod settings had a threshold of 15 blocks, a quality of 2, and a texture threshold of 2.

image screenshot_20260214_143113

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

@lhofhansl
Copy link
Contributor

Needs a rebase again. :(
Sorry @Handmade9485 .

@Handmade9485
Copy link
Author

@lhofhansl no need to be sorry.
Im just a little burnt out on this at the moment, but if the past is anything to go by, ill probably find the motivation to continue working on this in a couple of months.

And even then, Id probably try to get this feature complete before trying to resolve the merge conflicts. So, If anyone has input on how to do any of these, or if they are even feasible/necessary, let me know:

  1. Making LODs be opt in for games.
    Im worried about existing games, which were made without LOD support. Adding this retroactively, could destroy any game that relies on some level of visual clarity/fidelity.

  2. Zooming in should show more detailed blocks.
    Showing the player a zoomed in version of an LOD block wouldnt be very helpful, so the engine would need to switch from e.g. LOD2 up to LOD1. Im just not sure on the best implementation for this. Or maybe is isnt even necessary for this PR to begin with, and can be postponed.

  3. Reflective water makes the LOD line pretty obvious.
    No idea yet, how the engine differentiates between water and other liquids, to apply the shader only to the water, but since the LODs arent affected by that shader, it makes the seams pretty noticeable.

@sfan5
Copy link
Member

sfan5 commented Jan 17, 2026

First we need the necessary "infrastructure" for any kind of LODs to be implemented, something like described here: #15172 (comment)

@kromka-chleba
Copy link
Contributor

Are distant mapblocks still simplified to cubes as in the OP's screenshot?
I believe triangulated planes would both be more efficient and look better.
Thoughts?

@Handmade9485
Copy link
Author

I believe triangulated planes would both be more efficient and look better. Thoughts?

What do you mean by triangulated planes?

I did try less blocky approaches before, but they were bothersome. One approach was splitting the chunk into smaller segments for which I then generated convex hulls (thats why the branch im merging from is still called that).
But it was surprisingly difficult to get the hulls to align where they meet. And since all of minecrafts LOD mods use larger voxels and still look fine, i discarded that hull idea.

But I dont think they would be more efficient. On paper? Yes. But in practice, I doubt that it would make much of a difference. Especially if you look at the vram graph, the closer non-lod blocks make up most of the vertex count anyway.

@kromka-chleba
Copy link
Contributor

But it was surprisingly difficult to get the hulls to align where they meet. And since all of minecrafts LOD mods use larger voxels and still look fine, i discarded that hull idea.

Well, sticking with the simpler solution that works is probably better then. Thanks for clarification.
I assume this won't be that visible in the game, since distant lods are far away and relatively tiny.

@Handmade9485
Copy link
Author

Well, as difficult as it was for me to come to terms with, the greedy meshing was a mistake. Using non greedy meshes does use a bit more ram, but the mesh generation got faster by at least an order of magnitude. It also looks better and made it way simpler to keep water surfaces the same level, even across LOD borders.

So with this done, I cant think of anything else to implement at this point. It seems like I still gotta fix a few merge conflicts, but then what? Do I just click the "Ready for review" button?

screenshot_20260305_001929

@nauta-turbidus
Copy link
Contributor

So with this done, I cant think of anything else to implement at this point. It seems like I still gotta fix a few merge conflicts, but then what? Do I just click the "Ready for review" button?

Probably, yeah. Even if there is more stuff that could be done, it's better to leave the rest (pointclouds? etc.) for future PRs (assuming this one goes well).

name added 2 commits March 5, 2026 19:41
…ex_hull

# Conflicts:
#	client/shaders/nodes_shader/opengl_fragment.glsl
#	src/client/shader.cpp
#	src/client/shader.h
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.

7 participants