{
 "id": "marching-cubes",
 "title": "Marching Cubes",
 "aliases": [
  "MC"
 ],
 "domain": "geometry",
 "subdomain": "isosurface extraction",
 "stage": "geometry",
 "realtime": "interactive",
 "platforms": [
  "cpu",
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "cuda",
  "blender",
  "unity"
 ],
 "year_introduced": 1987,
 "inputs": [
  "voxels",
  "sdf"
 ],
 "outputs": [
  "mesh",
  "normals"
 ],
 "style": "both",
 "dynamic": "both",
 "summary": "Walks every cell of a scalar grid and, from the signs at its eight corners, picks a precomputed triangle pattern that cuts the cell where the field crosses the iso-value. The classic way to turn volumes or SDFs into triangle meshes.",
 "how_it_works": "Sample the field at grid corners. For each cell, build an 8-bit index from which corners are inside (below the iso-value). That index selects one of 256 cases (15 up to symmetry) from a lookup table listing which cell edges the surface crosses and how to connect those crossings into triangles. Each crossing vertex is placed by linear interpolation of the two corner values along the edge. Vertices on shared edges are identical, so welding them gives an indexed mesh. Normals come from the field gradient (central differences) rather than from the faces, which gives smooth shading. The whole loop is embarrassingly parallel: GPU versions classify cells, stream-compact the active ones with a prefix sum, then emit triangles.",
 "when_to_use": "Choose it when you need a quick, robust mesh from a density grid or SDF and sharp features do not matter (medical volumes, metaballs, voxel terrain, sculpt previews). Prefer `dual-contouring` or `manifold-dual-contouring` when corners and creases must survive, `surface-nets` when you want fewer, better-shaped triangles with the same simplicity, and `marching-tetrahedra` when you want to avoid the ambiguous cube cases.",
 "cost": {
  "class": "medium",
  "notes": "Linear in the number of cells; trivially parallel. Cost is dominated by field sampling and by triangle count, which grows with the square of grid resolution."
 },
 "failure_modes": [
  "Sharp edges and corners are rounded off because only edge crossings, never normals, are used",
  "Ambiguous face cases in the original 15-case table can produce holes or cracks unless the extended table is used",
  "Sliver triangles and uneven triangle sizes where the surface grazes a cell corner",
  "Stair-stepping or banding when the field is a binary mask instead of a smooth distance",
  "Cracks between chunks of different resolution unless a transition scheme is used"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/37402.37422",
   "type": "paper",
   "title": "Marching cubes: A high resolution 3D surface construction algorithm",
   "authors": [
    "William E. Lorensen",
    "Harvey E. Cline"
   ],
   "year": 1987,
   "venue": "ACM SIGGRAPH Computer Graphics",
   "url": "https://doi.org/10.1145/37402.37422",
   "ids": {
    "doi": "10.1145/37402.37422"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/37402.37422",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/37402.37422",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/37402.37422",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/37402.37422",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/37402.37422",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "lorensen1987marching"
  },
  {
   "role": "implementation",
   "key": "gh:mikolalysenko/isosurface",
   "type": "code",
   "title": "mikolalysenko/isosurface",
   "description": "Isosurface polygonizer algorithms",
   "authors": [
    "mikolalysenko"
   ],
   "year": 2013,
   "venue": "GitHub",
   "url": "https://github.com/mikolalysenko/isosurface",
   "ids": {
    "repo": "mikolalysenko/isosurface"
   },
   "license": "MIT",
   "extra": {
    "stars": 195,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2014-04-29T18:52:01Z",
    "language": "JavaScript",
    "homepage": null,
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mikolalysenko/isosurface",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mikolalysenko/isosurface",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mikolalysenko/isosurface",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mikolalysenko/isosurface",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mikolalysenko/isosurface",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mikolalysenko/isosurface",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "mikolalysenko2013mikolalysenkob"
  },
  {
   "role": "implementation",
   "key": "gh:mrdoob/three.js",
   "type": "code",
   "title": "mrdoob/three.js",
   "description": "JavaScript 3D Library.",
   "authors": [
    "mrdoob"
   ],
   "year": 2010,
   "venue": "GitHub",
   "url": "https://github.com/mrdoob/three.js",
   "ids": {
    "repo": "mrdoob/three.js"
   },
   "license": "MIT",
   "extra": {
    "stars": 119718,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-11-29T11:39:51Z",
    "language": "JavaScript",
    "homepage": "https://threejs.org/",
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "mrdoob2010mrdoob"
  },
  {
   "role": "tutorial",
   "key": "url:http://paulbourke.net/geometry/polygonise",
   "type": "tutorial",
   "title": "Polygonising a scalar field",
   "authors": [
    "Paul Bourke"
   ],
   "year": null,
   "venue": "paulbourke.net",
   "url": "https://paulbourke.net/geometry/polygonise",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261103002817/https://paulbourke.net/geometry/polygonise/",
     "timestamp": "20261103002817"
    },
    "page_title": "Polygonising a scalar field (Marching Cubes)",
    "host": "paulbourke.net",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET http://paulbourke.net/geometry/polygonise → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET http://paulbourke.net/geometry/polygonise → 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 http://paulbourke.net/geometry/polygonise → 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": 0.95,
   "__bib": "bourkepolygonising"
  }
 ],
 "presets": [
  {
   "id": "marching-cubes-specimen",
   "title": "Toy 2D marching squares: corner signs, cases and interpolated crossings",
   "runtime": "glsl-fragment",
   "params": {
    "CELLS": 10
   },
   "code": "// Toy 2D analogue (marching squares): corner signs pick a case per cell, edge crossings are linearly interpolated.\nconst float CELLS = 10.0;\nfloat field(vec2 p) {\n    vec2 a = vec2(0.36 + 0.06 * sin(iTime), 0.5), b = vec2(0.64, 0.5 + 0.1 * cos(iTime));\n    return 0.018 / dot(p - a, p - a) + 0.014 / dot(p - b, p - b) - 1.0;\n}\nfloat segd(vec2 p, vec2 a, vec2 b) {\n    vec2 pa = p - a, ba = b - a;\n    return length(pa - ba * clamp(dot(pa, ba) / max(dot(ba, ba), 1e-6), 0.0, 1.0));\n}\nvec2 xing(vec2 p0, vec2 p1, float f0, float f1) { return mix(p0, p1, f0 / (f0 - f1)); }\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n    vec2 uv = fragCoord / iResolution.xy;\n    float cs = 1.0 / CELLS;\n    vec2 c0 = floor(uv / cs) * cs;\n    vec2 P[4]; float F[4];\n    P[0] = c0; P[1] = c0 + vec2(cs, 0); P[2] = c0 + cs; P[3] = c0 + vec2(0, cs);\n    for (int i = 0; i < 4; i++) F[i] = field(P[i]);\n    float d = 1e9;\n    vec2 pts[4]; int n = 0;\n    for (int i = 0; i < 4; i++) {\n        int j = (i + 1) % 4;\n        if ((F[i] > 0.0) != (F[j] > 0.0)) { pts[n] = xing(P[i], P[j], F[i], F[j]); n++; }\n    }\n    if (n == 2) d = segd(uv, pts[0], pts[1]);\n    if (n == 4) d = min(segd(uv, pts[0], pts[1]), segd(uv, pts[2], pts[3]));\n    vec3 col = vec3(0.07, 0.08, 0.11);\n    float f = field(uv);\n    col += vec3(0.05, 0.08, 0.12) * (f > 0.0 ? 1.0 : 0.0);\n    vec2 g = abs(fract(uv / cs) - 0.5);\n    col = mix(col, vec3(0.2, 0.22, 0.3), smoothstep(0.015, 0.0, 0.5 - max(g.x, g.y)));\n    col = mix(col, vec3(1.0, 0.75, 0.25), smoothstep(0.004, 0.002, d));\n    for (int i = 0; i < 4; i++) {\n        float r = length(uv - P[i]);\n        col = mix(col, F[i] > 0.0 ? vec3(0.3, 0.9, 0.5) : vec3(0.4, 0.45, 0.55), smoothstep(0.011, 0.008, r));\n    }\n    // true contour for reference\n    col = mix(col, vec3(1.0, 0.3, 0.3), smoothstep(0.012, 0.0, abs(f)) * 0.0);\n    fragColor = vec4(pow(col, vec3(0.8)), 1.0);\n}\n",
   "basis": "original",
   "license_note": "written for this index",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-29",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "marching-cubes",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-29T15:51:50.471Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.1657,
      "std": 0.0949,
      "unique_colors": 81
     },
     "image": "/specimens/marching-cubes-specimen.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "dual-contouring",
  "surface-nets",
  "marching-tetrahedra",
  "manifold-dual-contouring"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "sdf-csg-smooth-min",
   "why": "The smooth-min SDF supplies the scalar field; marching cubes meshes it."
  },
  {
   "id": "taubin-smoothing",
   "why": "Taubin smoothing relaxes the stair-stepped output without shrinking it."
  },
  {
   "id": "qem-mesh-simplification",
   "why": "Simplify the dense triangle soup the grid produces."
  }
 ],
 "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/marching-cubes.json"
 },
 "solves": [
  "convert voxel or density field to a mesh",
  "extract surface from scalar volume or metaballs",
  "make terrain with caves and overhangs",
  "visualize medical scan volume as a surface"
 ],
 "authority": "Lorensen & Cline, 1987",
 "url": "https://texelatlas.vercel.app/t/marching-cubes/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 3.74,
  "tier": "light",
  "p50_ms": 0.123,
  "p95_ms": 0.1269,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "marching-cubes-specimen",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 3.32,
   "tier": "light",
   "p50_ms": 0.0528,
   "p95_ms": 0.0531,
   "speedup_x": 2.33,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 2.33,
   "tier": "light",
   "p50_ms": 0.067,
   "p95_ms": 0.0673,
   "speedup_x": 1.84,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}