A real-time 3D black hole simulation with gravitational wave radiation, orbital inspiral, tidal disruption, and spacetime curvature visualization, written in Rust using WGPU.
- Real-time N-body simulation with Newtonian gravity + 2.5PN post-Newtonian corrections
- Gravitational wave radiation reaction (Peters 1964): binary inspiral → plunge → merger
- Schwarzschild spacetime distortion via Tendex lines (tidal tensor visualization, ribbon rendering with intensity-driven thickness)
- Three-orthogonal-planes mode for cleaner cross-section visualization of tidal fields
- Binary black hole photon sphere deformation due to companion perturbation
- Tidal disruption and event horizon absorption with Hills-mass branching
- Gravitational wave retarded propagation: radiative field at speed c, near-field instantaneous
- Trajectory prediction with radiation damping
- Spawn safety validation: real-time checks against event horizons, merger thresholds, Roche limits and body overlap when adding black holes/bodies — prevents instant mergers/absorption/collisions; one-click "Safe Pos" auto-avoidance
- Instanced rendering for efficient trail and debris visualization
The simulation uses Tendex lines to visualize spacetime curvature, based on Owen et al. (2011, arXiv:1012.4869).
The "electric" part of the curvature tensor
where
At each spatial sample point, we compute the three eigenvalues and eigenvectors of
- Red lines: positive eigenvalue direction (tidal stretching)
- Blue lines: negative eigenvalue direction (tidal compression)
- Line length: fixed at
$\frac{2}{3} \times \text{grid spacing}$ (1/3 on each side, leaving 1/3 gap between adjacent grid points) - Line thickness and opacity: modulated by
$\sqrt{|\lambda|}$ (intensity), so stronger tidal forces produce thicker, brighter lines
Since
Rendering: Lines are rendered as camera-facing quad ribbons (TriangleList topology, 2 triangles = 6 vertices per line), with intensity driving both thickness (
Three-orthogonal-planes mode: Instead of rendering the full 3D volume of grid points, you can toggle to show only the three central orthogonal planes (XY, YZ, XZ), producing a cleaner cross-section view. The grid center follows the mass-weighted centroid of all black holes with a smooth response (0.15 per frame, ~7 frames to 95%).
Binary systems lose orbital energy to gravitational wave radiation, causing inspiral and eventual merger. Based on the classic Peters (1964) formula:
Energy loss rate:
Semi-major axis decay rate:
Equivalent relative drag acceleration (natural units G=c=1):
Split to two bodies (center-of-mass frame, accelerations are Galilean-invariant):
where
Application: applied to black-hole pairs, body-black-hole pairs, and debris-black-hole pairs.
Plunge phase enhancement: when
Binary black hole inspiral ends at the ISCO (Innermost Stable Circular Orbit), followed by a rapid plunge phase.
ISCO criterion (Blanchet & Iyer 2003, 3PN):
where
- Test-particle limit (
$\nu \to 0$ ):$r_{\text{ISCO}} = 6GM/c^2 = 3(r_{s1}+r_{s2})$ - Equal-mass (
$\nu = 1/4$ ): numerical relativity gives$r_{\text{ISCO}} \approx 5M$
This simulator's merger condition:
Physically, ISCO ≈
Mass loss: the merged black hole has mass
Isolated Schwarzschild black hole photon sphere radius and critical impact parameter:
Companion perturbation (Erdl & Schneider 1993; Patil et al. 2016 arXiv:1610.04863; Cunha et al. 2018 arXiv:1805.03798):
Let the primary black hole have mass
Monopole perturbation (overall compression):
Quadrupole tidal perturbation (angle-dependent deformation):
where
Calibration constants:
Physical effect: the photon sphere is elongated toward the companion and compressed on the far side; when
Standard GR result: gravitational waves propagate exactly at the speed of light
Observational constraint (GW170817/GRB 170817A, Abbott et al. 2017):
Retarded time (Blanchet 2014, Eq. 219):
The radiative field at observation point
Near-field vs. radiative field (2.5PN expansion structure):
| Component | Distance dependence | Propagation |
|---|---|---|
| Near-field (Newtonian-like) | Instantaneous in Newtonian limit (PN 0th order) | |
| Radiative (gravitational wave) | Strictly at |
In this simulator:
- Newtonian tidal field (Tendex static part) uses instantaneous positions (PN 0th order)
- Gravitational wave radiative field uses retarded time
$t_{\text{ret}} = t - r/c$ -
WAVE_SPEED = c = 1(natural units) - Grid eigenvalue temporal smoothing factor 0.3, approximating PN tail terms (
$\propto 1/c^2$ ) hereditary effect
Roche limit (Rees 1988, Hills 1975):
Condition for disruption outside horizon:
Equivalently, a density criterion:
Hills mass
-
$M_{\text{bh}} < M_H$ : Sun-like stars are disrupted outside the horizon (producing tidal disruption events, TDEs) -
$M_{\text{bh}} > M_H$ : stars cross the horizon intact and are swallowed whole
This simulator's branching logic:
- If
$d_{\text{Roche}} > r_s$ (large/low-density bodies): Roche disruption path, producing 60 debris particles forming an accretion disk around the black hole - If
$d_{\text{Roche}} < r_s$ (compact bodies like neutron stars, white dwarfs): direct absorption
Debris disk formation: When a body is tidally disrupted, debris forms a prograde accretion disk around the black hole centered at the black hole position, with orbital radius ≥ 1.5 × ISCO radius (ensuring debris spawns outside the event horizon, even if the body was already inside). Particles follow Keplerian orbital velocities and gradually spiral in via gravitational wave radiation reaction.
Implements both plus (+) and cross (×) polarization modes (Maggiore 2008):
where
Chirp mass:
TT-gauge strain tensor (with polarization angle
In the weak-field limit, curvature tensors from multiple sources superpose linearly:
All mass sources (black holes and ordinary bodies) produce tidal effects, superposed with the dynamic gravitational wave oscillation.
src/
├── main.rs # Application entry, event loop, ApplicationHandler
├── ui.rs # egui panel, axis gizmo, spawn safety indicators
├── camera.rs # Camera control and perspective projection
├── geometry.rs # Sphere/torus geometry generation
├── physics/
│ ├── mod.rs # Simulation struct, gw_radiation_reaction (Peters formula)
│ ├── integrator.rs # Shared gravity integrator (live sim & trajectory prediction)
│ ├── spawn.rs # Spawn validation: prevent instant merger/absorption/collision
│ ├── grid.rs # Tendex lines: tidal tensor computation and eigendecomposition
│ ├── collision.rs # Black hole merger (ISCO), horizon absorption (Hills), Roche disruption
│ └── trajectory.rs # Trajectory prediction (with radiation damping)
└── renderer/
├── mod.rs # Renderer struct, render method
├── types.rs # Vertex/Uniform structs, constants
├── shaders.rs # WGSL shaders (with photon sphere deformation)
└── pipeline.rs # Render pipeline and buffer creation
-
physics/mod.rs - Core physics:
-
gw_radiation_reaction()- Peters 1964 formula implementation, with plunge phase enhancement -
update_debris()- Debris gravity + radiation damping updates -
center_of_mass()- Mass-weighted center of mass of all black holes (shared by camera & grid)
-
-
physics/integrator.rs - Shared gravity integrator:
-
step_gravity()- Single shared time-step for black holes & bodies; used by both the live simulation and trajectory prediction, so previews match actual evolution exactly
-
-
physics/spawn.rs - Spawn validation & auto-avoidance:
-
check_black_hole_spawn() / check_body_spawn()- Reject positions inside event horizons, merger thresholds, Roche limits, or overlapping bodies (with a 20% safety margin) -
safe_black_hole_pos() / safe_body_pos()- Nudge a conflicting position to the nearest safe spot
-
-
physics/grid.rs - Tendex line spacetime curvature visualization:
-
compute_tidal_tensor()- Computes tidal tensor$E_{jk}$ (with retarded GW contribution) -
update_grid_points()- Eigendecomposition + temporal smoothing (approximating PN tail terms) -
get_tendex_render_data()- Generates camera-facing quad ribbon vertices (intensity-driven thickness & opacity, three-planes mode)
-
-
physics/collision.rs - Collisions and evolution:
-
check_mergers()- ISCO-based merger criterion -
check_event_horizon_absorption()- Hills-mass branching: disruption vs. absorption -
check_roche_disruption()- Roche-limit disruption producing accretion disks -
check_body_collisions()- Body collision fragmentation based on Q*_D scaling law
-
-
renderer/shaders.rs - WGSL shaders:
-
perturbed_photon_sphere()- Photon sphere deformation (companion perturbation) -
compute_lensed_direction()- Gravitational lensing ray bending -
star_field()- Procedural starfield (with Milky Way band, nebulae)
-
# Build with optimizations
cargo build --release
# Run
cargo run --release# Install wasm32 target
rustup target add wasm32-unknown-unknown
# Install wasm-bindgen-cli
cargo install wasm-bindgen-cli
# Build wasm release
cargo build --release --target wasm32-unknown-unknown --features web
# Generate JS bindings into dist/
wasm-bindgen --out-dir dist --target web target/wasm32-unknown-unknown/release/blackhole_sim.wasm
# Copy index.html
cp static/index.html dist/
# Serve locally (Wasm requires an HTTP server, cannot use file://)
cd dist && python -m http.server 8080
# Open http://localhost:8080/The web build uses the WebGL2 backend via wgpu for broad browser compatibility.
- Mouse: Rotate camera
- Scroll: Zoom in/out
- UI Panel: Add black holes/bodies, adjust parameters, toggle visualization options
- Spawn positions are validated in real time: the Add button is disabled with the reason shown when too close to an existing black hole/body (event horizon, merger threshold, Roche limit, or overlap); click 🛡 Safe Pos to auto-nudge to a safe location
- Gravity Waves: Toggle Tendex grid visualization
- Three Orthogonal Planes: Show only XY/YZ/XZ central planes (cleaner cross-section)
- Grid Size / Spacing: Adjust grid resolution and physical scale
- Space: Pause/resume
- ESC: Exit
- Peters, P. C. (1964). "Gravitational Radiation and the Motion of Two Point Masses." Physical Review, 136(4B), B1224-B1232. — Core formula source
- Blanchet, L. (2014). "Gravitational Radiation from Post-Newtonian Sources and Inspiralling Compact Binaries." Living Reviews in Relativity, 17, 2. arXiv:1310.1528. — PN expansion and retardation
- Blanchet, L. & Iyer, B. R. (2003). "Third post-Newtonian dynamics of compact binaries." Class. Quantum Grav., 20, 755. — 3PN ISCO criterion
- Blanchet, L., Langlois, K. & Ligout, P. (2025). "ISCO of arbitrary-mass compact binaries at fourth post-Newtonian order." arXiv:2505.01278. — 4PN ISCO
- Buonanno, A., Cook, G. B. & Pretorius, F. (2007). "Inspiral, plunge, merger, ringdown waveform of black-hole binaries." Phys. Rev. D, 75, 124018. arXiv:gr-qc/0610122.
-
Barack, L. & Sago, N. (2007). "Gravitational self-force on a particle in circular orbit around a Schwarzschild black hole." Phys. Rev. D, 75, 064021. — GSF ISCO offset
$\alpha = 1.2512$ - Favata, M. (2010). "Conservative self-force correction to the innermost stable circular orbit." Phys. Rev. D, 83, 024028.
-
Synge, J. L. (1966). "The escape of photons from gravitationally intense stars." Mon. Not. R. Astron. Soc., 131, 463. —
$b_c = 3\sqrt{3} M$ - Erdl, H. & Schneider, P. (1993). "The gravitational lensing in the binary black hole system." Astronomy & Astrophysics, 268, L9. — Binary black hole lensing
- Patil, S. P., Mishra, M. & Narasimha, B. P. (2016). "Curious case of gravitational lensing by binary black holes." arXiv:1610.04863. — Dual photon sphere merger
- Cunha, P. V. P., Herdeiro, C. A. R. & Rodriguez, M. J. (2018). "Shadows of exact binary black holes." Phys. Rev. D, 98, 044053. arXiv:1805.03798.
- Assumpção, T. et al. (2018). "Black hole binaries: ergoregions, photon surfaces, wave scattering." arXiv:1806.07909.
- Weinberg, S. (1972). Gravitation and Cosmology. Wiley. — Deflection angle formula
- Keeton, C. R. & Petters, A. O. (2005). "Formalism for testing theories of gravity using lensing by compact objects." Phys. Rev. D, 72, 104006. — Second-order deflection
- Einstein, A. (1916, 1918). "Näherungsweise Integration der Feldgleichungen / Über Gravitationswellen." Sitzungsber. K. Preuss. Akad. Wiss. — GWs propagate at c
-
Abbott, B. P. et al. (2017). "Gravitational Waves and Gamma-Rays from a Binary Neutron Star Merger: GW170817 and GRB 170817A." Astrophysical Journal Letters, 848, L13. —
$v_{\text{gw}} = c$ to$10^{-15}$ - Will, C. M. (1998). "Bounding the mass of the graviton using gravitational-wave observations." Phys. Rev. D, 57, 2061. arXiv:gr-qc/9709011.
- Rees, M. J. (1988). "Tidal disruption of stars by black holes of 10⁶–10⁸ solar masses." Nature, 333, 523-528. — Hills mass
- Hills, J. G. (1975). "Possible power source of Seyfert galaxies and QSOs." Nature, 254, 295-298.
- Kesden, M. (2012). "Tidal-disruption rate of stars by spinning supermassive black holes." Phys. Rev. D, 86, 064026. — Spin dependence
- Stone, N. C., Kesden, M., Cheng, R. M. & van Velzen, S. (2019). "Stellar Tidal Disruption Events in General Relativity." Gen. Rel. Grav., 51, 30. arXiv:1801.10180.
- Owen, R. et al. (2011). "Frame-Dragging Vortexes and Tidal Tendexes Attached to Colliding Black Holes." Physical Review Letters, 106, 151101. arXiv:1012.4869. — Tendex lines
- Nichols, D. A. "Visualizations of Spacetime Curvature." https://dnichols1.github.io/visualizations/
- Maggiore, M. (2008). Gravitational Waves. Volume 1: Theory and Experiments. Oxford University Press.
- Misner, C. W., Thorne, K. S. & Wheeler, J. A. (1973). Gravitation. W. H. Freeman.
- Poisson, E. & Will, C. M. (2014). Gravity: Newtonian, Post-Newtonian, Relativistic. Cambridge University Press.
- Hamilton, A. J. S. & Lisle, J. P. (2008). "The river model of black holes." Am. J. Phys., 76, 519-532. arXiv:gr-qc/0411060.
- Abbott, B. P. et al. (2016). "Observation of Gravitational Waves from a Binary Black Hole Merger." Physical Review Letters, 116(6), 061102. — GW150914 first detection
MIT License
