This is a simple Rust implementation of Peter Shirley's “Ray Tracing in One Weekend.”
Compared to the original C++ version this version
- Has a slightly nicer scene (fewer intersections/collisions and no floating spheres)
- Doesn't contain oodles of memory leaks 😉 (Rust memory safety FTW)
- Writes a binary BMP instead of an ASCII PPM, because text formats are never the right choice IMNSHO
- Has some simple parallelization using rayon via ndarray
- Uses external crates such as nalgebra for
Vec3
and has fewer roll-your-own data structures in general
Compared to other Rust versions [1, 2] I chose to stick closer to the C++ original in that the code uses trait objects for runtime polymorphism instead of enums, i.e., my list of hittables is a
Vec<Box<dyn Hittable + Sync>>
instead of a
Vec<Sphere>
and the material reference in the Sphere
object is an
Arc<dyn Material + Send + Sync>
instead of something like
pub enum Material {
Lambertian(Lambertian),
Metal(Metal),
Dielectric(Dielectric),
}
where the Send
and Sync
constraints are for parallelization.
The choice to use trait objects was mainly because this was an exercise in using Rust's trait objects for me 😄.
There is currently one line of unsafe
code in here, probably because I used rayon/ndarray incorrectly.
Suggestions are welcome.
When the use_oidn
feature is enabled, raytracing-weekend-rs
uses Intel®'s Open Image Denoise library via Will Usher's oidn-rs bindings to reduce the amount of noise.
When enabled, the OIDN_DIR
environment variable must be set to the root of the Open Image Denoise installation for building and Path
/LD_LIBRARY_PATH
must be set so that the corresponding DLLs/SOs are found at runtime.