Sep 3 '21
This is an older version of the article. Click here to see the current one.

CPU Raytracer

I hear all graphics programmers have made one. Well, after some years of OpenGL so did I. At the time I decided I didn’t like the randomness and duplication of typical Monte Carlo raytracers and tried my hand at the older and slower recursive branching kind.

The code is still available on github. Sorry.

I started work on a this in Oct 2012, mainly just for fun but also for a comparison to shader based approximations. I’m sure it could be much faster with a GPU. I chose not to use one. I’ll post rendering times when I’m good and ready.

Gallery

enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here

Tech

At the core of the raytracer is the spatial data structure. I didn’t mess around with any BVH nonsense :P. This thing was made to render one mesh only. I decided I wanted a kd-tree + surface area heuristic (SAH). I then followed and implemented the algorithm described by: On building fast kd-Trees for Ray Tracing, and on doing that in O(N log N).

It also includes the technique described in Tracing Ray Differentials to anti-aliase texture sampling. You’ll note crisp checkerboard filtering in the image of the gold rings despite aliasing at geometry edges. That’s just one ray per pixel!