Marching Cubes
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.
Also known as MC
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 | Official add-on | import { MarchingCubes } from 'three/addons/objects/MarchingCubes.js' docs |
| Babylon.js 9.38.0 | None found | |
| Godot 4.7 | None found | |
| Unity | None found | |
| Unreal 5.7 | Built in | Modeling Mode > Voxel tools (VoxelMerge / VoxelBlend / Solidify) and Geometry Script Solidify (GeometryScriptSolidifyOptions) docs |
| Blender 5.2 | Built in | Geometry Nodes > Volume > Grid to Mesh (or Volume to Mesh) docs Isosurface extraction; the manual calls it similar to Marching Cubes. |
| WebGPU W3C | None found | |
| Metal | None found |
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 choose it
Reach for it when
- 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
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.
Field marks
- 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
Presets
Toy 2D marching squares: corner signs, cases and interpolated crossings
{
"CELLS": 10
}Show GLSL (41 lines)
// Toy 2D analogue (marching squares): corner signs pick a case per cell, edge crossings are linearly interpolated.
const float CELLS = 10.0;
float field(vec2 p) {
vec2 a = vec2(0.36 + 0.06 * sin(iTime), 0.5), b = vec2(0.64, 0.5 + 0.1 * cos(iTime));
return 0.018 / dot(p - a, p - a) + 0.014 / dot(p - b, p - b) - 1.0;
}
float segd(vec2 p, vec2 a, vec2 b) {
vec2 pa = p - a, ba = b - a;
return length(pa - ba * clamp(dot(pa, ba) / max(dot(ba, ba), 1e-6), 0.0, 1.0));
}
vec2 xing(vec2 p0, vec2 p1, float f0, float f1) { return mix(p0, p1, f0 / (f0 - f1)); }
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = fragCoord / iResolution.xy;
float cs = 1.0 / CELLS;
vec2 c0 = floor(uv / cs) * cs;
vec2 P[4]; float F[4];
P[0] = c0; P[1] = c0 + vec2(cs, 0); P[2] = c0 + cs; P[3] = c0 + vec2(0, cs);
for (int i = 0; i < 4; i++) F[i] = field(P[i]);
float d = 1e9;
vec2 pts[4]; int n = 0;
for (int i = 0; i < 4; i++) {
int j = (i + 1) % 4;
if ((F[i] > 0.0) != (F[j] > 0.0)) { pts[n] = xing(P[i], P[j], F[i], F[j]); n++; }
}
if (n == 2) d = segd(uv, pts[0], pts[1]);
if (n == 4) d = min(segd(uv, pts[0], pts[1]), segd(uv, pts[2], pts[3]));
vec3 col = vec3(0.07, 0.08, 0.11);
float f = field(uv);
col += vec3(0.05, 0.08, 0.12) * (f > 0.0 ? 1.0 : 0.0);
vec2 g = abs(fract(uv / cs) - 0.5);
col = mix(col, vec3(0.2, 0.22, 0.3), smoothstep(0.015, 0.0, 0.5 - max(g.x, g.y)));
col = mix(col, vec3(1.0, 0.75, 0.25), smoothstep(0.004, 0.002, d));
for (int i = 0; i < 4; i++) {
float r = length(uv - P[i]);
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));
}
// true contour for reference
col = mix(col, vec3(1.0, 0.3, 0.3), smoothstep(0.012, 0.0, abs(f)) * 0.0);
fragColor = vec4(pow(col, vec3(0.8)), 1.0);
}
Attribution: written for this index
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| marching-cubes-specimen | Tesla T4 1920x1080 | 3.74× baseline (light) · 0.123 ms / 0.127 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| marching-cubes-specimen | NVIDIA L4 1920x1080 | 3.32× baseline (light) · 0.053 ms / 0.053 ms · 2.3× faster on L4 | opengl-timer-query · Cross-architecture validation |
| marching-cubes-specimen | NVIDIA A100-SXM4-40GB 1920x1080 | 2.33× baseline (light) · 0.067 ms / 0.067 ms · 1.8× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): its primary source cites Sweet-Spot Anamorphic Geometry & Sutherland-Hodgman Sightline Clipping; cited by Deferred shading (G-buffer), Kinematic Swept-Volume Boolean Carving via 2D Slab Distance Fields, Infinigen (Procedural Photorealistic Worlds), Ligne-claire / Moebius-style shading, Manifold Dual Contouring, Depth/normal Sobel edge outlines, Screen-space fluid rendering (curvature flow).
Crosses
- SDF Modeling: CSG and Smooth Minimum: The smooth-min SDF supplies the scalar field; marching cubes meshes it.
- Taubin Smoothing: Taubin smoothing relaxes the stair-stepped output without shrinking it.
- Quadric Error Metric Simplification: Simplify the dense triangle soup the grid produces.
Sources
- primaryWilliam E. Lorensen, Harvey E. Cline (1987). Marching cubes: A high resolution 3D surface construction algorithm. ACM SIGGRAPH Computer Graphics.Verified via crossref · 2026-11-29doi:10.1145/37402.37422
- implementationmikolalysenko (2013). mikolalysenko/isosurface. Isosurface polygonizer algorithmsGitHub API · license MIT · 2026-11-29
- implementationmrdoob (2010). mrdoob/three.js. JavaScript 3D Library.GitHub API · license MIT · 2026-11-29
- tutorialPaul Bourke. Polygonising a scalar field. paulbourke.net.Verified via live page · 2026-11-29