A work-in-progress ray tracer following the "Ray Tracing in One Weekend" series. Scenes are authored in TOML, loaded into core::render::Render, and rendered to PNGs under samples/. The library exposes both single-threaded and Rayon-powered renderers plus a profiler that charts wall time across SPP sweeps.
- Install the Rust 2024 toolchain.
- Render a TOML scene (defaults to
scenes/bouncing_spheres.toml, writessamples/<scene>.png):
cargo run --release --bin rustray -- [path/to/scene.toml] [--concurrent]- Omit the path to use the default scene. Pass
--concurrentto split the image into row chunks per CPU and render in parallel; the default mode runs the single-threadedraytrace.
- Sweep through several sample-per-pixel counts and generate a timing chart:
cargo run --release --bin rustray_profile -- [path/to/scene.toml] [--concurrent]- The profiler renders each configured SPP in
src/bin/rustray_profile.rs(defaults: 10, 50, 100, 200, 500, and 1000), savingsamples/<scene>_<spp>spp[_concurrent].png, printing a wall-time summary, and writingprofile/profile_<scene>[_concurrent].pngusingcharming.
- Scenes round-trip through
core::scene_file::{load_render, save_render}. The TOML schema includes:- Global
width,samples,depth, and a serializedcamera(fullCamerastate: origin, lower_left_corner, horizontal/vertical, basis vectorsu/v/w,up, aperture, focal length, aspect ratio, and vertical FOV). Rays carry a randomtimevalue to support motion blur. geometries: tagged entries forSphere,Quad,Cube(assembled from quads), orWorld(sky gradient).materials: tagged entries forLambertian/Metallic/Dielectric/DiffuseLight/Isotropic/World, with texturesColor,Checker,Noise, orUv(uses assets likeassets/earth.jpg).objects: pairs a geometry id with a material id plus optionaltransforms(Rotate,Translate,Scale,Movewith time range for motion blur) and an optionalalbedotint applied byMaterialInstance.volumes: participating media; references a boundary geometry, phase-function material, density, and optionalboundary_transforms.
- Global
- Scenes are deduped when serialized, so reused geometry/materials stay shared.
src/bin/rustray.rs— CLI renderer that loads a TOML scene, optionally runsraytrace_concurrent, and writessamples/<scene>.png.src/bin/rustray_profile.rs— profiling helper that renders multiple SPPs and emits a timing bar chart.src/lib.rs— exposesraytrace(single-threaded) andraytrace_concurrent(Rayon) plus helpers for chunking and assembling scanlines.src/core/— camera/ray/bbox primitives, BVH (bvh), threaded chunker (acceleration), render container (render), renderables/objects (object), volumes (volume), sky gradient (world), and TOML scene loader/saver (scene_file).src/geometry/— hittables (sphere, quad, cube), transforms (rotate/translate/scale/move), andGeometryInstancethat applies transforms and motion blur-aware bounds.src/materials/— lambertian, metallic, dielectric, diffuse light, andMaterialInstancefor optional albedo tinting;core::volume::Isotropicprovides the volume phase function;src/textures/covers color/checker/Perlin noise/UV textures.src/stats/— chart rendering viacharmingfor profiling.examples/— programmatic scene builders that mirror the TOML files.samples/holds rendered outputs;profile/holds timing charts;target/is build output (do not commit).
- Samples per pixel are snapped to a perfect square for stratified jitter (
sqrt(spp) x sqrt(spp)grid). Gamma correction is applied via square root before saving. - BVH culling (built in
Scene::build_bvh) sits in front of per-object hit tests; every hittable supplies a bounding box, including transformed/moving instances. - Rays keep their
timethrough scattering to keep motion blur and animated transforms consistent. - Volumes implement an isotropic phase function; the world background is modeled as a
Worldhittable/material pair.
- Format:
cargo fmt - Lint:
cargo clippy -- -D warnings - Build:
cargo build - Test:
cargo test(no tests yet)
400 boxes, 1,000+ spheres, 1 diffuse light, a low density volume over the entire scene, glass/metal/diffuse/perlin noise/UV mapping materials, movement transformations
examples/next_week_scene.rs
scenes/next_week_scene.toml
Rendering a 800x800 image with 10000 samples per pixel and max depth 50 using 10 threads
Wall time: 2h 37m 36s 801ms
Image saved to samples/next_week_scene.png
- 400+ spheres, glass/metal/diffuse materials
examples/bouncing_spheres.rs
scenes/bouncing_spheres.toml
Rendering a 800x450 image with 10000 samples per pixel and max depth 50 using 10 threads
Wall time: 0h 29m 7s 372ms
Image saved to samples/bouncing_spheres.png
examples/cornell_box.rs
scenes/cornell_box.toml
Rendering a 600x600 image with 10000 samples per pixel and max depth 50 using 10 threads
Wall time: 0h 22m 57s 831ms
Image saved to samples/cornell_box.png
Concurrent rendering is more efficient on multi-core machines vs. single-threaded rendering, however in both methods the render time grows with samples per pixel, max depth, and scene complexity (number of objects, types of materials, etc).
Melt your CPU rendering pretty things.

Profiling render scenes/bouncing_spheres.toml at 10, 50, 100, 200, 500, and 1000 samples-per-pixel.
Profiling render scenes/bouncing_spheres.toml at 10, 50, 100, 200, 500, and 1000 samples-per-pixel.




