{
 "id": "sdf-soft-shadows",
 "title": "SDF Soft Shadows",
 "aliases": [],
 "domain": "visibility",
 "subdomain": "distance field shadows",
 "stage": "visibility",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu"
 ],
 "year_introduced": 2008,
 "inputs": [
  "sdf"
 ],
 "outputs": [
  "visibility-mask"
 ],
 "style": "both",
 "dynamic": "dynamic",
 "summary": "While sphere-tracing toward the light, the smallest ratio of distance-to-surface over travelled distance approximates the light's unoccluded cone, giving cheap penumbrae for free.",
 "how_it_works": "A shadow ray is marched through a signed distance field from the shaded point toward the light. At each step, the SDF value d at distance t tells how close the ray passes to geometry; the ratio k*d/t is the sine-like angle of the nearest occluder as seen from the origin. Keeping the minimum of this ratio over the ray, clamped to 0..1, gives a visibility value that is 1 in open space, falls smoothly near silhouettes and reaches 0 when the ray hits geometry. The constant k sets penumbra width. Improvements use the previous step's distance to estimate the closest approach more accurately, remove banding, and smooth the result. The same field also serves AO and global-illumination queries.",
 "when_to_use": "Choose it when the scene is already an SDF (raymarched demos, shader-art, Dreams-style content, or a baked or voxelised distance field) and you want cheap soft shadows with no shadow map. Prefer `shadow-mapping` with `percentage-closer-soft-shadows` for triangle-mesh scenes, `ray-traced-shadows` for accurate penumbrae against meshes, and `contact-shadows` for a screen-space supplement.",
 "cost": {
  "class": "medium",
  "notes": "Tens of SDF evaluations per pixel; cost depends on the complexity of the field function."
 },
 "failure_modes": [
  "Penumbra is an approximation of one light cone and is not physically accurate for large lights",
  "Banding or light leaks if the step size is clamped too low or too high",
  "Inexact (Lipschitz-violating) SDFs from domain warping give artifacts",
  "Self-shadowing at grazing angles needs a normal offset"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://iquilezles.org/articles/rmshadows",
   "type": "web",
   "title": "Soft shadows in raymarched SDFs",
   "authors": [
    "Inigo Quilez"
   ],
   "year": null,
   "venue": "iquilezles.org",
   "url": "https://iquilezles.org/articles/rmshadows",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261024011958/https://iquilezles.org/articles/rmshadows/",
     "timestamp": "20261024011958"
    },
    "page_title": "Inigo Quilez :: computer graphics, maths, shaders, fractals, demoscene",
    "host": "iquilezles.org",
    "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://iquilezles.org/articles/rmshadows → 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://iquilezles.org/articles/rmshadows → 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,
   "__bib": "quilezsoft"
  }
 ],
 "presets": [
  {
   "id": "sdf-soft-shadows-spheres-box",
   "title": "Raymarched spheres and box with soft shadows",
   "runtime": "glsl-fragment",
   "params": {
    "SHADOW_K": 10,
    "SHADOW_STEPS": 48
   },
   "code": "// GLSL ES 3.0, Shadertoy-style: raymarched SDF scene with soft shadows\nconst float SHADOW_K = 10.0;      // penumbra sharpness (higher = harder)\nconst int   SHADOW_STEPS = 48;\nconst vec3  LIGHT_DIR = normalize(vec3(-0.6, 0.8, 0.4));\n\nfloat sdSphere(vec3 p, float r) { return length(p) - r; }\nfloat 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); }\n\nfloat map(vec3 p) {\n    float ground = p.y + 1.0;\n    float s = sdSphere(p - vec3(-0.9, -0.1 + 0.15 * sin(iTime), 0.0), 0.9);\n    float b = sdBox(p - vec3(1.1, -0.4, 0.3), vec3(0.6, 0.6, 0.6));\n    return min(ground, min(s, b));\n}\n\nvec3 calcNormal(vec3 p) {\n    vec2 e = vec2(0.001, 0.0);\n    return normalize(vec3(map(p + e.xyy) - map(p - e.xyy), map(p + e.yxy) - map(p - e.yxy), map(p + e.yyx) - map(p - e.yyx)));\n}\n\n// Soft shadow: track the narrowest cone (min of k*d/t) seen along the ray to the light.\nfloat softShadow(vec3 ro, vec3 rd) {\n    float res = 1.0;\n    float t = 0.02;\n    for (int i = 0; i < SHADOW_STEPS; i++) {\n        float d = map(ro + rd * t);\n        res = min(res, SHADOW_K * d / t);\n        t += clamp(d, 0.02, 0.5);\n        if (res < 0.001 || t > 12.0) break;\n    }\n    res = clamp(res, 0.0, 1.0);\n    return res * res * (3.0 - 2.0 * res);\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n    vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n    vec3 ro = vec3(0.0, 1.6, -5.5);\n    vec3 rd = normalize(vec3(uv.x, uv.y - 0.2, 1.6));\n    float t = 0.0;\n    bool hit = false;\n    for (int i = 0; i < 100; i++) {\n        float d = map(ro + rd * t);\n        if (d < 0.001) { hit = true; break; }\n        t += d;\n        if (t > 30.0) break;\n    }\n    vec3 col = mix(vec3(0.75, 0.85, 1.0), vec3(0.3, 0.5, 0.9), clamp(uv.y + 0.6, 0.0, 1.0));\n    if (hit) {\n        vec3 p = ro + rd * t;\n        vec3 n = calcNormal(p);\n        float diff = clamp(dot(n, LIGHT_DIR), 0.0, 1.0);\n        float sh = softShadow(p + n * 0.01, LIGHT_DIR);\n        vec3 albedo = (p.y < -0.99) ? vec3(0.8) * (0.8 + 0.2 * step(0.0, sin(p.x * 3.0) * sin(p.z * 3.0))) : vec3(0.9, 0.45, 0.3);\n        float sky = 0.5 + 0.5 * n.y;\n        col = albedo * (vec3(1.0, 0.95, 0.85) * diff * sh * 1.2 + vec3(0.3, 0.4, 0.55) * sky * 0.35);\n    }\n    fragColor = vec4(pow(col, vec3(1.0 / 2.2)), 1.0);\n}",
   "basis": "original",
   "license_note": "written for this index",
   "execution_fidelity": "faithful-pass",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-29",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "sdf-soft-shadows",
     "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.6215,
      "std": 0.2487,
      "unique_colors": 115
     },
     "image": "/specimens/sdf-soft-shadows-spheres-box.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "ray-traced-shadows",
  "sdf-ambient-occlusion",
  "contact-shadows",
  "percentage-closer-soft-shadows"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [],
 "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/sdf-soft-shadows.json"
 },
 "solves": [
  "soft shadows needed in ray marched scenes",
  "cheap penumbra without many shadow rays",
  "shadertoy style scene needs realistic shading",
  "sdf rendering shadows look hard and aliased"
 ],
 "authority": "Quilez",
 "url": "https://texelatlas.vercel.app/t/sdf-soft-shadows/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 24.84,
  "tier": "heavy",
  "p50_ms": 0.8173,
  "p95_ms": 0.842,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "sdf-soft-shadows-spheres-box",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 22.43,
   "tier": "heavy",
   "p50_ms": 0.3566,
   "p95_ms": 0.3608,
   "speedup_x": 2.29,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 14.67,
   "tier": "moderate",
   "p50_ms": 0.4224,
   "p95_ms": 0.4277,
   "speedup_x": 1.93,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}