Mariusz Bartosik's website

Graphics programming, demoscene and book reviews

Ray Tracing in One Weekend

Ray Tracing in One Weekend book cover

Peter Shirley

PublisherAmazon Digital Services LLC
Print pages49

Wouldn’t it be nice to create a small ray tracer as a weekend project? Well, that’s exactly the idea behind this mini e-book. After implementing all the features described in it, you will be able to create the image from the cover.

While reading the book, you will learn how to send rays through pixels, render spheres, create diffuse, metal and dielectric materials. You will also learn how to deal with aliasing, improve your camera to easily place it in space and implement defocus blur (depth of field) effect for it. All the fundamental concepts needed for creating a path tracer. There is also a description of PPM format followed by a chapter on how to create a simple vector class, so your program can be self-contained and don’t have to use any external libraries.

Even if it’s possible to read this book in 30 minutes, I must say that programming your own ray tracer may take a bit more than a few hours. After reading each chapter you will refactor the code, create new scenes and render them. Expect to write about 16 kB of text (less than 400 lines of pure code) to create your very own path tracer. The author is a fan of a practical approach to learning; that is, you should write all the code by yourself. If you want to use the included C++ example implementation, you still have to type it by hand, as all the snippets are embedded as images.

Ray Tracing in One Weekend example scenes
Some test scenes you will create while reading the book

Speaking of code, maybe it’s not the best educational code example in the world, but it does its job. In your own implementation, you should take care of memory deallocation (or just use the standard <vector> container), keep longer code in .cpp files, not in headers, and use more descriptive variable names, because a few weeks later you will forget that ns controls “number of samples”. There is also no need to use rand48() when you can utilise various built-in generators from the standard <random> header. But that’s just my recommendations, you can use the example code as it is, and it will work just fine.

By the way: after reading chapter 8, you may get stuck on how to handle *mat_ptr in a sphere object constructor. There are no code fragments describing this. This should not be a problem for experienced programmers, but some readers were complaining about it, so the author actually bent his rules and published the code. If you want to take a peek, check out the GitHub repo with code for the book.

A nice thing in releasing technical books in electronic format is that they are easy to update and distribute, so it should not be a problem to make a few improvements, fix some typos and remove unused variables from the code. In fact, in my copy, the author says “thank you” to some readers, so it was clearly an updated version. There is a chance that there will be another update in the future. For more info, extra resources and ideas, visit the “In One Weekend” series website.

Overall, this mini-book is like a notepad with lecture notes. Short explanations, hand drawn images and code snippets are there, but you have to do additional research and organise exercise labs on your own. If you are willing to do this, then this book is for you and can bring you some fun and satisfaction. While there are still some issues to correct, I like this do-it-yourself approach and I’ll definitely check out the other two mini-books in the series.


Written by Mariusz Bartosik

I’m a software engineer interested in 3D graphics programming and the demoscene. I'm also a teacher and a fan of e-learning. I like to read books. In spare time, I secretly work in my lab on the ultimate waffles with whipped cream recipe.


Leave a Reply

Required fields are marked *. Your email address will not be published. You can use Gravatar to personalize your avatar.

Allowed HTML tags: <blockquote> <a href=""> <strong> <em> <pre> . Use [code lang="cpp"] and [/code] for highlighted code.