ray_tracing_core 0.1.1

Ray Tracing based on Peter Shirley's mini books
Documentation
  • Coverage
  • 20.53%
    62 out of 302 items documented1 out of 84 items with examples
  • Size
  • Source code size: 192.69 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 21.48 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 39s Average build duration of successful builds.
  • all releases: 39s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Rabbid76

Crate ray_tracing_core

GitHub page rabbid76.github.io/ray-tracing-with-rust
GitHub repository Rabbid76/ray-tracing-with-rust

Based on Peter Shirley's books:

cover scene - ray tracing 3

“Note that I avoid most “modern features” of C++, but inheritance and operator overloading are too useful for ray tracers to pass on.”
Peter Shirley, Ray Tracing in One Weekend

Example

use ray_tracing_core::random;
use ray_tracing_core::test::TestSceneSimple;
use ray_tracing_core::types::ColorRGB;
use ray_tracing_core::types::FSize;

fn main() {
    let cx = 40;
    let cy = 20;
    let samples = 10;
    let scene = TestSceneSimple::new().scene;
    
    let mut pixel_data: Vec<u8> = Vec::with_capacity(cx * cy * 4);
    pixel_data.resize(cx * cy * 4, 0);
    
    for x in 0..cx {
        for y in 0..cy {
            let mut c = ColorRGB::new(0.0, 0.0, 0.0);
            for _ in 0..samples {
                let u = (x as FSize + random::generate_size()) / cx as FSize;
                let v = 1.0 - (y as FSize + random::generate_size()) / cy as FSize;
                c = c + scene.ray_trace_color(u, v);
            }
            c = c / samples as FSize;
    
            let i = (y * cx) + x;
            pixel_data[i * 4] = (c[0].sqrt() * 255.0).round() as u8;
            pixel_data[i * 4 + 1] = (c[1].sqrt() * 255.0).round() as u8;
            pixel_data[i * 4 + 2] = (c[2].sqrt() * 255.0).round() as u8;
            pixel_data[i * 4 + 3] = 255;
        }
    }
    
    // [...]
}