PorkStudios / FarPlaneTwo

Level-of-Detail renderer in Minecraft. Allows for render distances of millions of blocks. (Cubic Chunks-compatible) (WIP)
https://daporkchop.net/
Other
1.45k stars 48 forks source link

Question: How does the meshing work? #49

Closed Dimev closed 3 years ago

Dimev commented 3 years ago

I know you are going to do a big writeup later on when the mod is closer to completion, but I'm interested: how do you generate the meshes for the distant chunks?

Looking through the code it looks like it's some form of dual contouring, that looks to be running on a regular grid. Is this correct, and if so, how do you avoid gaps between lods?

NotStirred commented 3 years ago

here is a debug image of the LOD blending (the image is from a month ago) image

DaMatrix commented 3 years ago

well, it depends on which mode you're talking about:

heightmap mode

extremely simple: takes the highest point, rough generators can binary search the entire Y coordinate space. mesh simplification is as trivial as, for each 2² space of samples, taking the sample whose height has the greatest deviation from the average of all 4.

voxel mode

rough generators simply generate a density grid, and i run dual contouring on that (a slightly modified variant that allows me to have multiple density types for solid/transparent blocks at once, and mixes them together). this doesn't need anything special for generating at lower detail levels - i just need to increase the distance between sample points. exact generators are also pretty simple: i just track which blocks have at least one exposed face, and assemble the faces into a mesh. the complicated part happens when simplifying those meshes, as i can't do exact generation at arbitrarily low scales. basically, i made the observation that dual contouring doesn't ACTUALLY require a density grid, all it needs is the coordinates and normal vector at which the isosurface intersects each one of the voxel edges. by somewhat abusing this fact, i can run dual contouring on a MESH rather than a density grid. more specifically, i combine all the meshes in a 2³ region of tiles and dual contour those to get a single low-resolution tile. it's not a perfect solution, and i plan to change it to use some form of vertex clustering once i finish changing the "voxel renderer" into a "arbitrary 3d mesh broken up into tiles-renderer".

seamless transitions

literally just this. in voxel mode i simply run it in 3d.

Dimev commented 3 years ago

Thanks!