A Rust ray tracer for general relativity and black hole visualization.
It solves geodesic equations numerically and renders gravitational lensing, redshift, beaming, accretion disks, and
photon trajectories in Schwarzschild and Kerr spacetimes.
Inspired by 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 BlackHoleViz_v2.
See the Image Gallery for more rendered outputs.
- Multi-geometry ray tracing:
Euclidean,EuclideanSpherical,Schwarzschild,Kerr(Kerr-Schild), andKerrBL(Boyer-Lindquist). - Geodesic integration with RKF45;
KerrBLuses separated equations of motion via Carter's constant (therefore faster thanKerr). - Relativistic shading effects: gravitational and Doppler redshift plus relativistic beaming.
- Physically motivated emission: black-body spectrum integration in CIE XYZ.
- Scene primitives:
Sphere,Disc, and Perlin-noise-basedVolumetricDisc. - Flexible materials and textures: bitmap, checker, and black-body mappers.
- Image output formats: standard image export plus HDR (
.hdr). - Debug and analysis tools: per-pixel ray export and arbitrary ray-at-position export.
- Config-driven scenes through TOML definitions.
Note: VolumetricDisc is primarily a visual effect for accretion-disk appearance rather than a strict physical
model.
- Rust toolchain (
cargo) uvfor Python helper scripts (brew install uvon macOS)
cargo build --releasecargo run --release -- --width=1500 --height=1500 --camera-position=-16.0,0.0,3.5 --theta=-3.142 --psi=0.0 --phi=0.0 --config-file scene-definitions/schwarzschild.toml render --filename=render.png--widthand--height: output resolution.--camera-position: camera location.render: full image render command.--filename: output image path.
Predefined scenes live in scene-definitions as TOML files.
You can swap geometry, textures, and objects by choosing or editing a scene file.
This repository includes helper scripts for rendering workflows, ray export, plotting, and animation.
scripts/rays/create_rays_positions.sh: Generates rays in Schwarzschild spacetime from a position and direction, then writes CSV files torays/.scripts/rays/create_rays_from_camera.sh: Generates Schwarzschild rays starting from a camera and selected pixel, then writes CSV files torays/.
uv run manim scripts/animate-rays/main.py AnimateRaysThis command renders an animation from CSV ray data in rays/.
For the full script catalog and grouped layout, see scripts/Readme.md.
Checkerboard texturing helps visualize lensing and warped geometry.
schwarzschild-black-hole-rays.mp4
flyover_schwarzschild_black_hole_with_accretion_disk.mp4
Background image source: https://commons.wikimedia.org/wiki/File:Messier_object_025.jpg
A Schwarzschild black hole with a spherical object behind it, showing lensing while the camera moves.
schwarzschild_black_hole_lensing_object_behind.mp4
Background image source: https://commons.wikimedia.org/wiki/File:Messier_object_025.jpg
Example render command:
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 renderKerr scenes often require a high --max-steps value because of complex geodesic behavior near the black hole.
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=250Animation of a Kerr black hole with r_s = 1.0 and spin parameter a increasing from 0.0 to 0.5.
- 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
- BlackHoleViz_v2
- Novikov, I. D., & Thorne, K. S. (1973). Astrophysics of black holes. In C. DeWitt & B. S. DeWitt (Eds.), Black Holes (Les Astres Occlus), p. 343. Chapter bibliographic entry, Book record
- https://commons.wikimedia.org/wiki/File:Messier_object_025.jpg
This project is licensed under the terms in LICENSE.





