Jump to ratings and reviews
Rate this book

The Ray Tracer Challenge: A Test-Driven Guide to Your First 3D Renderer

Rate this book

Brace yourself for a fun challenge: build a photorealistic 3D renderer from scratch! It's easier than you think. In just a couple of weeks, build a ray-tracer that renders beautiful scenes with shadows, reflections, brilliant refraction effects, and subjects composed of various graphics primitives: spheres, cubes, cylinders, triangles, and more. With each chapter, implement another piece of the puzzle and move the renderer that much further forward. Do all of this in whichever language and environment you prefer, and do it entirely test-first, so you know it's correct. Recharge yourself with this project's immense potential for personal exploration, experimentation, and discovery.


The renderer is a ray tracer, which means it simulates the physics of light by tracing the path of light rays around your scene. Each exciting chapter presents a bite-sized piece of the puzzle, building on earlier chapters and setting the stage for later ones. Requirements are given in plain English, which you translate into tests and code. When the project is complete, look back and realize you've built an entire system test-first!


There's no research necessary -- all the necessary formulas and algorithms are presented and illustrated right here. Dive into intriguing topics from fundamental concepts such as vectors and matrices; to the algorithms that simulate the intersection of light rays with spheres, planes, cubes, cylinders, and triangles; to geometric patterns such as checkers and rings. Lighting and shading effects, such as shadows and reflections, make your scenes come to life, and constructive solid geometry (CSG) enables you to combine your graphics primitives in simple ways to produce complex shapes.


Play and experiment as you discover the fun of writing a ray tracer. Accept the challenge today!


What You Need:




Aside from a computer, operating system, and programming environment, you'll need a way to display PPM image files. On Windows, programs like Photoshop will work, or free programs like IrfanView. On Mac, no special software is needed, as Preview can open PPM files.

439 pages, Kindle Edition

First published December 11, 2018

56 people are currently reading
284 people want to read

About the author

Jamis Buck

4 books69 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
49 (72%)
4 stars
16 (23%)
3 stars
2 (2%)
2 stars
0 (0%)
1 star
1 (1%)
Displaying 1 - 12 of 12 reviews
Profile Image for Sten Anderson.
34 reviews2 followers
March 16, 2019
I've always had an interest in computer graphics, and although I'm an experienced programmer, I've always found the topic daunting to approach. While there is certainly no shortage of books on rendering and ray tracing I would often struggle to get to a workable implementation that I could understand. The challenge for me had always been, how do I start with nothing and create even a baseline Ray Tracer in discrete steps? Forget anti-aliasing and reflections, if my first render is a blank image, where do I begin my debugging? The chasm seemed uncrossable to me.

Until now.

Jamis has written something truly unique and remarkable here. He has effectively solved the complexity problem by applying Test Driven Development to one of the most rewarding pieces of software you'll ever write. TDD, as a discipline, allows you to make the smallest possible incremental step while also giving you the confidence that you are headed in the right direction. Applied to the development of a Ray Tracer is nothing short of ingenious. You'll have written several dozen tests before you cast your first ray, confident in the knowledge that when you do, it'll be correct.

I'm happy to say that after many false starts over the years, I have in fact, written a working Ray Tracer thanks to this book. It's difficult to describe the sheer joy of building something up from nothing and viewing your first render of mirrored balls and checkered floors, reinforced by hundreds of unit tests.

I've been at this programming thing for over twenty years and I have to say, this is one of the most unique and welcome technical books I've read. Ever.

Highly recommend.
Author 43 books12 followers
October 18, 2022
One of the best technical books I've ever read. I could not put it down. I created my own ray tracer and I can't believe that I wrote every line of code and it is doing the kinds of things that it is doing. Since I've finished the book, I'm continuing to optimize and add new features. I can do this because I have a full understanding of the concepts the book taught.

This book does not just dump a bunch of pre-written code on you and explain it. It starts with the principles and explains them thoroughly. Then it gives you a test to write - some input and expected output. It's up to you to now write the function that will make that test pass. Sometimes there is some more explanation of how that function should operate, sometimes there is some pseudocode. And sometimes you are left to work it out on your own. But the theory part sets you up to be able to write every function. I only got stuck once or twice and eventually got through it. This is a great way of teaching.
Profile Image for Gábor Hajba.
139 reviews3 followers
October 22, 2018
A great book for programmers. Instead of giving you code, Jamis invites you on a language-agnostic and test-driven journey to explore how a ray tracer works. I learned a lot, and I will use the exercises of this book to learn new programming languages.
Profile Image for Yura Gavrilovich.
102 reviews7 followers
January 10, 2024
A very good book!
I used it to pick up a new programming language and to learn about ray tracing on the way. It's written in the form of tests in pseudocode, so one can use any programming language to work through it. Most of the topics are explained really well and it brings you joy to watch for beautiful pictures, generated after each chapter
Profile Image for Richard.
28 reviews1 follower
August 14, 2019
[Note: This review regards the first printed paperback version]

I bought this book on the 31st May and it sat on my desk for a few weeks whilst wrapping up other work. On the 2nd July I made my first first commit and I've spent almost all my free time up until the start of August working through it. I originally intended to blog a sort of mini-series as I progressed, but that went out of the window after the first commit - I was utterly enthralled by the challenge and didn't stop for such mundane tasks as writing blog posts! Even tearing away enough free time to write this review has been challenging, although I mostly wrote it whilst waiting for scenes to render and animations build.

I am very glad I bought this book - I have never read anything quite like it. The way it was presented means I was never truly floundering, and it quietly taught me without me realising. I've always had trouble reading linear algebra but I've noticed that I'm now finding it easier to read some formulae. I've still got a way to go with that sort of stuff, but I'm definitely improving.

I did have some problems - several times I didn't notice that the result of a square root was supposed to be negated and wondering why my tests were failing. On occasion I simply didn't read instructions properly and implemented something almost, but not quite, right. And of course, I spent a lot of time trying to make SpecFlow fit how I have traditionally tested. But it was pretty much all user error... I didn't spot any mistakes in the book or run into insurmountable issues. I do wish there were a few more reference YAML files though, that would mean I could compare images I generate with those in the book to make sure I really had things working correctly, not to mentioning actually defining correct camera and lighting properties is more challenging that you might think.

In short, I found this book fun. Really, really fun. It reminded me why I became a programmer in the first place. It also had the unexpected side effect of making me realise that I've been burning out for a while now doing the same old same old. I didn't expect a technical book to make me think about life choices!

I also can't stress enough how awesome the test driven format of the book is. It was quite something to implement a few tests, and just like that you have another amazing piece of rendering functionality.

Even though I've reached the end of book, this isn't the end of the story. At the time of writing this review, Jamis has also published 3 bonus chapters on the forums, one for creating bounding boxes, another for soft shadows and the third for texture mapping. I really can't wait to get that last one implemented! Some of the (low poly!) OBJ files I've tested also reference external materials and supporting these should be straightforward enough.

[This review is an abridged version of one I posted on my blog. See https://www.cyotek.com/blog/book-revi... for the original review plus screenshots]
Profile Image for Colin.
4 reviews1 follower
September 28, 2019
I made the ubiquitous teapot. And I'm proud of the result. The BDD/ TDD based Cucumber approach was magic, so much so that after doing it once in my main language (PHP) I'm going to see how good it is at teaching me a new language (RUST).

The book is hand-holding almost all the way through, with the end getting right tricky and pointy. Almost everything has a cucumber test case along side it, which is great for being able to verify results without needing in depth calculations to figure out if you're right. Of course, when things are not right, it's that much harder to figure out where things went wrong. As the algorithms are described in passing, but with links to the full deal.

I would've liked more test cases, maybe Scenarios for almost each test rather than a single one. There were a few instances that I had to get deep into my debugging skills to figure out where errors were introduced. Not sure how you could support that unless you had a couple of major test cases that checked the calculation at each step to find where things went pear shaped.

This book is great for coders of any skill level. Introducing the reader to BDD via this method is also brilliant; I've loved cucumber for a while so seeing it used in this manner is a delight. A very respected co-coder at work is using the book to learn Go, and is recoding the cucumber into Go-Unit tests; but it's still BDD and still fantastic.
27 reviews
December 23, 2019
This is now one of my favorite programming books! Not only is it a methodical building-block-approach to learning how ray tracers work, but it's a genuinely good way to familiarize yourself with the ins and outs of a programming language. For myself, I used Go after a year of learning it on the side -- this posed challenges because of its lack of OO inheritance, default/optional arguments, etc., and solving those challenges was equally as fun as implementing the ray tracer itself. The bonus chapters and forum are also a great supplement to the book. Thanks Jamis!
Profile Image for Isabelle.
335 reviews
November 22, 2019
A good progression and a very fun project - enjoyed it a lot. Caveat, though: it is absolutely possible to go through the whole book and still have only a fuzzy understanding of how a ray tracer actually works.
Profile Image for Matthew Hanna.
35 reviews
November 12, 2022
This is a lot of fun but takes a lot of time. My natural instinct was to do lots of different programming languages which made it even longer. C#, Java, C, C++, and Python. I think Go, Kotlin and JavaScript are next on my list.
Profile Image for Steven Behnke.
1 review
July 6, 2019
Loved it

This is a great introduction to building a Ray Tracer. The test driven approach gives you confidence along the way that your code is correct.
Profile Image for Mircea.
67 reviews12 followers
May 11, 2022
It's a cool book if you ever wondered how ray tracing works It's from first principles Also math! lots of math
Displaying 1 - 12 of 12 reviews

Can't find what you're looking for?

Get help and learn more about the design.