{
 "id": "qem-mesh-simplification",
 "title": "Quadric Error Metric Simplification",
 "aliases": [
  "QEM",
  "quadric simplification",
  "Mesh Simplification",
  "Mesh Decimation",
  "Polygon Reduction"
 ],
 "domain": "geometry",
 "subdomain": "mesh simplification",
 "stage": "geometry",
 "realtime": "interactive",
 "platforms": [
  "cpu",
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "blender",
  "unity",
  "unreal"
 ],
 "year_introduced": 1997,
 "inputs": [
  "mesh"
 ],
 "outputs": [
  "mesh"
 ],
 "style": "both",
 "dynamic": "static",
 "summary": "Collapses mesh edges greedily, always choosing the cheapest collapse measured by a sum of squared distances to the planes of the original surrounding faces. A fast, general-purpose way to cut triangle counts while keeping shape.",
 "how_it_works": "Attach to each vertex a 4x4 symmetric quadric: the sum of outer products of the plane equations of the faces around it. The error of placing a vertex at v is vᵀQv. For each candidate edge, merge the two quadrics, solve for the optimal position (or fall back to an endpoint or midpoint if the system is singular), and push the edge into a priority queue by cost. Repeatedly pop the cheapest edge, collapse it, update neighbouring costs and continue until the target triangle count is reached. Practical versions add rules to avoid triangle flips, preserve boundaries via extra penalty planes, weight by area and carry UVs or attributes in extended quadrics.",
 "when_to_use": "Choose it for automatic LODs, cleaning dense scans or marching-cubes output and shrinking assets for the web. Prefer `isotropic-remeshing` when you need uniform triangle sizes rather than minimal count, `instant-meshes` or `quadriflow` for clean quad topology, and hand-authored LODs where silhouettes or animation deformation must be controlled.",
 "cost": {
  "class": "offline",
  "notes": "Near O(n log n) with a priority queue; millions of triangles take seconds on CPU. Not a per-frame operation."
 },
 "failure_modes": [
  "UV seams, skin weights and normals tear or distort unless attributes are included in the metric",
  "Flipped or overlapping triangles when a collapse moves a vertex across its ring",
  "Boundary and thin-shell collapse: open edges shrink or holes grow",
  "Topology can change unexpectedly (non-manifold results) without explicit checks",
  "Uneven triangle shapes: it optimises error, not triangle quality"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/258734.258849",
   "type": "paper",
   "title": "Surface simplification using quadric error metrics",
   "authors": [
    "Michael Garland",
    "Paul S. Heckbert"
   ],
   "year": 1997,
   "venue": "Proceedings of the 24th annual conference on Computer graphics and interactive techniques  - SIGGRAPH '97",
   "url": "https://doi.org/10.1145/258734.258849",
   "ids": {
    "doi": "10.1145/258734.258849"
   },
   "license": null,
   "extra": {
    "csl_type": "proceedings-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/258734.258849",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/258734.258849",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/258734.258849",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/258734.258849",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/258734.258849",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "garland1997surface"
  },
  {
   "role": "implementation",
   "key": "gh:zeux/meshoptimizer",
   "type": "code",
   "title": "zeux/meshoptimizer",
   "description": "Mesh optimization library that makes meshes smaller and faster to render",
   "authors": [
    "zeux"
   ],
   "year": 2016,
   "venue": "GitHub",
   "url": "https://github.com/zeux/meshoptimizer",
   "ids": {
    "repo": "zeux/meshoptimizer"
   },
   "license": "MIT",
   "extra": {
    "stars": 8972,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-11-29T00:55:16Z",
    "language": "C++",
    "homepage": "https://meshoptimizer.org/",
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/zeux/meshoptimizer",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/zeux/meshoptimizer",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/zeux/meshoptimizer",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/zeux/meshoptimizer",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/zeux/meshoptimizer",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/zeux/meshoptimizer",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "zeux2016zeux"
  },
  {
   "role": "implementation",
   "key": "gh:sp4cerat/fast-quadric-mesh-simplification",
   "type": "code",
   "title": "sp4cerat/Fast-Quadric-Mesh-Simplification",
   "description": "Mesh triangle reduction using quadrics",
   "authors": [
    "sp4cerat"
   ],
   "year": 2015,
   "venue": "GitHub",
   "url": "https://github.com/sp4cerat/Fast-Quadric-Mesh-Simplification",
   "ids": {
    "repo": "sp4cerat/Fast-Quadric-Mesh-Simplification"
   },
   "license": "MIT",
   "extra": {
    "stars": 1779,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2024-07-28T15:58:10Z",
    "language": "C",
    "homepage": null,
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/sp4cerat/Fast-Quadric-Mesh-Simplification",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/sp4cerat/Fast-Quadric-Mesh-Simplification",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/sp4cerat/Fast-Quadric-Mesh-Simplification",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/sp4cerat/Fast-Quadric-Mesh-Simplification",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/sp4cerat/Fast-Quadric-Mesh-Simplification",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/sp4cerat/Fast-Quadric-Mesh-Simplification",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "spcerat2015sp4cerat"
  },
  {
   "role": "tutorial",
   "key": "url:https://www.cs.cmu.edu/~./garland/quadrics/qslim.html",
   "type": "tutorial",
   "title": "QSlim",
   "authors": [
    "Michael Garland"
   ],
   "year": null,
   "venue": "cs.cmu.edu",
   "url": "https://www.cs.cmu.edu/~garland/quadrics/qslim.html",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20260911034942/https://www.cs.cmu.edu/~garland/quadrics/qslim.html",
     "timestamp": "20260911034942"
    },
    "page_title": "QSlim Simplification Software",
    "host": "cs.cmu.edu",
    "title_confirmed_by_page": false,
    "title_unconfirmed": true
   },
   "provenance": {
    "title": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://www.cs.cmu.edu/~./garland/quadrics/qslim.html → 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.cs.cmu.edu/~./garland/quadrics/qslim.html → 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.5,
   "__bib": "garlandqslim"
  }
 ],
 "presets": [
  {
   "id": "qem-mesh-simplification-live",
   "title": "Quadric Error Metric Simplification — smooth high-poly reference (left) vs QEF edge-collapsed facets & error map (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_DECIMATION": 0.62,
    "P_ERROR_HEAT": 0.55,
    "P_WIRE_ALPHA": 0.85,
    "P_SPLIT": 0.44
   },
   "basis": "original",
   "license_note": "Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).",
   "code": "const float P_DECIMATION = 0.62; // P Decimation Ratio [0.1, 1.0, 0.02]\nconst float P_ERROR_HEAT = 0.55; // P Quadric Error Map [0.0, 1.0, 0.02]\nconst float P_WIRE_ALPHA = 0.85; // P Mesh Wireframe [0.0, 1.5, 0.05]\nconst float P_SPLIT = 0.44; // P Hi-Poly / QEM Split [0.0, 1.0, 0.02]\n\nmat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }\n\n// Sculpted multi-lobed organic polyhedron with both smooth basins and sharp ridges (ideal QEM test!)\nfloat mapSculpt(vec3 p, float spin) {\n  vec3 q = p;\n  q.xz = rot2(spin * 0.35) * q.xz;\n  q.yz = rot2(0.28) * q.yz;\n  float r = length(q);\n  vec3 d = q / max(r, 1e-4);\n  float lobes = 0.14 * sin(d.x * 5.0) * cos(d.y * 5.0) + 0.09 * cos(d.z * 6.0 + d.x * 3.0);\n  float ridge = 0.045 * abs(sin(atan(d.z, d.x) * 4.0));\n  return (r - (0.78 + lobes + ridge)) * 0.78;\n}\n\nvec3 calcNormal(vec3 p, float spin) {\n  vec2 e = vec2(0.0025, 0.0);\n  return normalize(vec3(\n    mapSculpt(p + e.xyy, spin) - mapSculpt(p - e.xyy, spin),\n    mapSculpt(p + e.yxy, spin) - mapSculpt(p - e.yxy, spin),\n    mapSculpt(p + e.yyx, spin) - mapSculpt(p - e.yyx, spin)\n  ));\n}\n\n// Compute triangle-grid facet center, flat quantized normal, edge distance, and local quadric error\nvoid evalQemFacet(vec3 objP, vec3 smoothN, float freq, out vec3 flatN, out float edgeDist, out float qemErr) {\n  // Spherical octahedral-like parameterization to form uniform triangle facets on the 3D surface\n  vec3 d = normalize(objP + vec3(1e-5));\n  vec2 sp = vec2(atan(d.z, d.x) / 3.14159265, asin(clamp(d.y, -0.999, 0.999)) / 1.5707963);\n  vec2 g = sp * vec2(freq * 1.8, freq);\n  vec2 cell = floor(g);\n  vec2 f = fract(g);\n  float upper = step(f.x, f.y);\n  vec3 bary = (upper > 0.5) ? vec3(1.0 - f.y, f.x, f.y - f.x) : vec3(1.0 - f.x, f.y, f.x - f.y);\n  edgeDist = min(bary.x, min(bary.y, bary.z));\n\n  // Centroid of the collapsed QEM triangle on the unit sphere\n  vec2 cUV = (cell + ((upper > 0.5) ? vec2(0.33, 0.67) : vec2(0.67, 0.33))) / vec2(freq * 1.8, freq);\n  float lon = cUV.x * 3.14159265;\n  float lat = clamp(cUV.y * 1.5707963, -1.55, 1.55);\n  vec3 cDir = vec3(cos(lat) * cos(lon), sin(lat), cos(lat) * sin(lon));\n\n  // Approximate face normal & quadric error v^T Q v = (n_smooth . (v - v_plane))^2\n  flatN = normalize(mix(cDir, smoothN, 0.25));\n  qemErr = clamp((1.0 - dot(smoothN, flatN)) * 12.0, 0.0, 1.0);\n}\n\nvec3 errPalette(float x) {\n  x = clamp(x, 0.0, 1.0);\n  vec3 c0 = vec3(0.10, 0.32, 0.64);\n  vec3 c1 = vec3(0.16, 0.84, 0.66);\n  vec3 c2 = vec3(0.98, 0.72, 0.18);\n  vec3 c3 = vec3(0.98, 0.22, 0.34);\n  if (x < 0.35) return mix(c0, c1, x / 0.35);\n  if (x < 0.72) return mix(c1, c2, (x - 0.35) / 0.37);\n  return mix(c2, c3, (x - 0.72) / 0.28);\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 decim = clamp(P_DECIMATION, 0.05, 1.0);\n  float heatMix = clamp(P_ERROR_HEAT, 0.0, 1.0);\n  float wireVis = clamp(P_WIRE_ALPHA, 0.0, 1.5);\n  float spin = iTime;\n\n  vec3 ro = vec3(0.0, 0.06, 2.45);\n  vec3 rd = normalize(vec3(uv, -1.52));\n\n  vec3 col = mix(vec3(0.032, 0.042, 0.068), vec3(0.092, 0.116, 0.168), smoothstep(-0.55, 0.55, uv.y));\n  vec2 bgG = abs(fract(uv * 10.0 - 0.5) - 0.5);\n  col += vec3(0.018, 0.028, 0.045) * smoothstep(0.03, 0.0, min(bgG.x, bgG.y));\n\n  float t = 0.0;\n  bool hit = false;\n  for (int i = 0; i < 64; i++) {\n    float d = mapSculpt(ro + rd * t, spin);\n    if (d < 0.002) { hit = true; break; }\n    t += d;\n    if (t > 9.0) break;\n  }\n\n  if (hit) {\n    vec3 p = ro + rd * t;\n    vec3 nSmooth = calcNormal(p, spin);\n\n    vec3 objP = p;\n    objP.xz = rot2(spin * 0.35) * objP.xz;\n    objP.yz = rot2(0.28) * objP.yz;\n    vec3 objN = nSmooth;\n    objN.xz = rot2(spin * 0.35) * objN.xz;\n    objN.yz = rot2(0.28) * objN.yz;\n\n    // Left: dense reference mesh (freq = 18); Right: QEM simplified mesh (freq drops with P_DECIMATION)\n    bool isQem = screenX >= split;\n    float triFreq = isQem ? mix(13.0, 3.8, decim) : 18.0;\n\n    vec3 flatObjN;\n    float edgeD;\n    float qemErr;\n    evalQemFacet(objP, objN, triFreq, flatObjN, edgeD, qemErr);\n\n    // Transform faceted normal back to world space for authentic flat-shaded decimated lighting\n    vec3 nFlat = flatObjN;\n    nFlat.yz = rot2(-0.28) * nFlat.yz;\n    nFlat.xz = rot2(-spin * 0.35) * nFlat.xz;\n    vec3 nShade = isQem ? normalize(mix(nSmooth, nFlat, 0.82)) : nSmooth;\n\n    vec3 l1 = normalize(vec3(0.62, 0.85, 0.55));\n    vec3 l2 = normalize(vec3(-0.72, -0.20, 0.52));\n    float diff1 = max(dot(nShade, l1), 0.0);\n    float diff2 = max(dot(nShade, l2), 0.0);\n    vec3 hVec = normalize(l1 - rd);\n    float spec = pow(max(dot(nShade, hVec), 0.0), 36.0) * 0.45;\n    float rim = pow(1.0 - max(dot(nSmooth, -rd), 0.0), 3.0) * 0.28;\n\n    vec3 clayAlb = vec3(0.76, 0.74, 0.72);\n    vec3 qemAlb = mix(vec3(0.72, 0.75, 0.80), errPalette(qemErr * 1.45), heatMix);\n    vec3 alb = isQem ? qemAlb : clayAlb;\n\n    col = alb * (0.26 + 0.84 * diff1 + 0.24 * diff2) + vec3(spec) + vec3(0.45, 0.72, 1.0) * rim;\n    float wire = smoothstep(0.065, 0.012, edgeD);\n    vec3 wireCol = isQem ? vec3(0.06, 0.08, 0.12) : vec3(0.22, 0.30, 0.42);\n    col = mix(col, wireCol, wire * (isQem ? 0.72 : 0.28) * min(wireVis, 1.2));\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": "qem-mesh-simplification",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:04:36.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.7607,
      "std": 0.1378,
      "min": 0.2136,
      "max": 0.9219
     },
     "image": "/specimens/qem-mesh-simplification-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "isotropic-remeshing",
  "instant-meshes",
  "loop-subdivision"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "marching-cubes",
   "why": "Collapse the dense uniform mesh into an adaptive one."
  },
  {
   "id": "geometry-images",
   "why": "Remesh/simplify before parametrization to keep atlas sizes sane."
  }
 ],
 "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/qem-mesh-simplification.json"
 },
 "solves": [
  "mesh has too many polygons for realtime",
  "decimate model while keeping its shape",
  "generate lod chain from a high poly asset",
  "reduce triangles but preserve silhouette and features"
 ],
 "authority": "Garland & Heckbert, 1997",
 "url": "https://texelatlas.vercel.app/t/qem-mesh-simplification/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 25.84,
  "tier": "heavy",
  "p50_ms": 0.8113,
  "p95_ms": 0.8766,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "qem-mesh-simplification-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 21.07,
   "tier": "heavy",
   "p50_ms": 0.3329,
   "p95_ms": 0.3486,
   "speedup_x": 2.44,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 15.44,
   "tier": "moderate",
   "p50_ms": 0.4447,
   "p95_ms": 0.4729,
   "speedup_x": 1.82,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}