{
 "id": "mesh-shaders",
 "title": "Mesh shaders",
 "aliases": [
  "task shaders",
  "amplification shaders"
 ],
 "domain": "performance",
 "subdomain": "pipeline stages",
 "stage": "performance",
 "realtime": "realtime",
 "platforms": [
  "desktop-gpu",
  "webgpu"
 ],
 "year_introduced": 2018,
 "inputs": [
  "mesh"
 ],
 "outputs": [
  "gbuffer",
  "depth"
 ],
 "style": "both",
 "dynamic": "both",
 "summary": "A compute-style geometry pipeline where task and mesh stages replace input assembly and vertex processing, letting each workgroup emit its own small batch of primitives after culling.",
 "how_it_works": "A task (amplification) shader runs one thread per candidate meshlet, performs frustum, cone and occlusion tests, and launches mesh workgroups only for visible ones. Each mesh shader workgroup loads its meshlet's vertices and micro indices from buffers, transforms them cooperatively, and writes vertex and primitive outputs straight to the rasterizer, bypassing fixed-function index fetch.\n\nThe model removes the vertex cache dependency and lets the shader generate geometry procedurally or decompress it on the fly. Output limits per workgroup are small, so meshlets are built to fit them.",
 "when_to_use": "Choose it on hardware with native support when you already have `meshlets` and want per-cluster culling without a separate compute pass. Prefer classic indirect draws from `gpu-driven-rendering` on older GPUs or WebGL2, or where the extension is missing. Prefer `nanite-virtualized-geometry` style software raster for triangles smaller than a pixel.",
 "cost": {
  "class": "medium",
  "notes": "Often faster than the vertex pipeline for dense meshes, but results depend on vendor, meshlet size and output count; no numbers asserted."
 },
 "failure_modes": [
  "Not portable: unavailable on older GPUs and absent from WebGL2",
  "Wrong meshlet sizing underutilizes a vendor's hardware",
  "Debugging and tooling support is weaker than for vertex pipelines",
  "Tiny triangles still rasterize inefficiently in hardware"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://developer.nvidia.com/blog/introduction-turing-mesh-shaders",
   "type": "web",
   "title": "Introduction to Turing Mesh Shaders",
   "authors": [
    "Christoph Kubisch"
   ],
   "year": null,
   "venue": "developer.nvidia.com",
   "url": "https://developer.nvidia.com/blog/introduction-turing-mesh-shaders",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261105084756/https://developer.nvidia.com/blog/introduction-turing-mesh-shaders/",
     "timestamp": "20261105084756"
    },
    "page_title": "Introduction to Turing Mesh Shaders | NVIDIA Technical Blog",
    "host": "developer.nvidia.com",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://developer.nvidia.com/blog/introduction-turing-mesh-shaders → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://developer.nvidia.com/blog/introduction-turing-mesh-shaders → 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://developer.nvidia.com/blog/introduction-turing-mesh-shaders → 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": "kubischintroduction"
  },
  {
   "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"
  }
 ],
 "presets": [
  {
   "id": "mesh-shaders-live",
   "title": "Mesh Shaders — meshlet clusters & normal-cone backface culling (left) vs shaded mesh (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_CLUSTER_DENS": 4.5,
    "P_CONE_THRESH": 0.22,
    "P_ROT_SPEED": 0.8,
    "P_SPLIT": 0.5
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_CLUSTER_DENS = 4.5; // P Meshlet Density [2.5, 8.0, 0.25]\nconst float P_CONE_THRESH = 0.22; // P Cone Cull Bias [0.0, 0.65, 0.02]\nconst float P_ROT_SPEED = 0.80; // P Spin Speed [0.0, 2.2, 0.05]\nconst float P_SPLIT = 0.50; // P Meshlets / Lit 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\nvec3 hash33(vec3 p) {\n  p = fract(p * vec3(0.1031, 0.1030, 0.0973));\n  p += dot(p, p.yxz + 33.33);\n  return fract((p.xxy + p.yxx) * p.zyx);\n}\n\n// Sculpted high-detail organic torus + grooved core showcasing dense triangle meshlets\nfloat mapMesh(vec3 p, float spin) {\n  vec3 q = p;\n  q.xz = rot2(spin * 0.65) * q.xz;\n  q.xy = rot2(spin * 0.35 + 0.35) * q.xy;\n  vec2 t = vec2(length(q.xz) - 0.56, q.y);\n  float dTor = length(t) - 0.26 - 0.035 * sin(atan(q.z, q.x) * 6.0 + atan(q.y, t.x) * 3.0);\n  float dCore = length(q) - 0.34;\n  return min(dTor, dCore);\n}\n\nvec3 calcNormal(vec3 p, float spin) {\n  vec2 e = vec2(0.0022, 0.0);\n  return normalize(vec3(\n    mapMesh(p + e.xyy, spin) - mapMesh(p - e.xyy, spin),\n    mapMesh(p + e.yxy, spin) - mapMesh(p - e.yxy, spin),\n    mapMesh(p + e.yyx, spin) - mapMesh(p - e.yyx, spin)\n  ));\n}\n\n// 3D Voronoi meshlet partition in object space returning (borderDist, cellID)\nvec4 evalMeshlet(vec3 objP, float dens) {\n  vec3 gp = objP * dens;\n  vec3 cell = floor(gp);\n  vec3 f = fract(gp);\n  float d1 = 1e5;\n  float d2 = 1e5;\n  vec3 bestId = vec3(0.0);\n  vec3 bestCenter = vec3(0.0);\n  for (int dz = -1; dz <= 1; dz++) {\n    for (int dy = -1; dy <= 1; dy++) {\n      for (int dx = -1; dx <= 1; dx++) {\n        vec3 nb = vec3(float(dx), float(dy), float(dz));\n        vec3 cid = cell + nb;\n        vec3 rnd = hash33(cid);\n        vec3 pt = nb + 0.15 + 0.70 * rnd;\n        float d = length(f - pt);\n        if (d < d1) {\n          d2 = d1;\n          d1 = d;\n          bestId = cid;\n          bestCenter = (cid + 0.15 + 0.70 * rnd) / dens;\n        } else if (d < d2) {\n          d2 = d;\n        }\n      }\n    }\n  }\n  return vec4(d2 - d1, bestId);\n}\n\nvec3 meshletPalette(vec3 id) {\n  vec3 h = hash33(id + 7.13);\n  float ang = h.x * 6.2831853;\n  return 0.52 + 0.42 * cos(ang + vec3(0.0, 2.094, 4.188));\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  bool isLit = screenX >= split;\n  float dens = clamp(P_CLUSTER_DENS, 2.0, 9.0);\n  float coneBias = clamp(P_CONE_THRESH, 0.0, 0.70);\n  float spin = iTime * max(P_ROT_SPEED, 0.0);\n\n  vec3 ro = vec3(0.0, 0.04, 2.38);\n  vec3 rd = normalize(vec3(uv, -1.55));\n\n  vec3 col = mix(vec3(0.026, 0.036, 0.058), vec3(0.068, 0.088, 0.135), smoothstep(-0.55, 0.55, uv.y));\n\n  float t = 0.0;\n  bool hit = false;\n  for (int i = 0; i < 64; i++) {\n    float d = mapMesh(ro + rd * t, spin);\n    if (d < 0.002) { hit = true; break; }\n    t += d * 0.85;\n    if (t > 7.0) break;\n  }\n\n  if (hit) {\n    vec3 p = ro + rd * t;\n    vec3 n = calcNormal(p, spin);\n\n    // Transform hit point back to object space so meshlets stick rigidly to the mesh\n    vec3 objP = p;\n    objP.xz = rot2(spin * 0.65) * objP.xz;\n    objP.xy = rot2(spin * 0.35 + 0.35) * objP.xy;\n\n    vec4 mInfo = evalMeshlet(objP, dens);\n    float seam = smoothstep(0.065, 0.014, mInfo.x);\n    vec3 mCol = meshletPalette(mInfo.yzw);\n\n    // Sub-meshlet triangle wireframe (64-tri cluster tessellation pattern)\n    vec3 tf = abs(fract(objP * dens * 4.5 - 0.5) - 0.5);\n    float triWire = smoothstep(0.055, 0.012, min(min(tf.x, tf.y), tf.z));\n\n    // Task-shader normal-cone backface culling test: dot(viewDir, coneAxis) < sin(coneAngle)\n    float ndv = max(dot(n, -rd), 0.0);\n    float nearSilhouette = smoothstep(coneBias + 0.12, coneBias, ndv);\n\n    vec3 l1 = normalize(vec3(0.58, 0.82, 0.55));\n    vec3 l2 = normalize(vec3(-0.70, -0.25, 0.45));\n    float diff = max(dot(n, l1), 0.0) * 0.85 + max(dot(n, l2), 0.0) * 0.25;\n    float spec = pow(max(dot(n, normalize(l1 - rd)), 0.0), 48.0);\n\n    if (!isLit) {\n      // Left: Task/Mesh shader cluster view showing color-coded 64-tri meshlets & grazing cone-cull margin\n      col = mCol * (0.34 + 0.76 * diff) + vec3(0.85) * spec * 0.25;\n      col = mix(col, vec3(0.04, 0.06, 0.10), triWire * 0.28);\n      col = mix(col, vec3(0.96, 0.98, 1.0), seam * 0.85);\n      // Tint grazing meshlets approaching the backface-cone culling horizon in bright crimson\n      col = mix(col, vec3(0.98, 0.20, 0.24), nearSilhouette * 0.65);\n    } else {\n      // Right: Final lit brushed alloy surface with subtle meshlet boundary gleam\n      vec3 alloy = vec3(0.68, 0.74, 0.82);\n      col = alloy * (0.22 + 0.88 * diff) + vec3(0.98, 0.94, 0.88) * spec * 0.65;\n      col += mCol * seam * 0.16;\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": "mesh-shaders",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:53:31.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.5454,
      "std": 0.2299,
      "min": 0.1895,
      "max": 0.9331
     },
     "image": "/specimens/mesh-shaders-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "meshlets",
  "gpu-driven-rendering",
  "nanite-virtualized-geometry"
 ],
 "extends": [
  "meshlets"
 ],
 "supersedes": [],
 "combines_with": [
  {
   "id": "meshlets",
   "why": "Meshlet buffers with bounds and micro indices are what task and mesh stages read."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/performance/mesh-shaders.json"
 },
 "solves": [
  "vertex pipeline wastes work on culled geometry",
  "want per-cluster culling inside the draw",
  "huge meshlet scenes need flexible geometry stage",
  "replace input assembly for gpu-driven geometry"
 ],
 "authority": "Kubisch",
 "url": "https://texelatlas.vercel.app/t/mesh-shaders/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 39.43,
  "tier": "heavy",
  "p50_ms": 1.2222,
  "p95_ms": 1.2708,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 36,
  "preset_id": "mesh-shaders-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 31.15,
   "tier": "heavy",
   "p50_ms": 0.4953,
   "p95_ms": 0.5121,
   "speedup_x": 2.47,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 22.9,
   "tier": "heavy",
   "p50_ms": 0.6594,
   "p95_ms": 0.687,
   "speedup_x": 1.85,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}