A compact C++/SDL2 recreation of the video idea: rays bend around a black hole, an accretion disk produces lensing arcs, and a second mode shows 2D ray trails falling into or orbiting the event horizon.
This is a didactic visualization, not a scientific general-relativity solver. It uses a simplified null-ray style integrator with RK4 so the whole thing stays small and easy to inspect.
The interactive 3D lensing mode runs in an OpenGL fragment shader: every pixel traces its own ray on the GPU. The 2D ray-trail mode stays CPU-rendered and is uploaded as a texture.
SDL2 is required. On this Mac it is already available through Homebrew/pkg-config.
make./black-hole-lensingControls:
1- 3D lensing/accretion-disk view2- 2D ray-trail view- Left-drag - move the black hole through the simulation
- Mouse wheel - increase/decrease black-hole mass
Left/Right- orbit cameraUp/Down- tilt cameraA- toggle auto orbit+/-- increase/decrease black-hole strength,/.- shrink/grow the event horizon[/]- decrease/increase integration stepsR- reset black-hole position and strengthS- saveblack-hole-frame.ppmEsc- quit
Generate a still frame without opening the interactive loop:
./black-hole-lensing --ppm black-hole.ppm 960 640Generate a still frame through the GPU shader:
./black-hole-lensing --gpu-ppm black-hole-gpu.ppm 960 640You can also render a shifted black hole for testing:
./black-hole-lensing --ppm shifted.ppm 960 640 0.7 0.2 0.0- A black event horizon with a glowing accretion disk.
- Background stars warped by ray bending.
- RK4 integration so rays curve smoothly instead of taking jagged Euler-style steps.
- GPU fragment-shader orchestration for the 3D lensing mode, with uniforms for black-hole position, mass, horizon, camera, and integration steps.

