{
 "id": "schwarzschild-null-geodesic-lensing",
 "title": "Schwarzschild Null-Geodesic Gravitational Lensing and Relativistic Accretion Disk",
 "aliases": [
  "black hole ray tracing",
  "relativistic accretion disk rendering",
  "Binet geodesic lensing",
  "Schwarzschild photon ray marching"
 ],
 "domain": "volumes",
 "subdomain": "relativistic ray tracing",
 "stage": "volume",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "cuda"
 ],
 "year_introduced": 2015,
 "inputs": [
  "hdr-image",
  "depth",
  "texture"
 ],
 "outputs": [
  "hdr-image",
  "radiance"
 ],
 "style": "photoreal",
 "dynamic": "dynamic",
 "summary": "Integrate curved null-geodesic photon paths around a Schwarzschild mass per pixel, combining thin-lens background deflection with relativistic Doppler-beamed, gravitationally redshifted emission from a Keplerian accretion disk.",
 "how_it_works": "Around a compact mass, light no longer follows straight rays. Each pixel near the hole steps a camera ray backward in Cartesian coordinates using the Binet null-geodesic acceleration $x'' = -\\tfrac{3}{2} h^2 x / r^5$ (in units of the Schwarzschild radius $r_s$, with conserved angular momentum $h = |x \\times v|$). Rays with impact parameter below the critical threshold $b_c = \\tfrac{3\\sqrt{3}}{2} r_s$ plunge into the event-horizon shadow, while rays grazing $b_c$ orbit partially around the hole to form a razor-sharp photon ring.\n\nWhenever a curved ray crosses the equatorial plane between the innermost stable circular orbit and the outer radius, the shader evaluates a thin, differentially rotating turbulent accretion disk. Emission follows a blackbody temperature profile ($T \\propto r^{-3/4}$) shifted in both frequency and brightness ($I \\propto g^4$) by the combined Keplerian Doppler factor and gravitational redshift, brightening and blue-shifting the approaching limb while dimming the receding side. Because rays bend over and beneath the shadow, the far side of the disk arches both above and below the black core.\n\nFor embedded 3D scenes rather than skyboxes alone, a depth-gated weak-field thin-lens pass deflects background pixels behind the lens plane while keeping foreground geometry sharp and clamping lookups away from the hole's own silhouette.",
 "when_to_use": "Choose it when rendering physically recognizable black holes, Einstein rings, or relativistic singularities in real-time VFX, space simulations, or cinematic visualization.\n\nPrefer [volume-ray-marching](volume-ray-marching) when rays travel in straight lines through ordinary nebulae, clouds, or gas without spacetime curvature. Prefer [sphere-tracing](sphere-tracing) for refractive or warped analytic SDF anomalies where general-relativistic disk crossings and photon rings are unnecessary. Prefer [lens-flare](lens-flare) for purely optical camera bloom and diffraction effects without scene deflection.",
 "cost": {
  "class": "medium",
  "notes": "Runs as a single fullscreen or bounding-region fragment pass whose cost scales with geodesic integration step count (typically 48–96 steps) and screen coverage of the black hole."
 },
 "failure_modes": [
  "Coarse integration steps near the photon sphere cause jagged or stepped aliasing along the critical photon ring and secondary disk images",
  "Screen-space background deflection cannot reveal occluded geometry behind foreground objects and tears at depth discontinuities unless eased smoothly behind the lens plane",
  "Extreme Doppler beaming ($g^4$) produces huge HDR spikes on the approaching side that clip harshly without wide-gamut tonemapping",
  "Schwarzschild symmetry omits Kerr spin frame-dragging asymmetry and D-shaped shadows unless extended with full Kerr metric integration"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1088/0264-9381/32/6/065001",
   "type": "paper",
   "title": "Gravitational lensing by spinning black holes in astrophysics, and in the movie\n                    <i>Interstellar</i>",
   "authors": [
    "Oliver James",
    "Eugénie von Tunzelmann",
    "Paul Franklin",
    "Kip S Thorne"
   ],
   "year": 2015,
   "venue": "Classical and Quantum Gravity",
   "url": "https://doi.org/10.1088/0264-9381/32/6/065001",
   "ids": {
    "doi": "10.1088/0264-9381/32/6/065001"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1088/0264-9381/32/6/065001",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1088/0264-9381/32/6/065001",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1088/0264-9381/32/6/065001",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1088/0264-9381/32/6/065001",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1088/0264-9381/32/6/065001",
     "checked_at": "2026-11-30T17:59:51.239Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-30T17:59:51.239Z",
   "title_sim": 1,
   "__bib": "james2015gravitational"
  },
  {
   "role": "implementation",
   "key": "gh:humpalumps/ultra-elements",
   "type": "code",
   "title": "Humpalumps/ultra-elements",
   "description": "Real-time elemental spell VFX lab for three.js (WebGL2): 39 tunable spells",
   "authors": [
    "Humpalumps"
   ],
   "year": 2026,
   "venue": "GitHub",
   "url": "https://github.com/Humpalumps/ultra-elements",
   "ids": {
    "repo": "Humpalumps/ultra-elements"
   },
   "license": "MIT",
   "extra": {
    "stars": 131,
    "stars_checked": "2026-11-30",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-10-30T21:54:34Z",
    "language": "JavaScript",
    "homepage": null,
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/Humpalumps/ultra-elements",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/Humpalumps/ultra-elements",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/Humpalumps/ultra-elements",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/Humpalumps/ultra-elements",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/Humpalumps/ultra-elements",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/Humpalumps/ultra-elements",
     "checked_at": "2026-11-30T17:59:51.239Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-30T17:59:51.239Z",
   "title_sim": null,
   "__bib": "humpalumps2026humpalumps"
  }
 ],
 "presets": [
  {
   "id": "schwarzschild-disk-default",
   "title": "Real-time Schwarzschild disk starting parameters",
   "runtime": "json-params",
   "params": {
    "geodesic_steps": 72,
    "isco_radius_rs": 3,
    "outer_disk_radius_rs": 13,
    "critical_impact_rs": 2.598,
    "inner_temp_kelvin": 6500,
    "kepler_speed_scale": 1
   },
   "basis": "original",
   "license_note": "written for this index",
   "execution_fidelity": "parameter-only",
   "proof": {
    "kind": "parameter",
    "label": "parameter preset",
    "ok": true,
    "proof": null
   }
  },
  {
   "id": "schwarzschild-null-geodesic-lensing-live",
   "title": "Schwarzschild Null-Geodesic Lensing — flat Euclidean rays (left) vs curved spacetime photon ring & Doppler disk (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_BH_MASS": 1,
    "P_DISK_INCL": 0.22,
    "P_DOPPLER_STR": 0.85,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_BH_MASS = 1.00; // P Horizon Scale [0.6, 1.5, 0.05]\nconst float P_DISK_INCL = 0.22; // P Disk Inclination [0.08, 0.55, 0.02]\nconst float P_DOPPLER_STR = 0.85; // P Relativistic Beaming [0.0, 1.4, 0.05]\nconst float P_SPLIT = 0.48; // P Flat / Geodesic Split [0.0, 1.0, 0.02]\n\nfloat hash21(vec2 p) {\n  p = fract(p * vec2(127.1, 311.7));\n  p += dot(p, p + 34.5);\n  return fract(p.x * p.y);\n}\n\n// Background galactic starfield & faint nebula sampled by asymptotic deflected photon direction d\nvec3 evalStarfield(vec3 d) {\n  d = normalize(d);\n  float phi = atan(d.z, d.x);\n  float th = acos(clamp(d.y, -1.0, 1.0));\n  vec2 g = vec2(phi * 26.0, th * 26.0);\n  vec2 id = floor(g);\n  vec2 f = fract(g) - 0.5;\n  float rnd = hash21(id);\n  float star = step(0.965, rnd) * exp(-dot(f, f) * 58.0) * (1.2 + 1.8 * hash21(id + 7.3));\n  vec3 starCol = mix(vec3(0.75, 0.88, 1.0), vec3(1.0, 0.84, 0.65), hash21(id + 3.1));\n  // Subtle galactic dust band\n  float band = exp(-pow(d.y * 2.8 + 0.35 * sin(phi * 2.0), 2.0) * 3.5);\n  vec3 neb = vec3(0.06, 0.09, 0.16) * band + vec3(0.015, 0.02, 0.035);\n  return neb + starCol * star;\n}\n\n// Keplerian accretion disk emission with relativistic Doppler beaming & gravitational redshift\nvec3 evalDiskEmission(vec3 pos, vec3 rayDir, float rs, float dopplerK) {\n  float r = length(pos.xz);\n  float rIn = rs * 2.15;\n  float rOut = rs * 6.8;\n  if (r < rIn || r > rOut) return vec3(0.0);\n\n  float ang = atan(pos.z, pos.x);\n  float omega = 1.65 / max(pow(r, 1.25), 0.2);\n  float spiral = 0.55 + 0.45 * sin(ang * 4.0 + r * 4.2 - iTime * (1.8 + omega));\n  float rings = 0.65 + 0.35 * sin(r * 14.0 - iTime * 1.4);\n  float radialFade = smoothstep(rIn, rIn + 0.25 * rs, r) * smoothstep(rOut, rIn + 1.4 * rs, r);\n\n  // Keplerian tangent velocity vector v (counter-clockwise orbiting disk)\n  vec3 velDir = normalize(vec3(-pos.z, 0.0, pos.x));\n  float beta = clamp(sqrt(0.5 * rs / max(r, rs * 1.1)), 0.0, 0.62);\n  float cosA = dot(velDir, -rayDir);\n  // Relativistic Doppler factor D = 1 / (gamma * (1 - beta*cosA)) -> approaching left side beams blazing blue-white, receding right redshifts!\n  float doppler = mix(1.0, (1.0 + beta * cosA) / max(1.0 - 0.55 * beta * cosA, 0.35), dopplerK);\n  float gravRed = sqrt(max(1.0 - rs / max(r, rs * 1.02), 0.08));\n  float gShift = clamp(doppler * gravRed, 0.25, 2.4);\n\n  // Temperature shifts from deep crimson -> blazing gold -> blue-white under gShift\n  vec3 coldC = vec3(0.95, 0.20, 0.04);\n  vec3 midC = vec3(1.0, 0.68, 0.24);\n  vec3 hotC = vec3(0.85, 0.94, 1.0);\n  vec3 tempCol = mix(coldC, mix(midC, hotC, smoothstep(0.85, 1.75, gShift)), smoothstep(0.35, 1.05, gShift));\n\n  float intensity = pow(gShift, 2.4) * radialFade * (0.45 + 0.55 * spiral * rings) * 2.2;\n  return tempCol * intensity;\n}\n\nvec3 aces(vec3 x) {\n  x = max(x, 0.0);\n  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  float sx = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  bool useGeodesic = sx >= split;\n\n  float rs = clamp(P_BH_MASS, 0.5, 1.6) * 0.42;\n  float incl = clamp(P_DISK_INCL, 0.06, 0.65);\n  float dopplerK = clamp(P_DOPPLER_STR, 0.0, 1.5);\n\n  float camDist = 5.4;\n  vec3 ro = vec3(0.0, camDist * sin(incl), camDist * cos(incl));\n  vec3 fw = normalize(-ro);\n  vec3 ri = normalize(cross(fw, vec3(0.0, 1.0, 0.0)));\n  vec3 up = cross(ri, fw);\n  vec3 rd = normalize(fw * 1.65 + ri * uv.x + up * uv.y);\n\n  // Integrate photon trajectory: null geodesic a = -1.5 * rs * h^2 * p / r^5 (where h = |p x rd| is angular momentum!)\n  vec3 pos = ro;\n  vec3 vel = rd;\n  vec3 hVec = cross(pos, vel);\n  float h2 = dot(hVec, hVec);\n\n  vec3 accCol = vec3(0.0);\n  bool captured = false;\n\n  const int STEPS = 84;\n  for (int i = 0; i < STEPS; i++) {\n    float r = length(pos);\n    if (r < rs * 1.02) { captured = true; break; }\n    if (r > 14.0) break;\n\n    float dt = clamp(r * 0.085, 0.04, 0.35);\n    vec3 prevPos = pos;\n\n    if (useGeodesic) {\n      // Schwarzschild exact general-relativistic null-geodesic bending force (-3/2 * rs * h^2 / r^5 * pos)\n      vec3 accel = -1.5 * rs * h2 * pos / max(pow(r, 5.0), 1e-4);\n      vel = normalize(vel + accel * dt);\n    }\n    pos += vel * dt;\n\n    // Detect crossing of equatorial accretion disk plane (y == 0)\n    if (prevPos.y * pos.y <= 0.0 && abs(pos.y - prevPos.y) > 1e-5) {\n      float f = abs(prevPos.y) / abs(pos.y - prevPos.y);\n      vec3 hitP = mix(prevPos, pos, f);\n      accCol += evalDiskEmission(hitP, vel, rs, dopplerK);\n    }\n  }\n\n  vec3 col = accCol;\n  if (!captured) {\n    col += evalStarfield(vel);\n  }\n\n  // Subtle Einstein photon sphere glow near r = 1.5 * rs on geodesic side\n  if (useGeodesic) {\n    float bImpact = sqrt(h2);\n    float bCrit = 2.598 * rs;\n    float photonRing = exp(-pow((bImpact - bCrit) / (0.045 * rs), 2.0));\n    col += vec3(1.0, 0.86, 0.62) * photonRing * 0.45;\n  }\n\n  float sep = smoothstep(0.0035, 0.0008, abs(sx - split));\n  col = mix(col, vec3(0.95, 0.97, 1.0), sep);\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "schwarzschild-null-geodesic-lensing",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T21:07:23.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.3932,
      "std": 0.3254,
      "min": 0,
      "max": 0.9966
     },
     "image": "/specimens/schwarzschild-null-geodesic-lensing-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "volume-ray-marching",
  "sphere-tracing",
  "lens-flare",
  "dual-filter-bloom"
 ],
 "extends": [
  "volume-ray-marching"
 ],
 "supersedes": [],
 "combines_with": [
  {
   "id": "dual-filter-bloom",
   "why": "HDR radiance from the Doppler-beamed inner accretion disk and photon ring drives physically convincing optical glare."
  },
  {
   "id": "agx-tonemapping",
   "why": "High-contrast blackbody emission compresses cleanly into display gamut without abrupt hue shifts on the hot approaching limb."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-30T17:59:51.239Z",
  "draft": "data/drafts/volumes/schwarzschild-null-geodesic-lensing.json"
 },
 "solves": [
  "render a physically plausible black hole with photon ring and accretion disk",
  "bend background starfields and environment maps around a gravity well",
  "integrate curved light rays in curved spacetime on the gpu in real time",
  "show top and bottom of an accretion disk simultaneously via gravitational lensing",
  "avoid numerical spiral blowup near the event horizon when ray marching"
 ],
 "authority": "James et al., 2015",
 "url": "https://texelatlas.vercel.app/t/schwarzschild-null-geodesic-lensing/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 41.35,
  "tier": "heavy",
  "p50_ms": 1.3604,
  "p95_ms": 1.4432,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "schwarzschild-null-geodesic-lensing-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 38.84,
   "tier": "heavy",
   "p50_ms": 0.6176,
   "p95_ms": 0.6199,
   "speedup_x": 2.2,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 24.39,
   "tier": "heavy",
   "p50_ms": 0.7025,
   "p95_ms": 0.7057,
   "speedup_x": 1.94,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}