liveBook · Manning

Dual contouring

As explained in Geometry for Programmers

Dual contouring is an isosurface extraction algorithm that places one optimized vertex in each active grid cell and connects neighboring vertices across sign-changing edges.

Dual contouring converts a signed distance function (SDF) into a boundary representation: line segments for a 2D contour or triangles for a 3D surface. It is useful when an SDF has made Boolean operations, offsets, hollowing, interpolation, or mesh repair easier, and the result must become a mesh again. section 11.3 section 11.7

Start by sampling the SDF on a grid. A sign change across a grid edge means the desired contour crosses that edge. Instead of placing the contour directly on cell borders, dual contouring connects points belonging to neighboring cells. Finer grids produce a closer approximation, but require more memory and processing. section 11.3.2 section 11.3.4

The first version of those points is simply the cell centers. Dual contouring then moves each cell’s point toward a position that better fits the modeled curve or surface. SDF values indicate distance from the boundary; derivatives and gradients supply geometric direction for fitting the point. The resulting connections follow the boundary more closely than center-to-center segments. section 11.3.2

Figure 11.23 Dual contouring runs line segments not from cell centers but from a point in a cell that fits the modeled curve best to the same optimum point in a neighboring cell.
11-23

Each active cell contributes a fitted point, and neighboring fitted points are connected across sign-changing edges. This is the practical meaning of the algorithm’s dual layout. section 11.3.2

Choose dual contouring with its trade-offs in mind:

  • Prefer it when preserving sharp features matters; it generally retains them better than marching cubes. section 11.3.4
  • Use a finer grid only when the added accuracy justifies the larger model and higher computational cost. section 11.3.2 section 11.3.4
  • Treat the distinction as a practical tendency, not an absolute rule: implementations can add sharp-feature restoration to marching cubes or improve dual contouring for smooth surfaces. section 11.3.4

Repairing or offsetting an imperfect mesh

Convert a problematic triangle mesh to an SDF, perform an approximate operation such as closing gaps, restoring interpolated geometry, or making an offset, then extract a triangle mesh with dual contouring. The conversion is not exact, but it can be more workable than performing difficult operations directly on a large mesh. section 11.3 section 11.3.4

How Geometry for Programmers covers it

How deep it goes
Explains grid sampling, sign changes, cell-based connections, and gradient-guided fitting, while deferring implementation-specific refinements.
Examples
Uses SDF mesh repair, hole filling, surface offsets, and fitted points connected between neighboring cells.
What it assumes
Builds on signed distance functions and introduces derivatives and gradients as tools for geometric fitting.
What you can do after
Apply it to extract an approximate mesh or contour from an SDF while balancing sharp features, accuracy, and cost.
How it connects
Connects signed distance functions, gradients, triangle meshes, marching cubes, Boolean operations, and offsets.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Geometry for Programmers. The section links point to the parts of the book it draws on.