Simple ray tracer written in Rust following Ray Tracing in One Weekend.
vec3.rs
:- implements
Vec3
, which represents both positions and offsets in space, along with helper functions such asnormalize
,interpolate
,reflect
,refract
, andrandom_in_unit_sphere
; - aliases
Vec3
asColor
, which represents color vectors with components between 0 and 1; and - implements
Ray
, which represents rays in space.
- implements
hittable.rs
:- implements
HitRecord
, which represents information about aRay
-Hittable
intersection such as point of intersection, unit normal, and intersection material; - introduces
Hittable
, which describes objects that can be hit and produceHitRecord
's; - implements
HittableList
, whichimpl Hittable
and represents collections ofHittable
's; and - implements
Sphere
, whichimpl Hittable
and represents spheres in space.
- implements
material.rs
:- introduces
Material
, which describes materials that potentially generateColor
's and redirectRay
's from aRay
-Hittable
intersection; - implements
Lambertian
, whichimpl Material
and represents matte surfaces that reflect and redirectRay
's randomly and thus appear "fuzzy"; - implements
Metal
, whichimpl Material
and represents metallic surfaces that reflectRay
's and appear "shiny"; and - implements
Dielectric
, whichimpl Material
and represents transparent surfaces that refractsRay
's and appear "clear".
- introduces
camera.rs
implementsCamera
, which represents cameras in space with different positions, angles, fields of view, aspect ratios, apertures, and focus distances, and can produceRay
's for positions in the frame.main.rs
:- implements
ray_color
, which queries the result colors fromRay
's intersecting withHittable
's; - implements
write_color
, which applies gamma correction toColor
's and writes their RGB values; - implements
random_world
, which generates random scenes asHittableList
's; and - sets up and renders a random scene, which is displayed above.
- implements
- To render a scene, use
cargo run --release > dump.ppm
. - Previous incremental renders can be found in
renders
in bothppm
andpng
format, labeled by the relevant sections in Ray Tracing in One Weekend.