{
 "id": "dual-contouring",
 "title": "Dual Contouring",
 "aliases": [
  "DC"
 ],
 "domain": "geometry",
 "subdomain": "isosurface extraction",
 "stage": "geometry",
 "realtime": "interactive",
 "platforms": [
  "cpu",
  "cuda",
  "desktop-gpu",
  "unity",
  "webgl2"
 ],
 "year_introduced": 2002,
 "inputs": [
  "voxels",
  "sdf"
 ],
 "outputs": [
  "mesh",
  "normals"
 ],
 "style": "both",
 "dynamic": "both",
 "summary": "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.",
 "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": "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.",
 "cost": {
  "class": "medium",
  "notes": "Linear in surface cells; the per-cell QEF solve makes it a few times slower than marching cubes."
 },
 "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"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/566570.566586",
   "type": "paper",
   "title": "Dual contouring of hermite data",
   "authors": [
    "Tao Ju",
    "Frank Losasso",
    "Scott Schaefer",
    "Joe Warren"
   ],
   "year": 2002,
   "venue": "Proceedings of the 29th annual conference on Computer graphics and interactive techniques",
   "url": "https://doi.org/10.1145/566570.566586",
   "ids": {
    "doi": "10.1145/566570.566586"
   },
   "license": null,
   "extra": {
    "csl_type": "proceedings-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/566570.566586",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/566570.566586",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/566570.566586",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/566570.566586",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/566570.566586",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "ju2002dual"
  },
  {
   "role": "tutorial",
   "key": "url:https://www.boristhebrave.com/2018/04/15/dual-contouring-tutorial",
   "type": "tutorial",
   "title": "Dual Contouring Tutorial",
   "authors": [
    "Boris the Brave"
   ],
   "year": null,
   "venue": "boristhebrave.com",
   "url": "https://www.boristhebrave.com/2018/04/15/dual-contouring-tutorial",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261115074155/https://www.boristhebrave.com/2018/04/15/dual-contouring-tutorial/",
     "timestamp": "20261115074155"
    },
    "page_title": "Dual Contouring Tutorial",
    "host": "boristhebrave.com",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://www.boristhebrave.com/2018/04/15/dual-contouring-tutorial → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://www.boristhebrave.com/2018/04/15/dual-contouring-tutorial → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "http",
     "endpoint": "GET https://www.boristhebrave.com/2018/04/15/dual-contouring-tutorial → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "bravedual"
  }
 ],
 "presets": [
  {
   "id": "dual-contouring-live",
   "title": "Dual Contouring — Marching Cubes corner blunting (left) vs QEF sharp-feature preservation (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_VOXEL_RES": 7,
    "P_DUAL_GRID": 0.85,
    "P_SPLIT": 0.46,
    "P_ROT_SPEED": 1
   },
   "basis": "original",
   "license_note": "Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).",
   "code": "const float P_VOXEL_RES = 7.0; // P Voxel Grid Res [4.0, 14.0, 1.0]\nconst float P_DUAL_GRID = 0.85; // P Dual Quad Wire [0.0, 1.5, 0.05]\nconst float P_SPLIT = 0.46; // P MC / DC Split [0.0, 1.0, 0.02]\nconst float P_ROT_SPEED = 1.0; // P Spin Speed [0.0, 2.5, 0.05]\n\nmat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }\n\nfloat sdBox(vec3 p, vec3 b) {\n  vec3 q = abs(p) - b;\n  return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);\n}\n\n// Sharp-featured CAD mechanical block: 90-degree cube minus cylindrical bore minus corner step\nfloat exactCAD(vec3 q) {\n  float dCube = sdBox(q, vec3(0.62));\n  float dBore = length(q.xy) - 0.30;\n  float dCut = sdBox(q - vec3(0.42, 0.42, 0.0), vec3(0.32, 0.32, 0.85));\n  return max(max(dCube, -dBore), -dCut);\n}\n\n// Marching Cubes approximation: lacks Hermite normals so grid quantization bevels/blunts sharp 90-deg edges!\nfloat mapMarchingCubes(vec3 p, float res, float spin) {\n  vec3 q = p;\n  q.xz = rot2(spin * 0.38) * q.xz;\n  q.yz = rot2(0.42) * q.yz;\n  float h = 0.42 / max(res, 2.0);\n  // 8-corner trilinear box blur of the SDF mimics Marching Cubes edge-crossing bevel loss\n  float d = exactCAD(q);\n  float dBlur = (\n    exactCAD(q + vec3(h, h, h)) + exactCAD(q + vec3(-h, h, h)) +\n    exactCAD(q + vec3(h, -h, h)) + exactCAD(q + vec3(-h, -h, h)) +\n    exactCAD(q + vec3(h, h, -h)) + exactCAD(q + vec3(-h, h, -h)) +\n    exactCAD(q + vec3(h, -h, -h)) + exactCAD(q + vec3(-h, -h, -h))\n  ) * 0.125;\n  // Subtle voxel-cell stair-stepping modulation\n  vec3 cellWobble = sin(q * res * 6.2831853) * (0.045 / res);\n  return mix(d, dBlur, 0.88) + (cellWobble.x + cellWobble.y + cellWobble.z) * 0.18;\n}\n\n// Dual Contouring (QEF solver): places dual vertices right onto sharp planes & creases using Hermite normals!\nfloat mapDualContour(vec3 p, float spin) {\n  vec3 q = p;\n  q.xz = rot2(spin * 0.38) * q.xz;\n  q.yz = rot2(0.42) * q.yz;\n  return exactCAD(q);\n}\n\nvec3 calcNormalMC(vec3 p, float res, float spin) {\n  vec2 e = vec2(0.003, 0.0);\n  return normalize(vec3(\n    mapMarchingCubes(p + e.xyy, res, spin) - mapMarchingCubes(p - e.xyy, res, spin),\n    mapMarchingCubes(p + e.yxy, res, spin) - mapMarchingCubes(p - e.yxy, res, spin),\n    mapMarchingCubes(p + e.yyx, res, spin) - mapMarchingCubes(p - e.yyx, res, spin)\n  ));\n}\n\nvec3 calcNormalDC(vec3 p, float spin) {\n  vec2 e = vec2(0.0018, 0.0);\n  return normalize(vec3(\n    mapDualContour(p + e.xyy, spin) - mapDualContour(p - e.xyy, spin),\n    mapDualContour(p + e.yxy, spin) - mapDualContour(p - e.yxy, spin),\n    mapDualContour(p + e.yyx, spin) - mapDualContour(p - e.yyx, spin)\n  ));\n}\n\nvec3 aces(vec3 x) {\n  x = max(x, 0.0);\n  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  float screenX = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  float res = clamp(floor(P_VOXEL_RES + 0.5), 3.0, 16.0);\n  float wireVis = clamp(P_DUAL_GRID, 0.0, 1.6);\n  float spin = iTime * max(P_ROT_SPEED, 0.0);\n\n  vec3 ro = vec3(0.0, 0.08, 2.50);\n  vec3 rd = normalize(vec3(uv, -1.52));\n\n  vec3 col = mix(vec3(0.032, 0.044, 0.070), vec3(0.09, 0.115, 0.165), smoothstep(-0.55, 0.55, uv.y));\n  bool isDC = screenX >= split;\n\n  float t = 0.0;\n  bool hit = false;\n  for (int i = 0; i < 64; i++) {\n    vec3 p = ro + rd * t;\n    float d = isDC ? mapDualContour(p, spin) : mapMarchingCubes(p, res, spin);\n    if (d < 0.002) { hit = true; break; }\n    t += d * 0.85;\n    if (t > 9.0) break;\n  }\n\n  if (hit) {\n    vec3 p = ro + rd * t;\n    vec3 n = isDC ? calcNormalDC(p, spin) : calcNormalMC(p, res, spin);\n\n    // Object space for voxel / dual quad wireframe overlay\n    vec3 objP = p;\n    objP.xz = rot2(spin * 0.38) * objP.xz;\n    objP.yz = rot2(0.42) * objP.yz;\n\n    vec3 qf = abs(fract(objP * res - 0.5) - 0.5);\n    vec3 an = abs(n);\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));\n    // Marching Cubes outputs irregular triangles (diagonal cuts across voxel faces); Dual Contouring outputs clean dual quads!\n    float dTriDiag = abs((fract(objP.x * res) - fract(objP.y * res)));\n    float wireMC = smoothstep(0.065, 0.015, min(dQuad, dTriDiag * 0.7));\n    float wireDC = smoothstep(0.055, 0.012, dQuad);\n\n    // Highlight sharp QEF crease edges where two CAD faces intersect at 90 degrees\n    float sharpCrease = 0.0;\n    if (isDC) {\n      vec3 nA = calcNormalDC(p + vec3(0.012, 0.0, 0.0), spin);\n      vec3 nB = calcNormalDC(p + vec3(0.0, 0.012, 0.0), spin);\n      vec3 nC = calcNormalDC(p + vec3(0.0, 0.0, 0.012), spin);\n      sharpCrease = smoothstep(0.18, 0.55, (1.0 - dot(n, nA)) + (1.0 - dot(n, nB)) + (1.0 - dot(n, nC)));\n    }\n\n    vec3 l1 = normalize(vec3(0.62, 0.85, 0.55));\n    vec3 l2 = normalize(vec3(-0.72, -0.22, 0.52));\n    float diff1 = max(dot(n, l1), 0.0);\n    float diff2 = max(dot(n, l2), 0.0);\n    vec3 hVec = normalize(l1 - rd);\n    float spec = pow(max(dot(n, hVec), 0.0), 42.0) * 0.48;\n    float rim = pow(1.0 - max(dot(n, -rd), 0.0), 3.0) * 0.28;\n\n    vec3 alb = isDC ? vec3(0.20, 0.72, 0.68) : vec3(0.76, 0.44, 0.34);\n    col = alb * (0.26 + 0.84 * diff1 + 0.24 * diff2) + vec3(spec) + vec3(0.45, 0.72, 1.0) * rim;\n\n    if (isDC) {\n      col = mix(col, vec3(0.05, 0.14, 0.18), wireDC * 0.52 * min(wireVis, 1.2));\n      col = mix(col, vec3(1.0, 0.92, 0.42), sharpCrease * 0.85);\n    } else {\n      col = mix(col, vec3(0.18, 0.08, 0.06), wireMC * 0.52 * min(wireVis, 1.2));\n    }\n  }\n\n  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));\n  col = mix(col, vec3(0.95, 0.97, 1.0), sep);\n\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "dual-contouring",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:04:29.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.6332,
      "std": 0.1779,
      "min": 0.2198,
      "max": 0.9036
     },
     "image": "/specimens/dual-contouring-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "manifold-dual-contouring",
  "surface-nets",
  "marching-cubes"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "sdf-csg-smooth-min",
   "why": "The SDF gives both edge crossings and analytic normals for the Hermite samples."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/geometry/dual-contouring.json"
 },
 "solves": [
  "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"
 ],
 "authority": "Ju et al., 2002",
 "url": "https://texelatlas.vercel.app/t/dual-contouring/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 47.08,
  "tier": "heavy",
  "p50_ms": 1.4782,
  "p95_ms": 1.5332,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "dual-contouring-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 39.63,
   "tier": "heavy",
   "p50_ms": 0.6261,
   "p95_ms": 0.7004,
   "speedup_x": 2.36,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 28.01,
   "tier": "heavy",
   "p50_ms": 0.8067,
   "p95_ms": 0.8225,
   "speedup_x": 1.83,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}