The Geodesic
Inspired by Relativistic chaos on Wikipedia
Built with Three.js · Custom fullscreen ShaderMaterial · RK4 geodesic integrator · Schwarzschild metric
Techniques Per-pixel ray tracing through curved spacetime · Accretion disk with Doppler beaming · Gravitational redshift · Voronoi-based procedural starfield · Adaptive step-size integration
Direction You are the curvature of space.
Result A real-time black hole with gravitational lensing — stars bend into Einstein rings, the accretion disk warps visibly through curved spacetime, and your movement reshapes the universe
The Story
In curved spacetime, there is no such thing as a straight line.
General relativity tells us that mass bends space, and light follows the curvature. A photon traveling near a black hole doesn’t fly past in a straight line — it curves. If it passes close enough, it orbits. Closer still, it spirals inward and is captured forever. The boundary between escape and capture is razor-thin, and at that boundary, light wraps around the black hole multiple times, creating an infinite nested series of Einstein rings.
This is relativistic chaos — the study of chaotic behavior in curved spacetime. Near a black hole, the basin boundary between photon capture and escape forms a fractal. Tiny changes in a photon’s initial direction send it to completely different fates. Some photons orbit once and escape. Others orbit twice, three times, or infinitely. The boundary between these outcomes is infinitely complex.
The Schwarzschild metric describes the simplest possible black hole — non-rotating, uncharged, defined only by its mass. Despite this simplicity, the photon dynamics are rich enough to produce some of the most visually stunning phenomena in physics: the black hole shadow, the photon ring, Einstein arcs, and the warped accretion disk where you can see both the top and underside simultaneously.
The Take
A field of stars on pure black. Your cursor is invisible — but its presence isn’t. Around where you are, space bends. Stars near you stretch into arcs. Stars behind you appear as rings of focused light around your position. At the center, a dark void — the black hole shadow, larger than the event horizon itself, where no photon can escape.
An accretion disk orbits in the equatorial plane — a thin ring of hot matter spiraling inward. From above, it would look like a flat ring. But through curved spacetime, you see something stranger: the far side of the disk bends over the top of the black hole, visible through light that has curved up and over the mass. One side of the disk burns brighter and bluer — the approaching side, Doppler-boosted. The other fades redder — the receding side, redshifted.
Move, and the entire universe reshapes itself around your gravity. The star field distorts, reforms, distorts again. Every position creates a unique lensing pattern. After enough time exploring, text emerges at the periphery — the only place reality isn’t distorted by your presence: “the straightest path through curved space is never a straight line.”
The Tech
Schwarzschild Geodesic Integration
Every pixel of the screen traces a light ray backward from the camera through curved spacetime. This is not an approximation or a visual trick — it’s the actual general relativistic geodesic equation, integrated numerically per pixel per frame.
The core equation is the Schwarzschild geodesic acceleration:
a = -(M/r³) × pos × (1 + 3L²/r²)
Where M is the black hole mass, r is the distance from the center, pos is the ray position, and L = |pos × vel| is the specific angular momentum. The 3L²/r² term is the general relativistic correction — without it, you get Newtonian gravity. With it, photons can orbit and be captured.
Each pixel uses 4th-order Runge-Kutta integration (RK4) with up to 200 steps. This means every frame computes approximately 1.8 million independent RK4 integrations (at 1280×720) — each with 200 steps of 6 function evaluations — for roughly 2 billion floating-point operations per frame. The GPU handles this at 60fps.
Adaptive Step Size
Steps near the black hole must be small (0.015 units) to accurately capture the extreme curvature. Steps far from the black hole can be large (0.6 units) to avoid wasting computation on nearly-straight rays. The step size scales linearly with distance: dt = clamp(r × 0.06, 0.015, 0.6).
Three Termination Conditions
Each ray terminates when it:
- Crosses the event horizon (r < R_s) → pure black
- Escapes to infinity (r > 60) → sample the starfield using the ray’s final direction
- Intersects the accretion disk (crosses y=0 plane at disk radius) → sample disk color
Accretion Disk
The disk extends from the Innermost Stable Circular Orbit (ISCO, r = 3R_s) to 10R_s. Temperature falls as r^(-3/4), creating a color gradient from white-hot at the inner edge through orange to deep red at the outer edge.
Doppler beaming shifts the color and brightness based on the angle between the ray direction and the disk’s orbital velocity. The approaching side is blue-shifted and amplified by D³ (where D is the Doppler factor). The receding side is red-shifted and dimmed. This creates the characteristic asymmetry visible in real black hole images.
Gravitational redshift further dims light from deep in the potential well: the factor √(1 - R_s/r) reduces brightness near the inner edge.
Turbulent spiral structures in the disk are created by layered sinusoidal functions of angle and radius, animated over time.
Gravitational Lensing Effects
The shader naturally produces several observable phenomena without any special code — they emerge from the physics:
- Einstein rings — When a background star is directly behind the black hole, its light bends equally around all sides, forming a complete ring
- Einstein arcs — Slightly off-center stars appear as stretched arcs
- Image doubling — Stars near the critical impact parameter appear at multiple positions
- Photon ring — An accumulation of light at the critical impact parameter (b = 3√3 × M ≈ 5.196M), enhanced with a subtle shader glow
- Black hole shadow — The dark region (larger than the event horizon) where all ray paths lead to capture
Voronoi Starfield
Stars are rendered procedurally using a multi-scale Voronoi-like approach. Four layers at different densities (120, 50, 20, 8 cells) produce a realistic star distribution from dense dim background stars to rare bright foreground stars. Each star is rendered as a sharp exponential point with a subtle glow halo — critically, using Voronoi distance (checking 3×3 cell neighborhoods) rather than grid-cell checks, which would produce visible square artifacts when the starfield is lensed.
Mobile
The step count reduces from 200 to 120 on mobile for performance. Touch interaction maps finger position to the gravitational mass. An idle demo slowly drifts the mass in a circular path after 2 seconds of no interaction.
Source: Relativistic chaos on Wikipedia