---
id: "mesh-shaders"
title: "Mesh shaders"
aliases: [task shaders, amplification shaders]
domain: "performance"
stage: "performance"
realtime: "realtime"
platforms: [desktop-gpu, webgpu]
year_introduced: 2018
inputs: [mesh]
outputs: [gbuffer, depth]
style: "both"
dynamic: "both"
cost: "medium"
authority: "Kubisch"
url: "https://texelatlas.vercel.app/t/mesh-shaders/"
sources_verified_at: "2026-11-29"
---
# Mesh shaders (Kubisch)

> 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.

## Reach for it when

- 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

## 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.

The 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 it

Choose it on hardware with native support when you already have [Meshlets (cluster rendering)](https://texelatlas.vercel.app/t/meshlets.md) and want per-cluster culling without a separate compute pass. Prefer classic indirect draws from [GPU-driven rendering](https://texelatlas.vercel.app/t/gpu-driven-rendering.md) on older GPUs or WebGL2, or where the extension is missing. Prefer [Nanite virtualized geometry](https://texelatlas.vercel.app/t/nanite-virtualized-geometry.md) style software raster for triangles smaller than a pixel.

## Cost

medium — Often faster than the vertex pipeline for dense meshes, but results depend on vendor, meshlet size and output count; no numbers asserted.
Measured GPU Weight: 39.43× baseline (heavy) — 1.2222 ms median / 1.2708 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 31.15× baseline (heavy) — 0.4953 ms median (2.47× faster on L4).
Ampere A100 scaling: 22.9× baseline (heavy) — 0.6594 ms median (1.85× faster on A100).

## 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

## Engine support

- metal: builtin — `MTLMeshRenderPipelineDescriptor (objectFunction, meshFunction)` (evidence: https://developer.apple.com/tutorials/data/documentation/metal/mtlmeshrenderpipelinedescriptor.json, checked 2026-12-01)
- unreal: builtin — `Nanite virtualized meshlet rasterizer & RHI mesh shader pipeline` (evidence: https://dev.epicgames.com/documentation/en-us/unreal-engine/nanite-virtualized-geometry-in-unreal-engine, checked 2026-12-01)

## Dataflow

- Inputs: mesh
- Outputs: gbuffer, depth
- Platforms: desktop-gpu, webgpu

## Presets

### Mesh Shaders — meshlet clusters & normal-cone backface culling (left) vs shaded mesh (right) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_CLUSTER_DENS": 4.5,
  "P_CONE_THRESH": 0.22,
  "P_ROT_SPEED": 0.8,
  "P_SPLIT": 0.5
}
```

```glsl
const float P_CLUSTER_DENS = 4.5; // P Meshlet Density [2.5, 8.0, 0.25]
const float P_CONE_THRESH = 0.22; // P Cone Cull Bias [0.0, 0.65, 0.02]
const float P_ROT_SPEED = 0.80; // P Spin Speed [0.0, 2.2, 0.05]
const float P_SPLIT = 0.50; // P Meshlets / Lit Split [0.0, 1.0, 0.02]

mat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }

vec3 hash33(vec3 p) {
  p = fract(p * vec3(0.1031, 0.1030, 0.0973));
  p += dot(p, p.yxz + 33.33);
  return fract((p.xxy + p.yxx) * p.zyx);
}

// Sculpted high-detail organic torus + grooved core showcasing dense triangle meshlets
float mapMesh(vec3 p, float spin) {
  vec3 q = p;
  q.xz = rot2(spin * 0.65) * q.xz;
  q.xy = rot2(spin * 0.35 + 0.35) * q.xy;
  vec2 t = vec2(length(q.xz) - 0.56, q.y);
  float dTor = length(t) - 0.26 - 0.035 * sin(atan(q.z, q.x) * 6.0 + atan(q.y, t.x) * 3.0);
  float dCore = length(q) - 0.34;
  return min(dTor, dCore);
}

vec3 calcNormal(vec3 p, float spin) {
  vec2 e = vec2(0.0022, 0.0);
  return normalize(vec3(
    mapMesh(p + e.xyy, spin) - mapMesh(p - e.xyy, spin),
    mapMesh(p + e.yxy, spin) - mapMesh(p - e.yxy, spin),
    mapMesh(p + e.yyx, spin) - mapMesh(p - e.yyx, spin)
  ));
}

// 3D Voronoi meshlet partition in object space returning (borderDist, cellID)
vec4 evalMeshlet(vec3 objP, float dens) {
  vec3 gp = objP * dens;
  vec3 cell = floor(gp);
  vec3 f = fract(gp);
  float d1 = 1e5;
  float d2 = 1e5;
  vec3 bestId = vec3(0.0);
  vec3 bestCenter = vec3(0.0);
  for (int dz = -1; dz <= 1; dz++) {
    for (int dy = -1; dy <= 1; dy++) {
      for (int dx = -1; dx <= 1; dx++) {
        vec3 nb = vec3(float(dx), float(dy), float(dz));
        vec3 cid = cell + nb;
        vec3 rnd = hash33(cid);
        vec3 pt = nb + 0.15 + 0.70 * rnd;
        float d = length(f - pt);
        if (d < d1) {
          d2 = d1;
          d1 = d;
          bestId = cid;
          bestCenter = (cid + 0.15 + 0.70 * rnd) / dens;
        } else if (d < d2) {
          d2 = d;
        }
      }
    }
  }
  return vec4(d2 - d1, bestId);
}

vec3 meshletPalette(vec3 id) {
  vec3 h = hash33(id + 7.13);
  float ang = h.x * 6.2831853;
  return 0.52 + 0.42 * cos(ang + vec3(0.0, 2.094, 4.188));
}

vec3 aces(vec3 x) {
  x = max(x, 0.0);
  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
  float screenX = fragCoord.x / max(iResolution.x, 1.0);
  float split = clamp(P_SPLIT, 0.0, 1.0);
  bool isLit = screenX >= split;
  float dens = clamp(P_CLUSTER_DENS, 2.0, 9.0);
  float coneBias = clamp(P_CONE_THRESH, 0.0, 0.70);
  float spin = iTime * max(P_ROT_SPEED, 0.0);

  vec3 ro = vec3(0.0, 0.04, 2.38);
  vec3 rd = normalize(vec3(uv, -1.55));

  vec3 col = mix(vec3(0.026, 0.036, 0.058), vec3(0.068, 0.088, 0.135), smoothstep(-0.55, 0.55, uv.y));

  float t = 0.0;
  bool hit = false;
  for (int i = 0; i < 64; i++) {
    float d = mapMesh(ro + rd * t, spin);
    if (d < 0.002) { hit = true; break; }
    t += d * 0.85;
    if (t > 7.0) break;
  }

  if (hit) {
    vec3 p = ro + rd * t;
    vec3 n = calcNormal(p, spin);

    // Transform hit point back to object space so meshlets stick rigidly to the mesh
    vec3 objP = p;
    objP.xz = rot2(spin * 0.65) * objP.xz;
    objP.xy = rot2(spin * 0.35 + 0.35) * objP.xy;

    vec4 mInfo = evalMeshlet(objP, dens);
    float seam = smoothstep(0.065, 0.014, mInfo.x);
    vec3 mCol = meshletPalette(mInfo.yzw);

    // Sub-meshlet triangle wireframe (64-tri cluster tessellation pattern)
    vec3 tf = abs(fract(objP * dens * 4.5 - 0.5) - 0.5);
    float triWire = smoothstep(0.055, 0.012, min(min(tf.x, tf.y), tf.z));

    // Task-shader normal-cone backface culling test: dot(viewDir, coneAxis) < sin(coneAngle)
    float ndv = max(dot(n, -rd), 0.0);
    float nearSilhouette = smoothstep(coneBias + 0.12, coneBias, ndv);

    vec3 l1 = normalize(vec3(0.58, 0.82, 0.55));
    vec3 l2 = normalize(vec3(-0.70, -0.25, 0.45));
    float diff = max(dot(n, l1), 0.0) * 0.85 + max(dot(n, l2), 0.0) * 0.25;
    float spec = pow(max(dot(n, normalize(l1 - rd)), 0.0), 48.0);

    if (!isLit) {
      // Left: Task/Mesh shader cluster view showing color-coded 64-tri meshlets & grazing cone-cull margin
      col = mCol * (0.34 + 0.76 * diff) + vec3(0.85) * spec * 0.25;
      col = mix(col, vec3(0.04, 0.06, 0.10), triWire * 0.28);
      col = mix(col, vec3(0.96, 0.98, 1.0), seam * 0.85);
      // Tint grazing meshlets approaching the backface-cone culling horizon in bright crimson
      col = mix(col, vec3(0.98, 0.20, 0.24), nearSilhouette * 0.65);
    } else {
      // Right: Final lit brushed alloy surface with subtle meshlet boundary gleam
      vec3 alloy = vec3(0.68, 0.74, 0.82);
      col = alloy * (0.22 + 0.88 * diff) + vec3(0.98, 0.94, 0.88) * spec * 0.65;
      col += mCol * seam * 0.16;
    }
  }

  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));
  col = mix(col, vec3(0.95, 0.97, 1.0), sep);

  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}
```

Attribution: MIT — written for this index.

## Lineage

- extends [Meshlets (cluster rendering)](https://texelatlas.vercel.app/t/meshlets.md)

## Combines with

- [Meshlets (cluster rendering)](https://texelatlas.vercel.app/t/meshlets.md): Meshlet buffers with bounds and micro indices are what task and mesh stages read.

## Combination ideas

- [Mesh-shader amplified geometry clipmaps with zero CPU draw calls](https://texelatlas.vercel.app/ideas/clipmap-terrain-mesh-shaders/)

## Sources

1. [primary] Christoph Kubisch Introduction to Turing Mesh Shaders. developer.nvidia.com. https://developer.nvidia.com/blog/introduction-turing-mesh-shaders (verified via http on 2026-11-29)
2. [implementation] zeux (2016) zeux/meshoptimizer. https://github.com/zeux/meshoptimizer License: MIT. (verified via github on 2026-11-29)

## Cite this entry

Texel. "Mesh shaders." https://texelatlas.vercel.app/t/mesh-shaders/ (accessed 2026-12-01).
