Skip to content

General relativity ray tracer in Rust for visualizing geodesics, gravitational lensing, and e.g. Schwarzschild black holes.

License

Notifications You must be signed in to change notification settings

mdreem/gr_raytracer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

345 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

General Relativity Raytracer

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.

How to render an image

There are various predefined geometries, defined via TOML-files:

  • scene-definitions/euclidean-spherical.toml
  • scene-definitions/euclidean.toml
  • scene-definitions/schwarzschild.toml
  • scene-definitions/kerr.toml
  • scene-definitions/schwarzschild-volumetric-streaky.toml
  • scene-definitions/schwarzschild-volumetric-stony.toml
  • scene-definitions/schwarzschild-volumetric-dense.toml
  • scene-definitions/kerr-volumetric-streaky.toml
  • scene-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.

Scripts

There are various scripts. Some of them create importable CSV files, others create images and animations based on Manim.

Create rays to be plotted.

  • 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 directory rays/.
  • 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 directory rays/.

Plot rays.

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

Examples

Plot of a Schwarzschild black hole with a accretion disk

Plot of the Schwarzschild solution with a accretion disk using a checkerboard texture to visualize the relations. alt text

Video of rays in a Schwarzschild metric

schwarzschild-black-hole-rays.mp4

Video of flying over a Schwarzschild black hole

flyover_schwarzschild_black_hole_with_accretion_disk.mp4

The background is: https://commons.wikimedia.org/wiki/File:Messier_object_025.jpg

Video of lensing due to a Schwarzschild black hole

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

Examples

Kerr black hole with accretion disk

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 render

Note the large number of max-steps required to get a good image, due to the complex light paths around a Kerr black hole.

Example 1

Example of a Kerr black hole with a radius r_s = 1.0 and a = 0.5.

alt text

Trajectories

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=250

Example of a trajectory of Kerr black hole with a radius r_s = 1.0 and a = 0.5 near the horizon.

alt text

Example 2

Example of a Kerr black hole with a radius r_s = 1.0 and a = 0.51.

alt text

Animation of increasing spin parameter a of Kerr black hole

This animations shows a Kerr black hole with r_s = 1.0 and increasing spin parameter a from 0.0 to 0.5.

alt text