This is a raytracer for general relativity, which can be used to visualize the effects of gravity on light paths. It is based on the principles of general relativity and uses numerical methods to solve the geodesic equations.
It is inspired by the paper Seeing relativity -- I. Ray tracing in a Schwarzschild metric to explore the maximal analytic extension of the metric and making a proper rendering of the stars and takes various formulas from it. Additional inspiration came from BlackHoleViz_v2.
There are various predefined geometries, defined via TOML-files:
scene-definitions/euclidean-spherical.tomlscene-definitions/euclidean.tomlscene-definitions/schwarzschild.tomlscene-definitions/kerr.tomlscene-definitions/schwarzschild-volumetric-streaky.tomlscene-definitions/schwarzschild-volumetric-stony.tomlscene-definitions/schwarzschild-volumetric-dense.tomlscene-definitions/kerr-volumetric-streaky.tomlscene-definitions/kerr-volumetric-stony.toml
These can be used to render an image of the described setup via
cargo run --release -- --width=1500 --height=1500 --camera-position=10.0,0.0,0.8 --config-file scene-definitions/schwarzschild.toml render --filename=render.png
where --width and --height define the resolution, the camera position can be adapted via --camera-position.
Call the command render to render a full image which will be saved to a file given by --filename.
There are various scripts. Some of them create importable CSV files, others create images and animations based on Manim.
scripts/create_rays_positions.sh: Creates rays in a Schwarzschild metric based on a given position and direction and saves them to a CSV file in the directoryrays/.scripts/create_rays_from_camera.sh: Creates rays in a Schwarzschild metric using the camera given its position and a selected pixel. The data will be saved to a CSV file in the directoryrays/.
Running python -m manim scripts/animate-rays/main.py AnimateRays will create an animation of the rays saved in
CSV files in the directory rays/.
Plot of the Schwarzschild solution with a accretion disk using a checkerboard texture to visualize the relations.

schwarzschild-black-hole-rays.mp4
flyover_schwarzschild_black_hole_with_accretion_disk.mp4
The background is: https://commons.wikimedia.org/wiki/File:Messier_object_025.jpg
This shows a Schwarzschild black hole with a spherical object behind it and its lensing effects when moving around.
schwarzschild_black_hole_lensing_object_behind.mp4
The background is: https://commons.wikimedia.org/wiki/File:Messier_object_025.jpg
The parameters are
gr_raytracer --width=500 --height=500 --max-steps=1000000 --camera-position=-10,0,-0.5 --theta=1.52 --psi=-1.57 --phi=0 --config-file scene-definitions/kerr.toml renderNote the large number of max-steps required to get a good image, due to the complex light paths around a Kerr black hole.
Example of a Kerr black hole with a radius r_s = 1.0 and a = 0.5.
Create a trajectory near the horizon like this:
gr_raytracer --width=501 --height=501 --max-steps=1000000 --camera-position=-5,0,0.5 --theta=1.57 --psi=1.57 --phi=0 --config-file scene-definitions/kerr.toml render-ray --col=195 --row=250Example of a trajectory of Kerr black hole with a radius r_s = 1.0 and a = 0.5 near the horizon.
Example of a Kerr black hole with a radius r_s = 1.0 and a = 0.51.
This animations shows a Kerr black hole with r_s = 1.0 and increasing spin parameter a from 0.0 to 0.5.



