This is a fast general relativistic ray-tracing engine built with Rust. The long-term goal is to support relativistic visualisation (e.g. black hole shadows, gravitational lensing, and eventually radiative transfer effects like attenuation) in arbitrary spacetime geometries.
All quantities are in geometrized units (
cargo install nullgeo-cli
This installs the nullgeo binary. Build with --features parallel to enable Rayon-based parallel ray tracing:
cargo install nullgeo-cli --features parallel
cargo add nullgeo
Or in Cargo.toml:
[dependencies]
nullgeo = "0.1"Enable the optional parallel feature for Rayon support: nullgeo = { version = "0.1", features = ["parallel"] }.
nullgeo shadow \
--metric=schwarzschild \
--mass=1.0 \
--width=512 --height=512 \
--fov-deg=30.0 \
--cam-x=-30.0 \
--dl=0.005 \
--max-steps=20000 \
--out=shadow.pgm
The Hamiltonian for photons in GR is
together with the null constraint
where the dot signifies differentiation with respect to an affine parameter
A local tetrad
The spatial unit vectors
A photon with spatial direction
We use Rayon's par_iter_mut() over the image buffer. For each pixel, a worker:
- Initializes the ray state by computing the photon's null covector at the camera position.
- Integrates the equations of motion using a 4th-order Runge-Kutta scheme to obtain the trajectory
$(x^{\mu}(\lambda), p_{\mu}(\lambda))$ . - Applies termination checks, e.g. stopping if the ray falls inside the horizon.
- Writes the pixel value to the grayscale image buffer.