GithubHelp home page GithubHelp logo

marvinst / raytracer Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 32.29 MB

This project is a rust implementation of a cpu-based raytracer based on the series Ray Tracing in One Weekend

Rust 100.00%

raytracer's Introduction

Introduction

This project is a rust implementation of a cpu-based raytracer based on the series:

This is a personal project to learn rust and my first real project in rust. As usual, some implementation hints from other similar projects were taken, but the work has been implemented mostly based on the original C++ implementation from the books.

Todo

Open tasks:

  • Book 2
    • Polish the demo scene code
  • Book 3
    • Implement pdf based sampling
    • Implement sampling from light sources
    • Update material functions for new sampling method
    • Remove spickles induced by incorrect color samples (resulting in not-a-number values)
  • Rewrite BVH to work with indices to objects instead of object containers
  • Create a more organized structure for the different scenes (perhaps serialize to/from JSON)
  • Implement additional tests for material functions

Build and Run

The project can be built and executed using cargo.

Build

cargo build --release

Run

cargo run --release

Multithreading

To speed up the rendering process, the raytracer is multithreaded, allowing us to evaluate several pixels in parallel threads.

Rayon

Rayon is used for multithreading, we iterate over each line and map with a parallel iterator over each pixel per line. It was not possible to use a parallel for iterator for all pixels, hence why the parallel iterator is applied for each line.

for j in (0..image_height).rev() {
    let pixels: Vec<Vector3<f32>> = (0..image_width).into_par_iter().map(|i| {
        get_pixel_color(
            image_width,
            image_height,
            samples_per_pixel,
            &cam,
            &world,
            max_depth,
            i,
            j,
        )
    }).collect();

    for pix in pixels {
        write_color(&mut f, &pix);
    }
}

During my brief testing, I also tried calculating each sample per pixel in a seperate thread, but this did not yield any significant speed up. It could be that a single sample is very fast to evaluate with just a few objects in the scene and therefore the overhead of starting of managing the threads outweighs the benefits.

Output

scene0 scene1 scene2 scene3 scene4 scene5 scene6 scene7 scene8

raytracer's People

Contributors

marvinst avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.