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
- 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.
Getting it running locally is straightforward – you just need Node.js and npm.
- Node.js and npm.
From the project root (black-hole-simulation):
npm installnpm startThen open the URL printed in the console (http://localhost:8080/) in your browser.
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.
- 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 (
RESOLUTIONinconfig.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.
- depends on resolution (
- 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.
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:
- https://rantonels.github.io/starless/ - online simulator of black hole with good introduction and explanations.
- https://www.youtube.com/watch?v=8-B6ryuBkCM&t=1s - how author implemented it in C++ from scratch. Good examples on how to put physic equations into code.
- https://testtubegames.com/blackhole.html - a simple online simulator where you can see black hole neighborhood slows down time. It’s a good playground to get intuition about the effects of general relativity.
- https://oseiskar.github.io/black-hole/ - astonishing simulation of black hole with relativistic beaming and gravitational redshift. Very accurate and well optimized.
- https://arxiv.org/pdf/1502.03808 - reproduction of Interstellar black hole.
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.



