Raytracer in Rust

A CPU-based raytracer built from the ground up in Rust. I loosely followed the book Ray Tracing in one Weekend. My goal was to recap a lot of basics in computer graphics while learning Rust. I implemented a small game engine a while ago (with a rasterization render pipeline). But with much more theoretical knowledge now, it was time to get back into programming a practical application.
Personal side project
March 20, 2024

My Part

As I wanted to get back to the basics with this project, I built everything from the ground up. This includes a vector 3 representation with common functions, camera setup, ray-sphere intersection, and color calculation based on different material properties. Only the parallelization is done using Rayon to automatically split up the workload for pixels over all cores. The image is written into a .bmp file at the end.

Learnings

The apparent learning was with Rust. Having an actual project made it interesting to learn how to solve problems differently than in other languages. For example: I used Rust’s traits system (instead of inheritance) to make objects hittable for rays. Or using of borrow-checker for objects versus shared pointers for materials. By learning a new programming language, I got a new view of common problems and how to solve them differently. On the other side: Computer graphics. It was fun to get back to the basics. Setting up world transforms and the camera, calculating the material effects for the rays… Applying theoretical knowledge brought up areas where I did not understand concepts as well as I thought.
Scroll to Top