Skip to content

Examplio/black-hole

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Relativistic Black Hole Simulation

A real-time, interactive simulation of a supermassive black hole with an accretion disk, gravitational lensing, and N-Body physics. Built with Rust and Bevy Engine.

Black Hole Preview Simulation picture

Features

  • Raymarching Rendering: Custom WGSL shader rendering a volumetric accretion disk.
  • Gravitational Lensing: Simulates the bending of light rays near the event horizon using geodesic approximations.
  • Relativistic Doppler Effect: Visualizes redshift (dimmer/redder) and blueshift (brighter/bluer) caused by the relativistic speed of the disk's rotation.
  • N-Body Physics: Planets interact with the black hole and each other using Newton's Law of Universal Gravitation.
  • Procedural Generation: The accretion disk texture and star field are generated procedurally on the GPU.

Physics & Math

1. Gravitational Lensing

The light path is bent towards the singularity as it passes through the gravity well. In the shader, this is approximated by iteratively modifying the ray direction vector $\vec{D}$:

$$\vec{D}_{new} = normalize(\vec{D}_{old} + \vec{V}_{center} \cdot \frac{k}{r^2})$$

Where $r$ is the distance to the singularity and $k$ is a lensing constant derived from the mass.

2. Relativistic Beaming (Doppler Effect)

Matter in the accretion disk rotates at relativistic speeds. Light emitted by matter moving towards the observer appears brighter and bluer (blueshift), while matter moving away appears dimmer and redder (redshift).

The intensity shift $I$ is approximated by the Doppler factor $\delta$:

$$I \propto \delta^4$$ $$\delta = \frac{1}{\gamma (1 - \beta \cos \theta)}$$

In the simulation, this results in the iconic "bright side" and "dim side" of the accretion disk.

3. Orbital Mechanics

Planets are initialized with a velocity vector perpendicular to the radius to achieve a stable circular orbit:

$$v_{orbit} = \sqrt{\frac{G M}{r}}$$

The simulation uses a Symplectic Euler integrator for stable orbital evolution.

Controls

Input Action
Left Mouse Button + Drag Rotate the camera
Mouse Wheel Zoom in / out

Installation & Run

Ensure you have Rust installed.

  1. Clone the repository:

  2. Run the project in release mode (recommended for high FPS):

    cargo run --release

    or

    cargo run

📦 Tech Stack

  • Language: Rust
  • Engine: Bevy 0.14
  • Shaders: WGSL (WebGPU Shading Language)

Created as a project to study astronomy in programming

About

Simple simulation built with Rust + WGSL

Topics

Resources

Stars

Watchers

Forks

Contributors