Skip to content

KubaSlowikowski/Black-hole-simulation

Repository files navigation

Ray-traced simulation of a black hole

This project is an interactive 3D visualization of how light bends around a non-rotating (Schwarzschild) black hole. Under the hood, it uses JavaScript with Three.js and GLSL shaders to numerically solve the equations that describe photon motion in curved spacetime.

In simple terms: it's a playground where you can see how general relativity bends light rays near a black hole.

Check out my YouTube video where I explain the physics and implementation details of the project: https://www.youtube.com/watch?v=PSfaJSl_aVg

Black Hole Animation

Overview

  • You look at a black hole surrounded by a thin, glowing accretion disc and a distant starry sky.
  • Light rays (photons) are not forced to go straight – their paths are bent by the gravity of the black hole, according to general relativity.
  • For every pixel on the screen, the shader calculates photon's path in curved spacetime.

How to run the project

Getting it running locally is straightforward – you just need Node.js and npm.

Requirements

  • Node.js and npm.

Install dependencies

From the project root (black-hole-simulation):

npm install

Start the development server

npm start

Then open the URL printed in the console (http://localhost:8080/) in your browser.

Controls

You control the camera with the mouse:

  • Left mouse button – rotate the camera.
  • Right mouse button – move the camera.
  • Mouse wheel / trackpad scroll – zoom in and out.

Every time you move the camera, the photon paths are recomputed for the new viewpoint.

Limitations and scope

  • The simulation uses a pure Schwarzschild black hole model:
    • no rotation,
    • no electric charge,
  • The accretion disc is a simplified thin disc:
    • relativistic beaming and redshift are not modeled in detail, so the disc brightness and color change are not affected by these effects.
  • Performance:
    • depends on resolution (RESOLUTION in config.js), the maximum number of steps, and bloom settings.
    • the main goal of this project was to generate physically accurate image. The Application calculates the whole curved path for each pixel in every frame, which makes it slow. I didn't focus on optimization, so there are many possible improvements.
  • If a user moves the camera to far from the black hole, the image will look weird because of ray-tracing maximum distance.
  • The mathematical model uses polar coordinates, near the poles of the black hole numerical errors may occur and become visible in the simulation.
  • RK4 integration uses a finite step size, so extreme parameter choices can still lead to numerical artifacts (especially close to the black hole poles).

Despite these simplifications, the project already shows the key features of general relativity near a black hole: the shadow, the photon sphere, and the strong lensing of both the accretion disc and the background sky.

Want to learn more?

If you want to connect what you see on the screen with the physics equations or simply learn more, these are good starting points. I based my learning path on those:

This project is meant as a bridge between abstract physics and something you can see and interact with: you can move the camera, watch how light bends and simple play with it.

About

3D simulation of black hole

Topics

Resources

License

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors