Originally inspired by Ray Tracing in One Weekend (Peter Shirley).
This library cannot be executed as-is, but it can provide tools that pytrace
can then use.
It is also possible to import it from a Rust script: see rstrace
for a concrete example.
Usually a scene would be created from pytrace
or rstrace
, but if one wishes to create
a new generalizable object, then this is the right crate to modify.
To do so, it is recommended to create a new file in the composite
module :
- Create a new file
composite/<object>.rs
- Implement
<object>
by providing abuild
method (more information below) - Integrate the new object with the rest of the program by adding the two lines
pub mod <object>;
andpub use <object>::<Object>;
incomposite/mod.rs
(see examples)
Of course, this project bears some resemblance with the original Ray tracing in one Weekend:
- The name of many types and functions are the same:
internal::hitable::schlick
,internal::camera::Camera::get_ray
,internal::vec3::Vec3
,internal::ray::Ray
,internal::hitable::Hit
,internal::hitable::Texture::Lambertian
. - Some ideas were kept: overloading
std::ops::Mul
forinternal::rgb::RGB
, initialinternal::camera::Camera
abstraction. - Some chunks of code have been translated to Rust almost verbatim:
internal::primitives::Sphere::hit
,internal::hitable::scatter
.
Many other similarities were partially or completely rewritten halfway into the project.
The hit
implementations for many objects were inspired by or debugged with the help of a wide variety of websites: internal::hitable::{EmptyCylinder, EmptyCone, Triangle}
were implemented after comparing the implementations of intersection with a ray from at least a dozen sources, most of which had made widely different design choices and were hard to adapt.
internal::hitable::{InfinitePlane, Disc}
are original implementations, internal::hitable::Parallelogram
was adapted from internal::hitable::Triangle
, and all of the other are merely wrappers.
- All composite objects (
composite::axes::Axes
,composite::cradle::NewtonCradle
,composite::die::Die
,composite::erlenmeyer::Erlenmeyer
,composite::molecules::Molecules
) - The intersection/removal mechanism implemented in
internal::hitable::Interaction
is completely original - Although the first versions of the
internal::hitable::Texture::Dielectric
branch ofinternal::hitable::scatter
were copied, later versions were fully remade from scratch with a completely different, which (unlike the original one) correctly deals with dielectric/dielectric interfaces (seeinternal::world::{scatter, World::caracteristics}
) internal::hitable::HitRecord
was also fully revised- The
internal::sky::Sky
texture - Brand new
internal::camera::Camera
abstraction: instead of(look_from, look_at, upwards, field_of_view_angle, aspect_ratio)
, it is much easier to fine-tune a view with(look_at, angle_around_target, angle_above_target, distance_to_target, tilt, field_of_view_angle, aspect_ratio)
- The original version did not support multithreading
- All scenes visible in
../img/
are of my own creation