raytracer_in_a_weekend
is my attempt at making a ray-tracer while following along the excellent Ray Tracing in One Weekend guide. It also served as a good mini-project to brush up my Rust skills.
The provided demo (in random.rs) renders a randomly generated scene. The scene consists of a collection of spheres with one of 4 types of materials:
- Lambertian (matte)
- Light
- Metal
- Dielectric (glass)
These things weren't covered in Ray Tracing in One Weekend but I added them anyway ¯\_(ツ)_/¯:
- Multi-threading using
rayon
- Planes
- Light emitting materials
- Textures: images (PNG and JPEG) and linear gradients
- SkyBoxes: both cubemaps and equirectangular images
- Normal mapping
- Tone-mapping
- Scene serialization/deserialization via JSON files
-
Ensure you've setup
cargo
properly. -
cd
to the project's root directory. -
There are 2 binaries:
gen_random_balls
- Exports a randomized scene full of spheres as a JSON file
- You can control scene generation by providing an optional seed
- Run by doing
cargo run --release --bin gen_random_balls > <scene-json-file>
custom
- Renders a scene by reading its description from a JSON file
- Takes in optional ray tracing parameters as CLI arguments
- Run by doing
cargo run --release --bin custom -- --scene <scene-json-file>
You can view all the command line arguments by doing
cargo run --release --bin <binary-name> -- -h
NOTE: Rendering is CPU intensive. To speed things up,
rayon
will try to use as many CPU cores as possible. A progress bar will be shown to ensure that you're not left waiting blindly. -
The rendered scene will be saved as
scene.png
(or whatever path you specified in the optionaloutput
CLI argument).
I've created an imgur album to host the sample images. You can find some of the images from that album below.