Code Monkey home page Code Monkey logo

tinyraytracer-rust's Introduction

tinyraytracer-Rust

It is inspired from tinyraytracer by ssloy which is written in C++. This is a Rust version of it. It is a very good tutorial for beginners to learn ray tracing. I have tried to keep the code as close to the original as possible.

Result

Requirements

  • git
  • rustc (> 1.50)
  • cargo (> 1.50)

How to compile and run

If you have cargo installed, you can compile and run it using:

git clone https://github.com/Qazalbash/tinyraytracer-Rust.git
cd tinyraytracer-Rust
cargo run --release

Otherwise, you can compile it manually using rustc and run the executable tinyraytracer:

git clone https://github.com/Qazalbash/tinyraytracer-Rust.git
cd tinyraytracer-Rust
rustc -C opt-level=3 -C target-cpu=native -C lto -C codegen-units=1 -C panic=abort -C debuginfo=0 --out-dir ./target --crate-name tinyraytracer src/main.rs

Description

The code is divided into 4 files:

  • constants.rs: It contains the constants used in the code.
  • main.rs: It contains the main function and the code for rendering the scene.
  • math.rs: It contains the code for vectors.
  • primitive.rs: It contains the code for primitives types like Sphere and Material.

In main.rs there is a special function to print patterns on the sides. It is called pattern. It is just for fun. By default it is set to:

#[inline]
fn pattern(a: f32, b: f32) -> math::Vec3 {
    match ((a + 1000.0) as i32 + b as i32) & 1 == 1 {
        true => constants::DARK_SQUARE,
        false => constants::LIGHT_SQUARE,
    }
}

Future work and improvements

There are many things that can be improved in this code. The first and foremost thing is to make it more optimized. I have tried to make it as optimized as possible, but there is still a lot of room for improvement. One aspect is to less use static variables and use dynamic memory allocation instead. I am also planning to make this in OpenCL and CUDA.

Related projects

Contributors

tinyraytracer-rust's People

Contributors

qazalbash avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  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.