Ray tracing in Rust

Wednesday, 14 January 2026 at 4:38 am


I have long been interested in ray tracing. To me, the technology that turns shapes into pixels is magical.

On this blog post you can see some of the images that I generated during my development of a CPU ray tracing engine in Rust.

For those who don’t know what ray tracing is: it’s a technique for rendering objects based on simulating the path of bouncing light. While conceptually simple, there are many details which need to be got right in order to achieve a realistic looking render.

You can find the source code for this project here.

Credit to the incredible book, Ray Tracing in One Weekend, for many of the ideas, equations, and algorithms that I implemented.

The cover of ray tracing in one weekend


Implementing a simple ray tracer turns out to be quite easy. Perfectly reflective spheres are the simplest way to start. Here three spheres are pictured reflecting off each other.

Three spheres


Then you might attempt to add a background colour, and light source.

Two blue spheres


It becomes more difficult when you want things that are not shiny. Here a sphere is pictured with Lambertian Diffusion which I think looks quite “plasticy”.

A sphere that diffuses light rather than perfectly reflecting it

And below, these spheres are pictured with different strengths of diffusions ranging from 100% on the left to 0% on the right.

Five spheres of different levels of diffusion


Going back to the metalic looking surfaces, here are five pictured with different roughnesses.

Five spheres of different levels of diffusion


The metalic spheres can then be coloured to give the appearance of different metals.

Gold, plastic, and silver spheres


To make a glass sphere, you need to consider the refraction of the beams of light as they pass into and outof other objects.

A glass sphere refracting the passing light


Glass, plastic, and gold spheres


To render arbitrary meshes you can just render the triangles in the right places.

A polygon mesh of a dog rendered in blue


You can also put images onto surfaces. This one is from NASA.

The earth


And finally you can render something that looks like the cover of the book.

A rendered scene, matching that on the cover of the ray tracing in one weekend book


Thanks for reading. If you ever have the time, I reccomend you follow along with the book and implement ray tracing in your favourite programming language. It’s a great workout of both programming and maths skills.