{
 "id": "enhanced-sphere-tracing",
 "title": "Enhanced Sphere Tracing",
 "aliases": [],
 "domain": "geometry",
 "subdomain": "ray marching",
 "stage": "geometry",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "cuda"
 ],
 "year_introduced": 2014,
 "inputs": [
  "sdf"
 ],
 "outputs": [
  "depth",
  "normals"
 ],
 "style": "both",
 "dynamic": "dynamic",
 "summary": "Sphere tracing with over-relaxation: step slightly beyond the safe distance and fall back only when consecutive spheres fail to overlap. Cuts iteration counts, especially for near-grazing rays, with a pixel-exact result.",
 "how_it_works": "Standard sphere tracing steps exactly by the distance d. Enhanced sphere tracing multiplies the step by a relaxation factor omega (around 1.2 to 1.6). After the step, it checks whether the new sphere still overlaps the previous one: the sum of the two radii must be at least the step length. If the check fails, it undoes the relaxation for that step and falls back to the safe step. It also uses the unrelaxed ray parameter with the smallest error to pick the best hit estimate. Automatic variants adapt omega per ray using the local curvature estimate. Some versions add a final refinement from the last spheres so grazing hits are resolved more precisely.",
 "when_to_use": "Choose it as a drop-in speed-up for any sphere-traced scene where fields are exact or conservative and you see slow grazing pixels. Prefer plain `sphere-tracing` when your field is far from 1-Lipschitz and fall-backs would be constant, and `segment-tracing` when you can supply local Lipschitz constants for warped or animated fields.",
 "cost": {
  "class": "medium",
  "notes": "Typically fewer iterations than basic sphere tracing at the cost of a few extra operations per step; gains depend on scene geometry."
 },
 "failure_modes": [
  "Overstep followed by backtrack wastes work on cluttered scenes",
  "Poorly chosen omega leads to rejected relaxations on every step and no gain",
  "Still assumes a Lipschitz-1 field; warps break the overlap test's guarantees",
  "Divergent step counts across a warp reduce GPU efficiency"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.2312/stag.20141233",
   "type": "paper",
   "title": "Enhanced Sphere Tracing",
   "authors": [
    "Benjamin Keinert",
    "Henry Schäfer",
    "Johann Korndörfer",
    "Urs Ganse",
    "Marc Stamminger"
   ],
   "year": 2014,
   "venue": "Smart Tools and Apps for Graphics - Eurographics Italian Chapter Conference",
   "url": "https://doi.org/10.2312/stag.20141233",
   "ids": {
    "doi": "10.2312/stag.20141233"
   },
   "license": null,
   "extra": {
    "csl_type": "article"
   },
   "provenance": {
    "title": {
     "authority": "doi.org",
     "endpoint": "https://doi.org/10.2312/stag.20141233 (CSL-JSON)",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "doi.org",
     "endpoint": "https://doi.org/10.2312/stag.20141233 (CSL-JSON)",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "doi.org",
     "endpoint": "https://doi.org/10.2312/stag.20141233 (CSL-JSON)",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "doi.org",
     "endpoint": "https://doi.org/10.2312/stag.20141233 (CSL-JSON)",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "doi.org",
     "endpoint": "https://doi.org/10.2312/stag.20141233 (CSL-JSON)",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "keinert2014enhanced"
  },
  {
   "role": "tutorial",
   "key": "url:https://iquilezles.org/articles/distfunctions",
   "type": "tutorial",
   "title": "Distance functions",
   "authors": [
    "Inigo Quilez"
   ],
   "year": null,
   "venue": "iquilezles.org",
   "url": "https://iquilezles.org/articles/distfunctions",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261125144804/https://iquilezles.org/articles/distfunctions/",
     "timestamp": "20261125144804"
    },
    "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/distfunctions → 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/distfunctions → 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": "quilezdistance"
  }
 ],
 "presets": [
  {
   "id": "enhanced-sphere-tracing-specimen",
   "title": "Over-relaxed sphere tracing step counts vs plain sphere tracing",
   "runtime": "glsl-fragment",
   "params": {
    "MAX_STEPS": 48,
    "OMEGA": 1.6,
    "EPS": 0.001
   },
   "code": "// Over-relaxed sphere tracing (omega 1.6 with fallback): left = plain tracing steps, right = relaxed steps, same heat scale.\nconst int MAX_STEPS = 48;\nconst float OMEGA = 1.6;\nconst float EPS = 0.001;\nfloat map(vec3 p) {\n    float s = length(p - vec3(-0.9, 0.0, 0.0)) - 0.8;\n    vec2 q = vec2(length(p.xz - vec2(1.0, 0.2)) - 0.8, p.y);\n    float t = length(q) - 0.25;\n    float b = p.y + 0.9;\n    return min(min(s, t), b);\n}\nvec3 heat(float x) { return clamp(vec3(1.5 * x, 1.5 - abs(3.0 * x - 1.5), 1.5 - 1.5 * x), 0.0, 1.0); }\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.0, -4.0), rd = normalize(vec3(uv.x, uv.y - 0.12, 1.4));\n    float om = uv.x > 0.0 ? OMEGA : 1.0;\n    float t = 0.0, prevR = 0.0, stepLen = 0.0; int n = 0; bool hit = false;\n    for (int i = 0; i < MAX_STEPS; i++) {\n        n = i;\n        float r = map(ro + rd * t);\n        if (om > 1.0 && stepLen > prevR + r) {          // overshoot: back up to the last safe step\n            t += prevR - stepLen; stepLen = 0.0; prevR = 0.0; continue;\n        }\n        if (r < EPS * t + 0.0005) { hit = true; break; }\n        stepLen = om * r; prevR = r; t += stepLen;\n        if (t > 20.0) break;\n    }\n    vec3 col = heat(float(n) / float(MAX_STEPS));\n    if (!hit && t > 20.0) col *= 0.35;\n    col = mix(col, vec3(1.0), smoothstep(0.003, 0.0, abs(uv.x)));\n    fragColor = vec4(pow(col, vec3(0.6)), 1.0);\n}\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": "enhanced-sphere-tracing",
     "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.5263,
      "std": 0.2299,
      "unique_colors": 95
     },
     "image": "/specimens/enhanced-sphere-tracing-specimen.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "sphere-tracing",
  "segment-tracing",
  "sdf-csg-smooth-min"
 ],
 "extends": [
  "sphere-tracing"
 ],
 "supersedes": [],
 "combines_with": [
  {
   "id": "sdf-csg-smooth-min",
   "why": "Step bounds rely on the SDF being close to exact."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/geometry/enhanced-sphere-tracing.json"
 },
 "solves": [
  "ray marching is slow at grazing angles",
  "too many iterations per pixel on distance fields",
  "want faster raymarcher without changing the result",
  "shader steps crawl along surfaces seen at a slant",
  "reduce march step count in an sdf scene"
 ],
 "authority": "Keinert et al., 2014",
 "url": "https://texelatlas.vercel.app/t/enhanced-sphere-tracing/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 11.65,
  "tier": "moderate",
  "p50_ms": 0.3832,
  "p95_ms": 0.3897,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "enhanced-sphere-tracing-specimen",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 10.11,
   "tier": "moderate",
   "p50_ms": 0.1608,
   "p95_ms": 0.168,
   "speedup_x": 2.38,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 7.12,
   "tier": "moderate",
   "p50_ms": 0.2052,
   "p95_ms": 0.2057,
   "speedup_x": 1.87,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}