carl taylor

Ray Tracer Extensions

I added three extra features to my ray tracer: anti-aliasing, soft shadows, and ambient occlusion.

bunny scene 108Bunny Scene Videoa2Ambient Occlusion

Anti-Aliasing
My anti-aliasing uses directed stochastic sampling. Instead of just casting one ray straight in the direction of each pixel, each pixel's area is broken up into an even grid of squares, the number of which depends on the user-specified anti-aliasing level. Within each square of the grid, a random point is chosen, and a ray is cast in that direction. The total color of that pixel is then the average of the color of all the rays cast within that pixel's grid.

Soft Shadows
Unlike the first shadows our ray tracers implement, shadows in the physical world don't have hard edges. This is because light sources in reality are volumetric, taking up more space than just the single point that our spec models lights as. The edges of real shadows are soft because near the edge of the shadow, part of the light source is visible behind the object while part of the light is obstructed, causing a partial shadow. Moving from the middle of the shadow to the end of the shadow, gradually more and more of the light can be seen, giving a smooth transition from shadow to light.

To implement this, for each point a ray hits, rather than just calculating a binary value for whether or not the point is in shadow, I send out many shadow test rays. For each of these rays, I calculate a random point on a sphere centered about the point light's origin rather than to the just the point itself, giving the light in effect a volume. I then add up the number of times the light was hit by the random shadow rays and divide it by the total number of shadow rays sent, getting a percentage of the light that this point should recieve.

Ambient Occlusion
One relatively cheap way to mimick global illumination is ambient occlusion. Ambient occlusion is a trick to make ambient light vary according to the geometry of the scene, darkening the area under objects, in crevaces, and other places where less ambient light should be seen.

For implementation, each time the ambient color of a ray intersection point is calculated, I send out a bunch of rays from that point to see how much geometry is directly around it. These rays are send our randomly in the hemisphere centered about the intersection point in the direction of the intersected face's normal. The percentage of the rays that do not intersect nearby geometry is computed, and that percentage is them used as the percentage of ambient light that should be shown.

References
Anti-aliasing and soft shadows
http://www.cs.unc.edu/~dm/UNC/COMP236/LECTURES/SoftShadows.pdf

Ambient occlusion
http://www.cs.unc.edu/~coombe/research/ao/

Picking a random point on a sphere
http://mathworld.wolfram.com/SpherePointPicking.html