---
id: "shadow-volumes"
title: "Shadow Volumes"
domain: "visibility"
stage: "visibility"
realtime: "realtime"
platforms: [desktop-gpu, webgl2, unity, unreal, godot]
year_introduced: 1977
inputs: [mesh]
outputs: [visibility-mask]
style: "both"
dynamic: "dynamic"
cost: "medium"
authority: "Crow, 1977"
url: "https://texelatlas.vercel.app/t/shadow-volumes/"
sources_verified_at: "2026-11-29"
---
# Shadow Volumes (Crow, 1977)

> Extrudes occluder silhouettes away from the light into volumes, then uses a stencil counter to decide whether each pixel lies inside any of them.

## Reach for it when

- shadow map edges are jaggy or aliased
- need razor sharp pixel-accurate hard shadows
- shadow acne and peter-panning in simple scenes
- stencil-based shadows for closed meshes

## How it works

For each point light, find silhouette edges of casters (edges shared by a front-facing and a back-facing triangle) and extrude them to infinity, forming closed volumes. Render the scene depth first, then draw volume faces into the stencil buffer: increment on back faces and decrement on front faces that pass depth (z-fail, Carmack's reverse) or the opposite for z-pass. Pixels with a non-zero count lie in shadow and are excluded from the lighting pass. The result has exact, pixel-accurate hard edges independent of any shadow-map resolution, but requires watertight, manifold geometry, silhouette computation and heavy fill rate.

## When to use it

Choose it for razor-sharp hard shadows on simple, closed meshes where shadow-map aliasing is unacceptable. Prefer [Shadow Mapping](https://texelatlas.vercel.app/t/shadow-mapping.md) for any content with alpha tests, foliage, skinned or non-manifold meshes, [Percentage-Closer Filtering](https://texelatlas.vercel.app/t/percentage-closer-filtering.md) for soft edges, and [Ray-Traced Shadows](https://texelatlas.vercel.app/t/ray-traced-shadows.md) for exact results on modern hardware.

## Cost

medium — Fill-rate bound: large extruded quads cover many pixels, so cost scales with overdraw of volume faces.
Measured GPU Weight: 51.13× baseline (heavy) — 1.6822 ms median / 1.7911 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 51.33× baseline (heavy) — 0.8161 ms median (2.06× faster on L4).
Ampere A100 scaling: 33.22× baseline (heavy) — 0.9567 ms median (1.76× faster on A100).

## Failure modes

- Requires closed, manifold meshes or shadows fail
- Cap and far-plane handling needed for z-fail correctness
- Hard edges only; softening needs extra tricks
- Very high fill-rate cost with many lights

## Dataflow

- Inputs: mesh
- Outputs: visibility-mask
- Platforms: desktop-gpu, webgl2, unity, unreal, godot

## Presets

### Shadow Volumes (Carmack Reverse) — extruded silhouette shadow wedges & stencil count (left) vs razor-sharp stencil-masked shadows (right) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_VOL_ALPHA": 0.6,
  "P_LIGHT_SWEEP": 0.55,
  "P_AMBIENT": 0.28,
  "P_SPLIT": 0.48
}
```

```glsl
const float P_VOL_ALPHA = 0.60; // P Volume Extrusion Vis [0.1, 1.0, 0.05]
const float P_LIGHT_SWEEP = 0.55; // P Light Motion [0.0, 1.6, 0.05]
const float P_AMBIENT = 0.28; // P Ambient Level [0.05, 0.6, 0.05]
const float P_SPLIT = 0.48; // P Volumes / Stencil [0.0, 1.0, 0.02]

float sdBox(vec3 p, vec3 b) {
  vec3 q = abs(p) - b;
  return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
}

// Sharp polygonal obelisks & floating prism casting extruded geometric shadow volumes
vec2 mapCasters(vec3 p) {
  float d1 = sdBox(p - vec3(-0.36, -0.10, -0.15), vec3(0.14, 0.42, 0.14));
  float d2 = sdBox(p - vec3(0.34, 0.06, -0.05), vec3(0.16, 0.16, 0.16));
  vec2 res = (d1 < d2) ? vec2(d1, 2.0) : vec2(d2, 3.0);
  return res;
}

vec2 mapScene(vec3 p) {
  vec2 res = vec2(p.y + 0.52, 1.0);
  vec2 c = mapCasters(p);
  if (c.x < res.x) res = c;
  return res;
}

vec3 calcNormal(vec3 p) {
  vec2 e = vec2(0.002, 0.0);
  return normalize(vec3(
    mapScene(p + e.xyy).x - mapScene(p - e.xyy).x,
    mapScene(p + e.yxy).x - mapScene(p - e.yxy).x,
    mapScene(p + e.yyx).x - mapScene(p - e.yyx).x
  ));
}

// Exact point-in-extruded-shadow-volume test (projects ray backward toward lightPos to see if a caster blocks it)
bool inShadowVolume(vec3 p, vec3 lPos) {
  vec3 toL = lPos - p;
  float distL = length(toL);
  vec3 dir = toL / max(distL, 1e-4);
  float t = 0.025;
  for (int i = 0; i < 24; i++) {
    float h = mapCasters(p + dir * t).x;
    if (h < 0.0025) return true;
    t += max(h, 0.025);
    if (t > distL - 0.04) break;
  }
  return false;
}

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);
  float volVis = clamp(P_VOL_ALPHA, 0.05, 1.0);
  float amb = clamp(P_AMBIENT, 0.05, 0.7);
  float t = iTime * max(P_LIGHT_SWEEP, 0.0);

  vec3 lPos = vec3(0.95 * cos(t * 0.65), 0.78, 0.75 * sin(t * 0.65) + 0.15);
  vec3 ro = vec3(0.0, 0.42, 2.25);
  vec3 rd = normalize(vec3(uv.x, uv.y - 0.15, -1.48));
  vec3 col = mix(vec3(0.04, 0.05, 0.09), vec3(0.11, 0.15, 0.24), smoothstep(-0.3, 0.6, uv.y));

  float dist = 0.05;
  vec2 hit = vec2(10.0, 0.0);
  for (int i = 0; i < 64; i++) {
    vec2 h = mapScene(ro + rd * dist);
    if (h.x < 0.002) { hit = vec2(dist, h.y); break; }
    dist += h.x;
    if (dist > 9.0) break;
  }

  float maxMarch = min(hit.x, 5.5);

  if (hit.y > 0.5) {
    vec3 p = ro + rd * hit.x;
    vec3 n = calcNormal(p);
    vec3 lDir = normalize(lPos - p);
    float lDist = length(lPos - p);
    float atten = 2.6 / (0.4 + lDist * lDist);

    // Exact binary stencil shadow test (pixel-sharp, zero shadow-map texel aliasing!)
    float lit = inShadowVolume(p + n * 0.008, lPos) ? 0.0 : 1.0;

    vec3 alb = vec3(0.68, 0.66, 0.62);
    if (hit.y < 1.5) {
      float chk = mod(floor(p.x * 3.0) + floor(p.z * 3.0), 2.0);
      alb = mix(vec3(0.50, 0.52, 0.56), vec3(0.76, 0.75, 0.72), chk);
    } else if (hit.y < 2.5) {
      alb = vec3(0.86, 0.54, 0.26);
    } else {
      alb = vec3(0.26, 0.72, 0.88);
    }

    float ndl = max(dot(n, lDir), 0.0);
    col = alb * (vec3(0.16, 0.22, 0.34) * amb * 2.2 + vec3(1.40, 1.24, 1.02) * ndl * lit * atten);
    if (hit.y < 1.5) col = mix(vec3(0.04, 0.05, 0.09), col, exp(-hit.x * 0.11));
  }

  // Left: Visualize the translucent extruded silhouette shadow-volume wedges & entry/exit stencil faces!
  if (screenX < split) {
    float volHits = 0.0;
    float edgeHits = 0.0;
    bool prevIn = false;
    for (int s = 1; s <= 22; s++) {
      float ts = (float(s) / 22.0) * maxMarch;
      vec3 sp = ro + rd * ts;
      bool curIn = inShadowVolume(sp, lPos);
      if (curIn) volHits += 1.0;
      if (curIn != prevIn && s > 1) edgeHits += 1.0;
      prevIn = curIn;
    }
    vec3 wedgeCol = mix(vec3(0.16, 0.78, 1.0), vec3(1.0, 0.28, 0.54), clamp(edgeHits * 0.5, 0.0, 1.0));
    col += wedgeCol * (volHits / 22.0) * volVis * 0.85;
    col += vec3(0.28, 0.96, 1.0) * clamp(edgeHits, 0.0, 2.0) * volVis * 0.24;
  }

  // Glowing point light indicator
  float glowD = length(cross(lPos - ro, rd));
  col += vec3(1.4, 1.15, 0.75) * exp(-glowD * 12.0) * 0.55;

  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));
  col = mix(col, vec3(0.95, 0.98, 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.

## Sources

1. [primary] Franklin C. Crow (1977) Shadow algorithms for computer graphics. Proceedings of the 4th annual conference on Computer graphics and interactive techniques. https://doi.org/10.1145/563858.563901 (verified via crossref on 2026-11-29)
2. [tutorial] Cass Everitt, Mark J. Kilgard (2003) Practical and Robust Stenciled Shadow Volumes for Hardware-Accelerated Rendering. arXiv preprint (cs.GR). https://arxiv.org/abs/cs/0301002 (verified via arxiv on 2026-11-29)

## Cite this entry

Texel. "Shadow Volumes." https://texelatlas.vercel.app/t/shadow-volumes/ (accessed 2026-12-01).
