# Marching cubes and LoD

I have and octree based world constructed (on the start) via marching cubes with certain density function to make a terrain (variations on noises). The terrain is rater smooth, it is not like minecraft blocky terrain at all. The deepest level of LoD is 12 and on this level (let's say) player is moving. The player have an ability to place blocks (just like in minecraft) and dig holes (block-like) in terrain. The blocks are stored as an overrides to density function so that the rendering algorithm looks if there's an override for each point of the certain marching cube block, and if there is, it constructs solid block, or hole there. Pretty simple.

The question is, what technique of LoD do you recommend, when I move away from the certain place where I have put my blocks to sustain details on lower LoD levels as much as possible?

I can see two ways there:

1. Render the terrain separately on each LoD and custom geometry (blocks) leave as they are. What this means is that my terrain will contain all blocks I placed rendered on LoD 12 while the terrain will be on appropriate LoD. This will lead to resource drain because all my custom blocks need to be rendered with maximum detail not depending how close I am to them, but on the other hand my house I built will look as house from the distance.

2. Just interpolate weights when switching to lower LoD level. This will be fast, but it will change how my blocks look (or should I say it will change a lot how looks whole my construction) drammatically - if I make a house from blocks and move away, my house won't look as house anymore.

From what I can tell there are two major requirements for your terrain that Marching Cubes (MC) simply cannot fulfill:

1. Sharp edge rendering
2. Chunked LOD

I'd recommend the Dual Contouring (DC) algorithm, which handles both cases quite gracefully, and as a bonus is able to optimize chunks with fewer features to use fewer triangles. There is an often-cited paper on the subject here.

http://www.cs.rice.edu/~jwarren/papers/dualcontour.pdf

The main difference between MC and DC is that DC operates on Hermite data. In the context of terrain rendering, there are two different sets of data that comprise Hermite data, usually based around a uniform 3D grid.

1. Signs (for one material) or indices (for multiple materials) at each corner
2. Surface intersections and normals at each edge that exhibits a sign or index change

The paper explains how the algorithm operates on the Hermite data and how to adapt it for an octree instead of just a uniform grid. Some other sources that may prove useful are:

http://upvoid.com/devblog/2013/05/terrain-engine-part-1-dual-contouring/

http://upvoid.com/devblog/2013/07/terrain-engine-part-2-volume-generation-and-the-csg-tree/

https://stackoverflow.com/questions/6485908/basic-dual-contouring-theory