Skip to content

erichenschel/black-hole-lensing-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Black Hole Lensing in C++

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.

Renders

Accretion disk lensing (GPU path)

Centered black hole with lensing arcs

Build

SDL2 is required. On this Mac it is already available through Homebrew/pkg-config.

make

Run

./black-hole-lensing

Controls:

  • 1 - 3D lensing/accretion-disk view
  • 2 - 2D ray-trail view
  • Left-drag - move the black hole through the simulation
  • Mouse wheel - increase/decrease black-hole mass
  • Left/Right - orbit camera
  • Up/Down - tilt camera
  • A - toggle auto orbit
  • + / - - increase/decrease black-hole strength
  • , / . - shrink/grow the event horizon
  • [ / ] - decrease/increase integration steps
  • R - reset black-hole position and strength
  • S - save black-hole-frame.ppm
  • Esc - quit

Generate a still frame without opening the interactive loop:

./black-hole-lensing --ppm black-hole.ppm 960 640

Generate a still frame through the GPU shader:

./black-hole-lensing --gpu-ppm black-hole-gpu.ppm 960 640

You can also render a shifted black hole for testing:

./black-hole-lensing --ppm shifted.ppm 960 640 0.7 0.2 0.0

What It Shows

  • 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.

About

Gravitational lensing visualization in C++/SDL2 — RK4 null-ray integrator, accretion-disk lensing arcs, CPU and GPU render paths

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages