Tyray: a ray tracer in Rust

3-2-2019

Over the holidays I wrote a tiny ray tracer in Rust. A ray tracer is a program that renders a 3D image by simulating the way light travels between light sources and a camera. Advanced versions of ray tracing techniques are used to render 3D movies such as the famous Pixar ones.

Rust is a language that is designed to be safe and fast. Writing a ray tracer is a good exercise to learn a new language, as it exposes you to various aspects of the language: how to deal with type conversions, numeric operations, objects and references, and concurrency.

My toy ray tracer is inspired by ssloy’s tinyraytracer and has the following features:

  • It can render spheres and planes (infinitely large flat surfaces)
  • It supports diffuse and specular lighting, as well as reflection and refraction (so it can render ‘glass-like’ materials)
  • It renders hard shadows
  • Rendering happens in parallel on all available cores

The source code is available on GitHub.