Ray Tracer update

10/2/2020 - 3 min read

I recently decided to make a raytracer following Ray Tracing in One Weekend. After a week or so I've gotten around to finishing the second book of the series. Here I went a bit over my thoughts after finishing the first book. You can check out the code here.

Before starting the second book I implemented Rayon, and I'm in love. I just had to change my code to be an iterator instead of a for loop, and use .into_par_iter(), and book, that's it. Instant parallelism. After using it for a while, I can't imagine why this wasn't the first thing I implemented, rendering is much faster now.

I also implemented a simple thing using the Image crate to export the images in png and ppm at the same time, so I don't have to convert it before sending it to someone.

Anyway, here's the final image from the second book:

Final render

It took 16 hours to render in my Windows PC, at 800x533, with 10000 samples per pixel and parallelism enabled.

I also had a lot of fun playing around with the Marble texture, trying to make it look as good as possible. It's not perfect, but I like how it looks:

Marble texture

After finishing the second book I implemented a simple ray marching algorithm for Signed Distance functions, using all the great information from Iñigo Quilez. It turns out it's pretty straightforward, considering all the amazing things it allows you to do.

This is my attempt at the Menger fractal:

Sponge fractal attempt

I also made this image which I'm quite proud of, Space Donut:

Space Donut

The image is 800x533, at 10000 samples per pixel. I reused the rising cubes from the final book image because I liked how they looked, and I made the donut metallic because a friend of mine kept asking for it.

My next steps now are to finish the third book, to learn about all those small details that can make a difference in quality, and to look into rendering in GPU, as doing it in CPU is pretty slow. Iterating on designs is tedious when it takes more than 30 seconds to see the results.

There's a lot to be improved, but I'm having a ton of fun and learning a lot about rendering, so I really recommend following these books to everyone.

© 2020 Guillem Caballero Coll