{
 "id": "shadow-map-bias-slope-scale-normal-offset",
 "title": "Shadow map depth bias (constant, slope-scale, normal offset)",
 "aliases": [
  "shadow bias",
  "depth bias",
  "slope-scaled depth bias",
  "normal-offset shadows",
  "shadow acne fix"
 ],
 "domain": "visibility",
 "subdomain": "shadow map artifact control",
 "stage": "visibility",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "unity",
  "unreal",
  "godot"
 ],
 "year_introduced": 2014,
 "inputs": [
  "depth",
  "normals",
  "mesh"
 ],
 "outputs": [
  "visibility-mask"
 ],
 "style": "both",
 "dynamic": "dynamic",
 "summary": "A family of offsets that keep a surface from shadowing itself in a shadow map: a constant depth offset, a term scaled by the surface's slope to the light, and a shift along the normal before lookup.",
 "how_it_works": "A shadow map stores depth at texel centres, but a receiver sampled between centres sits at a slightly different light-space depth, so a tilted surface compares itself against a sample that can be nearer than the point being shaded. Without correction half of every texel reads as shadowed (acne). Three fixes are combined. A **constant bias** subtracts a fixed amount from the receiver depth. A **slope-scaled bias** grows with the tangent of the angle between normal and light (or the depth gradient, as hardware polygon offset does), because the error grows as the surface becomes grazing. A **normal offset** moves the world position along the geometric normal by about one shadow texel (scaled by the sine of the light angle) before projecting, which shrinks the needed depth bias and avoids light leaking at contact points. Biases are best expressed in texel or world-space units per cascade, not clip-space depth, because texel footprint changes with every cascade and light type. Adaptive schemes compute the bias from the receiver's actual depth gradient.",
 "when_to_use": "Use it in every shadow-mapped renderer; it is the first thing to tune before blaming filtering. Prefer normal offset plus a small slope-scaled term over a big constant bias, which causes peter-panning (shadows detached from their casters). Reach for `percentage-closer-filtering` or `variance-shadow-maps` when the remaining artifact is blocky edges rather than self-shadowing, and use `contact-shadows` to recover the small-scale detail that bias removes. Per-cascade tuning matters with `cascaded-shadow-maps`; `virtual-shadow-maps` and `ray-traced-shadows` reduce but do not remove the need.",
 "cost": {
  "class": "cheap",
  "notes": "A few ALU operations in the shadow lookup; the depth-bias state in the caster pass is free on fixed-function hardware."
 },
 "failure_modes": [
  "Shadow acne stripes on surfaces near-parallel to the light when bias is too small",
  "Peter-panning: the shadow visibly detaches from the base of the caster when constant bias is too large",
  "Light leaking at thin walls and contact edges because bias exceeds wall thickness",
  "A bias tuned for one cascade or light range shows acne or detachment in another",
  "Normal offset shrinks or grows silhouettes of shadows on curved or finely tessellated geometry",
  "Back-face casting hides acne on closed meshes but leaks on thin or open geometry"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/2556700.2556706",
   "type": "paper",
   "title": "Adaptive depth bias for shadow maps",
   "authors": [
    "Hang Dou",
    "Yajie Yan",
    "Ethan Kerzner",
    "Zeng Dai",
    "Chris Wyman"
   ],
   "year": 2014,
   "venue": "Proceedings of the 18th meeting of the ACM SIGGRAPH Symposium on Interactive 3D Graphics and Games",
   "url": "https://doi.org/10.1145/2556700.2556706",
   "ids": {
    "doi": "10.1145/2556700.2556706"
   },
   "license": null,
   "extra": {
    "csl_type": "proceedings-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2556700.2556706",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2556700.2556706",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2556700.2556706",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2556700.2556706",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/2556700.2556706",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "dou2014adaptive"
  },
  {
   "role": "tutorial",
   "key": "url:https://learn.microsoft.com/en-us/windows/win32/dxtecharts/common-techniques-to-improve-shadow-depth-maps",
   "type": "tutorial",
   "title": "Common Techniques to Improve Shadow Depth Maps",
   "authors": [
    "Microsoft"
   ],
   "year": null,
   "venue": "learn.microsoft.com",
   "url": "https://learn.microsoft.com/en-us/windows/win32/dxtecharts/common-techniques-to-improve-shadow-depth-maps",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261101162838/https://learn.microsoft.com/en-us/windows/win32/dxtecharts/common-techniques-to-improve-shadow-depth-maps",
     "timestamp": "20261101162838"
    },
    "page_title": "Common Techniques to Improve Shadow Depth Maps - Win32 apps",
    "host": "learn.microsoft.com",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://learn.microsoft.com/en-us/windows/win32/dxtecharts/common-techniques-to-improve-shadow-depth-maps → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://learn.microsoft.com/en-us/windows/win32/dxtecharts/common-techniques-to-improve-shadow-depth-maps → 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://learn.microsoft.com/en-us/windows/win32/dxtecharts/common-techniques-to-improve-shadow-depth-maps → 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": "microsoftcommon"
  },
  {
   "role": "tutorial",
   "key": "url:https://therealmjp.github.io/posts/shadow-maps",
   "type": "tutorial",
   "title": "A Sampling of Shadow Techniques",
   "authors": [
    "Matt Pettineo"
   ],
   "year": null,
   "venue": "therealmjp.github.io",
   "url": "https://therealmjp.github.io/posts/shadow-maps",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20260915211806/https://therealmjp.github.io/posts/shadow-maps/",
     "timestamp": "20260915211806"
    },
    "page_title": "A Sampling of Shadow Techniques",
    "host": "therealmjp.github.io",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://therealmjp.github.io/posts/shadow-maps → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://therealmjp.github.io/posts/shadow-maps → 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://therealmjp.github.io/posts/shadow-maps → 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": 1,
   "__bib": "pettineosampling"
  },
  {
   "role": "implementation",
   "key": "gh:mrdoob/three.js",
   "type": "code",
   "title": "mrdoob/three.js",
   "description": "JavaScript 3D Library.",
   "authors": [
    "mrdoob"
   ],
   "year": 2010,
   "venue": "GitHub",
   "url": "https://github.com/mrdoob/three.js",
   "ids": {
    "repo": "mrdoob/three.js"
   },
   "license": "MIT",
   "extra": {
    "stars": 119718,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-11-29T11:39:51Z",
    "language": "JavaScript",
    "homepage": "https://threejs.org/",
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mrdoob/three.js",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "mrdoob2010mrdoob"
  }
 ],
 "presets": [
  {
   "id": "shadow-bias-acne-vs-peter-panning",
   "title": "Bias comparison: acne, tuned, peter-panning",
   "runtime": "glsl-fragment",
   "params": {
    "slope": 2,
    "texels": 32,
    "bias_panels": [
     0,
     0.08,
     0.3
    ]
   },
   "code": "// GLSL ES 3.0, Shadertoy-style. Three panels: no bias (acne), tuned bias, huge bias (peter-panning).\n// Top-down view of a ground plane lit at a grazing angle, shadowed by a wall, with a low-res shadow map.\nconst float SLOPE = 2.0;    // receiver light-depth gradient across the plane (grazing light)\nconst float TEXELS = 32.0;  // shadow-map resolution across one panel\nconst float GAP = 0.8;      // depth separation gained per unit of shadow length behind the wall\nconst vec3 BIAS = vec3(0.0, 0.08, 0.3);\nconst float WALL_X = -0.5;\n\nfloat lit(vec2 p, float bias) {\n  float t = 2.0 / TEXELS;\n  vec2 c = (floor((p + 1.0) / t) + 0.5) * t - 1.0;   // texel centre: what the map actually stored\n  bool inShadowTexel = c.x > WALL_X && c.x < WALL_X + 0.6 && abs(c.y) < 0.35;\n  float stored = SLOPE * c.x - (inShadowTexel ? GAP * (c.x - WALL_X) : 0.0);\n  float receiver = SLOPE * p.x;\n  return (receiver - bias > stored) ? 0.0 : 1.0;      // 0 = shadowed\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = fragCoord / iResolution.xy;\n  float panel = floor(uv.x * 3.0);\n  vec2 p = vec2(fract(uv.x * 3.0) * 2.0 - 1.0, uv.y * 2.0 - 1.0);\n  float bias = panel < 0.5 ? BIAS.x : (panel < 1.5 ? BIAS.y : BIAS.z);\n  float l = lit(p, bias);\n  vec3 ground = vec3(0.86, 0.80, 0.68) * (0.30 + 0.70 * l);\n  ground *= 0.92 + 0.08 * sin(p.y * 40.0);\n  bool wall = p.x > WALL_X - 0.08 && p.x < WALL_X && abs(p.y) < 0.35;\n  vec3 col = wall ? vec3(0.35, 0.22, 0.18) : ground;\n  float edge = abs(fract(uv.x * 3.0) - 0.5);\n  if (edge > 0.495) col = vec3(1.0);\n  fragColor = vec4(col, 1.0);\n}\n",
   "basis": "original",
   "license_note": "written for this index",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-29",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "shadow-map-bias-slope-scale-normal-offset",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-29T15:51:50.471Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.618,
      "std": 0.2282,
      "unique_colors": 19
     },
     "image": "/specimens/shadow-bias-acne-vs-peter-panning.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "shadow-mapping",
  "cascaded-shadow-maps",
  "percentage-closer-filtering",
  "variance-shadow-maps",
  "moment-shadow-maps",
  "virtual-shadow-maps",
  "contact-shadows"
 ],
 "extends": [
  "shadow-mapping"
 ],
 "supersedes": [],
 "combines_with": [
  {
   "id": "cascaded-shadow-maps",
   "why": "Per-cascade texel size defines the bias and normal-offset magnitude applied in each cascade lookup."
  },
  {
   "id": "percentage-closer-filtering",
   "why": "Bias must cover the whole PCF kernel footprint, so the receiver depth is plane-fitted or offset before the multi-tap compare."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/visibility/shadow-map-bias-slope-scale-normal-offset.json"
 },
 "solves": [
  "shadows covered in stripes on surfaces facing away from light",
  "shadow detaches from the bottom of objects",
  "floor looks striped or moire-patterned in shadowed areas",
  "characters seem to float above ground because shadow is offset",
  "shadow leaks through thin walls near contact point"
 ],
 "authority": "Dou et al., 2014",
 "url": "https://texelatlas.vercel.app/t/shadow-map-bias-slope-scale-normal-offset/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 0.99,
  "tier": "feather",
  "p50_ms": 0.0325,
  "p95_ms": 0.0397,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "shadow-bias-acne-vs-peter-panning",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 0.99,
   "tier": "feather",
   "p50_ms": 0.0157,
   "p95_ms": 0.0158,
   "speedup_x": 2.07,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 1,
   "tier": "feather",
   "p50_ms": 0.0288,
   "p95_ms": 0.0288,
   "speedup_x": 1.13,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}