Dual Contouring
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.
Also known as DC
In the family Geometry, meshing & signed distance fields, isosurface extraction
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | None found | |
| Babylon.js 9.38.0 | None found | |
| Godot 4.7 | None found | |
| Unity | None found | |
| Unreal 5.7 | None found | |
| Blender 5.2 | Built in | Modifiers > Generate > Remesh (Blocks / Smooth / Sharp octree modes call dualcon dual-contouring library) docs |
| WebGPU W3C | None found | |
| Metal | None found |
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 choose it
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
Choose it for voxel or SDF editing tools, CSG results and CAD-like shapes where hard edges must stay crisp. Prefer Manifold Dual Contouring when the output must be a valid 2-manifold, Surface Nets when you want the same dual topology without needing normals, and Marching Cubes when you only have a binary or noisy field with no reliable gradient.
Field marks
- 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
Presets
Dual Contouring — Marching Cubes corner blunting (left) vs QEF sharp-feature preservation (right)
{
"P_VOXEL_RES": 7,
"P_DUAL_GRID": 0.85,
"P_SPLIT": 0.46,
"P_ROT_SPEED": 1
}Show GLSL (144 lines)
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).
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| dual-contouring-live | Tesla T4 1920x1080 | 47.1× baseline (heavy) · 1.48 ms / 1.53 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| dual-contouring-live | NVIDIA L4 1920x1080 | 39.6× baseline (heavy) · 0.626 ms / 0.700 ms · 2.4× faster on L4 | opengl-timer-query · Cross-architecture validation |
| dual-contouring-live | NVIDIA A100-SXM4-40GB 1920x1080 | 28.0× baseline (heavy) · 0.807 ms / 0.823 ms · 1.8× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): its primary source cites Marching Tetrahedra; cited by Kinematic Swept-Volume Boolean Carving via 2D Slab Distance Fields, MeshAnything, OpenVDB, TRELLIS.2 (O-Voxel structured latents).
Crosses
- SDF Modeling: CSG and Smooth Minimum: The SDF gives both edge crossings and analytic normals for the Hermite samples.
Sources
- primaryTao 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.Verified via crossref · 2026-11-29doi:10.1145/566570.566586
- tutorialBoris the Brave. Dual Contouring Tutorial. boristhebrave.com.Verified via live page · 2026-11-29