/Spheres

🌈 Ray Tracer in Rust

Primary LanguageRustMIT LicenseMIT

Spheres

Build Status

This is a new ray tracer program implemented in Rust based on Ray Tracing in One Weekend and Ray Tracing: The Next Week

Ray Tracing Minibooks Book 1 on Amazon

Ray Tracing Minibooks Book 2 on Amazon

I upgraded to Rust 2018 while employing some new features, thereby reducing memory-related overhead. And I switched all vectors from f64 to f32, which may contribute to better performance. BTW, I made some benchmarks for this version.

Showcases

Sea

Generate 300 spheres (no overlap) in the space with different materials and settings.

It takes ~560 secs to render.

scenes/complex_scene.rs:complex_scene_1

complex_scene_1

scenes/complex_scene.rs:complex_scene_2

complex_scene_2

Textures

Light

scenes/legacy_scene.rs:legacy_scene_light

legacy_scene_light

Checker Texture

scenes/legacy_scene.rs:legacy_scene_texture

legacy_scene_texture

Perlin Noise

scenes/simple_scene.rs:simple_scene_perlin_noise

simple_scene_perlin_noise

Cornell Box

Spherical Harmonics

This image was computed by Francois Sillion, et al. as part of a research into using spherical harmonics to represent Bi-directional Reflectance Distribution Functions (BRDF) for surfaces. The reflectance properties of a green wall yield more balanced solutions.

scenes/cornell_box.rs:cornell_box

cornell_box

Usage

  • First, Rust has to be installed as described in the official tutorial.

  • Write your Write your specifications in main.rs:

    use self::renderer::utils::render_high_quality as render;
    use self::scenes::simple_scene::simple_scene_perlin_noise as scene;

    Here you can change render_high_quality to render_preview to render faster. And you can select from examples scenes by changing self::scenes::****::****.

    render(hitable_list, camera, "scene.png", true)?;

    The third parameter indicates that with previous rendering settings, the image will be rendered to /output.

    The fourth parameter indicates whether to enable ambient light or not.

  • Run:

    RUST_LOG="raytracer=info" cargo run --release

    If succeed, you may see information like this

    logging

    the image will be generated at /output.

Tests and Benchmarks

cargo test
cargo bench