Schwarzschild Null-Geodesic Gravitational Lensing and Relativistic Accretion Disk
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.
Also known as black hole ray tracing, relativistic accretion disk rendering, Binet geodesic lensing, Schwarzschild photon ray marching
In the family Atmosphere, water & volumes, relativistic ray tracing
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | None found | No built-in relativistic Schwarzschild null-geodesic gravitational lensing shader. |
| Babylon.js 9.38.0 | None found | |
| Godot 4.7 | None found | No built-in relativistic Schwarzschild null-geodesic gravitational lensing shader. |
| Unity | None found | No built-in relativistic Schwarzschild null-geodesic gravitational lensing shader. |
| Unreal 5.7 | None found | No built-in relativistic Schwarzschild null-geodesic gravitational lensing shader. |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
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'' = -3/2 h2 x / r5 (in units of the Schwarzschild radius rs, with conserved angular momentum h = |x × v|). Rays with impact parameter below the critical threshold bc = 3√3/2 rs plunge into the event-horizon shadow, while rays grazing bc orbit partially around the hole to form a razor-sharp photon ring.
Whenever 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 ∝ r-3/4) shifted in both frequency and brightness (I ∝ g4) 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.
For 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 choose it
Reach for it when
- 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
Choose it when rendering physically recognizable black holes, Einstein rings, or relativistic singularities in real-time VFX, space simulations, or cinematic visualization.
Prefer Ray-marched Participating Media when rays travel in straight lines through ordinary nebulae, clouds, or gas without spacetime curvature. Prefer Sphere Tracing for refractive or warped analytic SDF anomalies where general-relativistic disk crossings and photon rings are unnecessary. Prefer Pseudo lens flare for purely optical camera bloom and diffraction effects without scene deflection.
Field marks
- 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
Presets
Real-time Schwarzschild disk starting parameters
{
"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
}Attribution: written for this index
Schwarzschild Null-Geodesic Lensing — flat Euclidean rays (left) vs curved spacetime photon ring & Doppler disk (right)
{
"P_BH_MASS": 1,
"P_DISK_INCL": 0.22,
"P_DOPPLER_STR": 0.85,
"P_SPLIT": 0.48
}Show GLSL (132 lines)
const float P_BH_MASS = 1.00; // P Horizon Scale [0.6, 1.5, 0.05]
const float P_DISK_INCL = 0.22; // P Disk Inclination [0.08, 0.55, 0.02]
const float P_DOPPLER_STR = 0.85; // P Relativistic Beaming [0.0, 1.4, 0.05]
const float P_SPLIT = 0.48; // P Flat / Geodesic Split [0.0, 1.0, 0.02]
float hash21(vec2 p) {
p = fract(p * vec2(127.1, 311.7));
p += dot(p, p + 34.5);
return fract(p.x * p.y);
}
// Background galactic starfield & faint nebula sampled by asymptotic deflected photon direction d
vec3 evalStarfield(vec3 d) {
d = normalize(d);
float phi = atan(d.z, d.x);
float th = acos(clamp(d.y, -1.0, 1.0));
vec2 g = vec2(phi * 26.0, th * 26.0);
vec2 id = floor(g);
vec2 f = fract(g) - 0.5;
float rnd = hash21(id);
float star = step(0.965, rnd) * exp(-dot(f, f) * 58.0) * (1.2 + 1.8 * hash21(id + 7.3));
vec3 starCol = mix(vec3(0.75, 0.88, 1.0), vec3(1.0, 0.84, 0.65), hash21(id + 3.1));
// Subtle galactic dust band
float band = exp(-pow(d.y * 2.8 + 0.35 * sin(phi * 2.0), 2.0) * 3.5);
vec3 neb = vec3(0.06, 0.09, 0.16) * band + vec3(0.015, 0.02, 0.035);
return neb + starCol * star;
}
// Keplerian accretion disk emission with relativistic Doppler beaming & gravitational redshift
vec3 evalDiskEmission(vec3 pos, vec3 rayDir, float rs, float dopplerK) {
float r = length(pos.xz);
float rIn = rs * 2.15;
float rOut = rs * 6.8;
if (r < rIn || r > rOut) return vec3(0.0);
float ang = atan(pos.z, pos.x);
float omega = 1.65 / max(pow(r, 1.25), 0.2);
float spiral = 0.55 + 0.45 * sin(ang * 4.0 + r * 4.2 - iTime * (1.8 + omega));
float rings = 0.65 + 0.35 * sin(r * 14.0 - iTime * 1.4);
float radialFade = smoothstep(rIn, rIn + 0.25 * rs, r) * smoothstep(rOut, rIn + 1.4 * rs, r);
// Keplerian tangent velocity vector v (counter-clockwise orbiting disk)
vec3 velDir = normalize(vec3(-pos.z, 0.0, pos.x));
float beta = clamp(sqrt(0.5 * rs / max(r, rs * 1.1)), 0.0, 0.62);
float cosA = dot(velDir, -rayDir);
// Relativistic Doppler factor D = 1 / (gamma * (1 - beta*cosA)) -> approaching left side beams blazing blue-white, receding right redshifts!
float doppler = mix(1.0, (1.0 + beta * cosA) / max(1.0 - 0.55 * beta * cosA, 0.35), dopplerK);
float gravRed = sqrt(max(1.0 - rs / max(r, rs * 1.02), 0.08));
float gShift = clamp(doppler * gravRed, 0.25, 2.4);
// Temperature shifts from deep crimson -> blazing gold -> blue-white under gShift
vec3 coldC = vec3(0.95, 0.20, 0.04);
vec3 midC = vec3(1.0, 0.68, 0.24);
vec3 hotC = vec3(0.85, 0.94, 1.0);
vec3 tempCol = mix(coldC, mix(midC, hotC, smoothstep(0.85, 1.75, gShift)), smoothstep(0.35, 1.05, gShift));
float intensity = pow(gShift, 2.4) * radialFade * (0.45 + 0.55 * spiral * rings) * 2.2;
return tempCol * intensity;
}
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 sx = fragCoord.x / max(iResolution.x, 1.0);
float split = clamp(P_SPLIT, 0.0, 1.0);
bool useGeodesic = sx >= split;
float rs = clamp(P_BH_MASS, 0.5, 1.6) * 0.42;
float incl = clamp(P_DISK_INCL, 0.06, 0.65);
float dopplerK = clamp(P_DOPPLER_STR, 0.0, 1.5);
float camDist = 5.4;
vec3 ro = vec3(0.0, camDist * sin(incl), camDist * cos(incl));
vec3 fw = normalize(-ro);
vec3 ri = normalize(cross(fw, vec3(0.0, 1.0, 0.0)));
vec3 up = cross(ri, fw);
vec3 rd = normalize(fw * 1.65 + ri * uv.x + up * uv.y);
// Integrate photon trajectory: null geodesic a = -1.5 * rs * h^2 * p / r^5 (where h = |p x rd| is angular momentum!)
vec3 pos = ro;
vec3 vel = rd;
vec3 hVec = cross(pos, vel);
float h2 = dot(hVec, hVec);
vec3 accCol = vec3(0.0);
bool captured = false;
const int STEPS = 84;
for (int i = 0; i < STEPS; i++) {
float r = length(pos);
if (r < rs * 1.02) { captured = true; break; }
if (r > 14.0) break;
float dt = clamp(r * 0.085, 0.04, 0.35);
vec3 prevPos = pos;
if (useGeodesic) {
// Schwarzschild exact general-relativistic null-geodesic bending force (-3/2 * rs * h^2 / r^5 * pos)
vec3 accel = -1.5 * rs * h2 * pos / max(pow(r, 5.0), 1e-4);
vel = normalize(vel + accel * dt);
}
pos += vel * dt;
// Detect crossing of equatorial accretion disk plane (y == 0)
if (prevPos.y * pos.y <= 0.0 && abs(pos.y - prevPos.y) > 1e-5) {
float f = abs(prevPos.y) / abs(pos.y - prevPos.y);
vec3 hitP = mix(prevPos, pos, f);
accCol += evalDiskEmission(hitP, vel, rs, dopplerK);
}
}
vec3 col = accCol;
if (!captured) {
col += evalStarfield(vel);
}
// Subtle Einstein photon sphere glow near r = 1.5 * rs on geodesic side
if (useGeodesic) {
float bImpact = sqrt(h2);
float bCrit = 2.598 * rs;
float photonRing = exp(-pow((bImpact - bCrit) / (0.045 * rs), 2.0));
col += vec3(1.0, 0.86, 0.62) * photonRing * 0.45;
}
float sep = smoothstep(0.0035, 0.0008, abs(sx - split));
col = mix(col, vec3(0.95, 0.97, 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.
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| schwarzschild-null-geodesic-lensing-live | Tesla T4 1920x1080 | 41.4× baseline (heavy) · 1.36 ms / 1.44 ms | opengl-timer-query · 32 frames · GPU Weight Atlas · Colab T4 sweep |
| schwarzschild-null-geodesic-lensing-live | NVIDIA L4 1920x1080 | 38.8× baseline (heavy) · 0.618 ms / 0.620 ms · 2.2× faster on L4 | opengl-timer-query · Cross-architecture validation |
| schwarzschild-null-geodesic-lensing-live | NVIDIA A100-SXM4-40GB 1920x1080 | 24.4× baseline (heavy) · 0.703 ms / 0.706 ms · 1.9× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
Crosses
- Dual-filter and progressive-downsample bloom: HDR radiance from the Doppler-beamed inner accretion disk and photon ring drives physically convincing optical glare.
- AgX: High-contrast blackbody emission compresses cleanly into display gamut without abrupt hue shifts on the hot approaching limb.
Sources
- primaryOliver James, Eugénie von Tunzelmann, Paul Franklin, Kip S Thorne (2015). Gravitational lensing by spinning black holes in astrophysics, and in the movie <i>Interstellar</i>. Classical and Quantum Gravity.Verified via crossref · 2026-11-30doi:10.1088/0264-9381/32/6/065001
- implementationHumpalumps (2026). Humpalumps/ultra-elements. Real-time elemental spell VFX lab for three.js (WebGL2): 39 tunable spellsGitHub API · license MIT · 2026-11-30