Project 1

Ray Casting

OpenGL View

The three spheres above are rendered using OpenGL. It's a good starting point to determine if the generated camera rays are correct.

Ray Tracer

Now we're generating spheres using the camera rays (no opengl). When the ray hits the sphere, we color that pixel white. Otherwise, the pixels are colored black. Since the spheres in white above align with the OpenGL spheres, we know the generated ray directions are correct, and that the sign of the sphere intersection discriminant is correct.

Z Buffer

Finally, this is the Z Buffer generated for the ray traced spheres. These values can be used to determine which object is closest to a particular ray, which can be helpful when implementing occlusion. Mostly, we've verified that the depth that the rays from the camera intersect the spheres at is correct.


I had a really bad bug with my Z Buffer calculation. The sphere on the left and the sphere on the right are both -10 z back. The left sphere had a radius of 1.5 and the right sphere had a radius of 1. However, the z values from my sphere intersection were wildly different.

It took a while to catch, but I had an order of operations bug in my code after calculating the discriminant. When I divided by "2*a" below, I needed to surround the "2*a" with parenthesis.

After the fix

After adding in the parenthesis, this is what the image looks like




Intel HD Graphics 620, Intel Core i7 - 7500U CPU @ 2.7GHz, 16GB of memory