Mathematical Background
Einstein's Field Equations
The foundation of General Relativity is Einstein's field equations, which relate the curvature of spacetime to the distribution of matter and energy:
Rμν - ½Rgμν + Λgμν = (8πG/c4)TμνWhere:
Rμνis the Ricci curvature tensorRis the scalar curvaturegμνis the metric tensorΛis the cosmological constantTμνis the stress-energy tensor
The Schwarzschild Solution
For a non-rotating, spherically symmetric mass (like an idealized black hole), Karl Schwarzschild found an exact solution to Einstein's equations. The Schwarzschild metric in standard coordinates is:
ds2 = -(1 - rs/r)c2dt2 +
(1 - rs/r)-1dr2 + r2dΩ2Where:
rs = 2GM/c2is the Schwarzschild radiusGis the gravitational constantMis the mass of the objectcis the speed of lightdΩ2 = dθ2 + sin2θ dφ2
The Schwarzschild radius defines the event horizon - the boundary where spacetime curvature becomes so extreme that nothing can escape.
Geodesic Equations
Objects moving through curved spacetime follow geodesics - the "straightest possible" paths. The geodesic equation is:
d2xμ/dτ2 + Γμαβ(dxα/dτ)(dxβ/dτ) = 0Where:
τis the proper time along the pathΓμαβare the Christoffel symbols (computed from the metric)
Keplerian Orbits
In flat spacetime (Stage 1), planets follow elliptical orbits described by Kepler's equations. For an ellipse with semi-major axis a and eccentricity e, the position is:
r = a(1 - e cos E)Where E is the eccentric anomaly, found by solving Kepler's equation:
M = E - e sin E(M is the mean anomaly, which increases linearly with time)
Simplified Warping Function
For educational purposes, this visualization uses a simplified warping function inspired by the Schwarzschild metric. The actual implementation maps flat coordinates to warped coordinates using:
r' = r · (1 - w · rs/r · e-r/λ)Where:
ris the distance from the centerwis the warp factor (0 to 1, stage-dependent)rsis proportional to the massλis a scale length for smooth falloff
This creates the characteristic "funnel" shape while remaining computationally efficient for real-time rendering.
Color Mapping: Gravitational Potential
The color gradient represents the Newtonian gravitational potential (a useful approximation):
Φ(r) = -GM/rThis is normalized and mapped to colors: deep blue (low |Φ|) → cyan → yellow → orange → red (high |Φ|). Near the event horizon, colors shift toward red-orange, indicating extreme gravitational energy density.
Numerical Implementation
Key computational techniques used:
- All trajectories computed using Newton-Raphson iteration for Kepler's equation
- Float32Array buffers (Typed Arrays) for efficient GPU transfer
- WebGPU storage buffers hold thousands of grid line segments
- Each segment rendered as a GPU instance with minimal CPU overhead