---
id: "dual-contouring"
title: "Dual Contouring"
aliases: [DC]
domain: "geometry"
stage: "geometry"
realtime: "interactive"
platforms: [cpu, cuda, desktop-gpu, unity, webgl2]
year_introduced: 2002
inputs: [voxels, sdf]
outputs: [mesh, normals]
style: "both"
dynamic: "both"
cost: "medium"
authority: "Ju et al., 2002"
url: "https://texelatlas.vercel.app/t/dual-contouring/"
sources_verified_at: "2026-11-29"
---
# Dual Contouring (Ju et al., 2002)

> Places one vertex per cell by minimising a quadratic error built from Hermite data (edge crossings plus surface normals), then connects vertices of cells sharing a sign-changing edge. Preserves sharp corners that marching cubes bevels.

## Reach for it when

- marching cubes rounds off sharp corners and edges
- voxel terrain needs crisp cliffs and building edges
- extract mesh from sdf keeping sharp features
- adaptive isosurface mesh with fewer triangles

## How it works

Along each grid edge with a sign change, store the crossing point and the surface normal there (Hermite data). For every cell that contains the surface, collect those plane constraints and solve a small least-squares problem (QEF) for the point that best fits all planes; the solution lands on a corner when three or more different planes meet, on an edge for two. Faces are then generated in the dual sense: for each sign-changing edge, emit a quad joining the four cells around it. Octree versions collapse cells bottom-up when the combined QEF error stays under a tolerance, which makes adaptive meshes. QEF solving needs SVD or QR with truncation, plus clamping vertices to the cell so they cannot fly away on near-parallel planes.

## When to use it

Choose it for voxel or SDF editing tools, CSG results and CAD-like shapes where hard edges must stay crisp. Prefer [Manifold Dual Contouring](https://texelatlas.vercel.app/t/manifold-dual-contouring.md) when the output must be a valid 2-manifold, [Surface Nets](https://texelatlas.vercel.app/t/surface-nets.md) when you want the same dual topology without needing normals, and [Marching Cubes](https://texelatlas.vercel.app/t/marching-cubes.md) when you only have a binary or noisy field with no reliable gradient.

## Cost

medium — Linear in surface cells; the per-cell QEF solve makes it a few times slower than marching cubes.
Measured GPU Weight: 47.08× baseline (heavy) — 1.4782 ms median / 1.5332 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 39.63× baseline (heavy) — 0.6261 ms median (2.36× faster on L4).
Ampere A100 scaling: 28.01× baseline (heavy) — 0.8067 ms median (1.83× faster on A100).

## Failure modes

- Non-manifold edges and self-intersecting quads where several surface sheets pass through one cell
- Vertices shoot out of the cell on near-degenerate QEFs unless clamped or biased towards the mass point
- Needs good normals: noisy gradients create spikes
- Flat-shaded look and zig-zag normals on thin features at coarse resolution
- T-junction cracks between octree levels

## Engine support

- blender: builtin — `Modifiers > Generate > Remesh (Blocks / Smooth / Sharp octree modes call dualcon dual-contouring library)` (evidence: https://github.com/blender/blender/blob/main/source/blender/modifiers/intern/MOD_remesh.cc, checked 2026-12-01)

## Dataflow

- Inputs: voxels, sdf
- Outputs: mesh, normals
- Platforms: cpu, cuda, desktop-gpu, unity, webgl2

## Presets

### Dual Contouring — Marching Cubes corner blunting (left) vs QEF sharp-feature preservation (right) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_VOXEL_RES": 7,
  "P_DUAL_GRID": 0.85,
  "P_SPLIT": 0.46,
  "P_ROT_SPEED": 1
}
```

```glsl
const float P_VOXEL_RES = 7.0; // P Voxel Grid Res [4.0, 14.0, 1.0]
const float P_DUAL_GRID = 0.85; // P Dual Quad Wire [0.0, 1.5, 0.05]
const float P_SPLIT = 0.46; // P MC / DC Split [0.0, 1.0, 0.02]
const float P_ROT_SPEED = 1.0; // P Spin Speed [0.0, 2.5, 0.05]

mat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }

float sdBox(vec3 p, vec3 b) {
  vec3 q = abs(p) - b;
  return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
}

// Sharp-featured CAD mechanical block: 90-degree cube minus cylindrical bore minus corner step
float exactCAD(vec3 q) {
  float dCube = sdBox(q, vec3(0.62));
  float dBore = length(q.xy) - 0.30;
  float dCut = sdBox(q - vec3(0.42, 0.42, 0.0), vec3(0.32, 0.32, 0.85));
  return max(max(dCube, -dBore), -dCut);
}

// Marching Cubes approximation: lacks Hermite normals so grid quantization bevels/blunts sharp 90-deg edges!
float mapMarchingCubes(vec3 p, float res, float spin) {
  vec3 q = p;
  q.xz = rot2(spin * 0.38) * q.xz;
  q.yz = rot2(0.42) * q.yz;
  float h = 0.42 / max(res, 2.0);
  // 8-corner trilinear box blur of the SDF mimics Marching Cubes edge-crossing bevel loss
  float d = exactCAD(q);
  float dBlur = (
    exactCAD(q + vec3(h, h, h)) + exactCAD(q + vec3(-h, h, h)) +
    exactCAD(q + vec3(h, -h, h)) + exactCAD(q + vec3(-h, -h, h)) +
    exactCAD(q + vec3(h, h, -h)) + exactCAD(q + vec3(-h, h, -h)) +
    exactCAD(q + vec3(h, -h, -h)) + exactCAD(q + vec3(-h, -h, -h))
  ) * 0.125;
  // Subtle voxel-cell stair-stepping modulation
  vec3 cellWobble = sin(q * res * 6.2831853) * (0.045 / res);
  return mix(d, dBlur, 0.88) + (cellWobble.x + cellWobble.y + cellWobble.z) * 0.18;
}

// Dual Contouring (QEF solver): places dual vertices right onto sharp planes & creases using Hermite normals!
float mapDualContour(vec3 p, float spin) {
  vec3 q = p;
  q.xz = rot2(spin * 0.38) * q.xz;
  q.yz = rot2(0.42) * q.yz;
  return exactCAD(q);
}

vec3 calcNormalMC(vec3 p, float res, float spin) {
  vec2 e = vec2(0.003, 0.0);
  return normalize(vec3(
    mapMarchingCubes(p + e.xyy, res, spin) - mapMarchingCubes(p - e.xyy, res, spin),
    mapMarchingCubes(p + e.yxy, res, spin) - mapMarchingCubes(p - e.yxy, res, spin),
    mapMarchingCubes(p + e.yyx, res, spin) - mapMarchingCubes(p - e.yyx, res, spin)
  ));
}

vec3 calcNormalDC(vec3 p, float spin) {
  vec2 e = vec2(0.0018, 0.0);
  return normalize(vec3(
    mapDualContour(p + e.xyy, spin) - mapDualContour(p - e.xyy, spin),
    mapDualContour(p + e.yxy, spin) - mapDualContour(p - e.yxy, spin),
    mapDualContour(p + e.yyx, spin) - mapDualContour(p - e.yyx, spin)
  ));
}

vec3 aces(vec3 x) {
  x = max(x, 0.0);
  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
  float screenX = fragCoord.x / max(iResolution.x, 1.0);
  float split = clamp(P_SPLIT, 0.0, 1.0);
  float res = clamp(floor(P_VOXEL_RES + 0.5), 3.0, 16.0);
  float wireVis = clamp(P_DUAL_GRID, 0.0, 1.6);
  float spin = iTime * max(P_ROT_SPEED, 0.0);

  vec3 ro = vec3(0.0, 0.08, 2.50);
  vec3 rd = normalize(vec3(uv, -1.52));

  vec3 col = mix(vec3(0.032, 0.044, 0.070), vec3(0.09, 0.115, 0.165), smoothstep(-0.55, 0.55, uv.y));
  bool isDC = screenX >= split;

  float t = 0.0;
  bool hit = false;
  for (int i = 0; i < 64; i++) {
    vec3 p = ro + rd * t;
    float d = isDC ? mapDualContour(p, spin) : mapMarchingCubes(p, res, spin);
    if (d < 0.002) { hit = true; break; }
    t += d * 0.85;
    if (t > 9.0) break;
  }

  if (hit) {
    vec3 p = ro + rd * t;
    vec3 n = isDC ? calcNormalDC(p, spin) : calcNormalMC(p, res, spin);

    // Object space for voxel / dual quad wireframe overlay
    vec3 objP = p;
    objP.xz = rot2(spin * 0.38) * objP.xz;
    objP.yz = rot2(0.42) * objP.yz;

    vec3 qf = abs(fract(objP * res - 0.5) - 0.5);
    vec3 an = abs(n);
    float dQuad = (an.x > an.y && an.x > an.z) ? min(qf.y, qf.z) : ((an.y > an.z) ? min(qf.x, qf.z) : min(qf.x, qf.y));
    // Marching Cubes outputs irregular triangles (diagonal cuts across voxel faces); Dual Contouring outputs clean dual quads!
    float dTriDiag = abs((fract(objP.x * res) - fract(objP.y * res)));
    float wireMC = smoothstep(0.065, 0.015, min(dQuad, dTriDiag * 0.7));
    float wireDC = smoothstep(0.055, 0.012, dQuad);

    // Highlight sharp QEF crease edges where two CAD faces intersect at 90 degrees
    float sharpCrease = 0.0;
    if (isDC) {
      vec3 nA = calcNormalDC(p + vec3(0.012, 0.0, 0.0), spin);
      vec3 nB = calcNormalDC(p + vec3(0.0, 0.012, 0.0), spin);
      vec3 nC = calcNormalDC(p + vec3(0.0, 0.0, 0.012), spin);
      sharpCrease = smoothstep(0.18, 0.55, (1.0 - dot(n, nA)) + (1.0 - dot(n, nB)) + (1.0 - dot(n, nC)));
    }

    vec3 l1 = normalize(vec3(0.62, 0.85, 0.55));
    vec3 l2 = normalize(vec3(-0.72, -0.22, 0.52));
    float diff1 = max(dot(n, l1), 0.0);
    float diff2 = max(dot(n, l2), 0.0);
    vec3 hVec = normalize(l1 - rd);
    float spec = pow(max(dot(n, hVec), 0.0), 42.0) * 0.48;
    float rim = pow(1.0 - max(dot(n, -rd), 0.0), 3.0) * 0.28;

    vec3 alb = isDC ? vec3(0.20, 0.72, 0.68) : vec3(0.76, 0.44, 0.34);
    col = alb * (0.26 + 0.84 * diff1 + 0.24 * diff2) + vec3(spec) + vec3(0.45, 0.72, 1.0) * rim;

    if (isDC) {
      col = mix(col, vec3(0.05, 0.14, 0.18), wireDC * 0.52 * min(wireVis, 1.2));
      col = mix(col, vec3(1.0, 0.92, 0.42), sharpCrease * 0.85);
    } else {
      col = mix(col, vec3(0.18, 0.08, 0.06), wireMC * 0.52 * min(wireVis, 1.2));
    }
  }

  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));
  col = mix(col, vec3(0.95, 0.97, 1.0), sep);

  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}
```

Attribution: Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).

## Lineage

- extended by [Manifold Dual Contouring](https://texelatlas.vercel.app/t/manifold-dual-contouring.md)

## Combines with

- [SDF Modeling: CSG and Smooth Minimum](https://texelatlas.vercel.app/t/sdf-csg-smooth-min.md): The SDF gives both edge crossings and analytic normals for the Hermite samples.

## Sources

1. [primary] Tao Ju, Frank Losasso, Scott Schaefer, Joe Warren (2002) Dual contouring of hermite data. Proceedings of the 29th annual conference on Computer graphics and interactive techniques. https://doi.org/10.1145/566570.566586 (verified via crossref on 2026-11-29)
2. [tutorial] Boris the Brave Dual Contouring Tutorial. boristhebrave.com. https://www.boristhebrave.com/2018/04/15/dual-contouring-tutorial (verified via http on 2026-11-29)

## Cite this entry

Texel. "Dual Contouring." https://texelatlas.vercel.app/t/dual-contouring/ (accessed 2026-12-01).
