Chris Brenton

CPE 572 Spring 2012

## Ray Marching

It's like ray tracing, but different. Instead of determining geometry intersections once per ray, you start at the camera origin and find the distance to the closest object in the scene. Each time this distance is greater than zero, move the ray along its direction vector an amount equivalent to the minimum distance. This is the furthest it can go without hitting anything. If the distance is zero, count it as a hit.

#### A basic illustration of ray marching in 2D.

Ray marching allows for certain effects to be done faster and cheaper than traditional ray tracing. A great example of this is infinite object repetition. This costs basically nothing with a ray marcher, while it adds literally infinite work to a ray tracer. This repeating Pokeball field took the longest to render out of these three images, and it took only 2 minutes to produce a 1080p image.

Ray marching uses distance functions instead of intersection functions, which allows easy rendering of implicit surfaces. However, normals at a given point cannot be easily defined for implicit surfaces. To get around this problem, I used the central difference method. This involves calculating the distance to an object at a given point, as well as several points each jittered slightly in one direction, which allows for an accurate estimation of the normal at the given point. Because of this, I can accurately shade implicit surfaces.

Ambient occlusion involves shading geometry based on the proximity of other objects. This is a phenomena that does not exist in nature, but it is often used to make rendered images look more "real", or to add clarity to geometry, like in architectural rendering. Ray marching makes this easy because it already requires a way to find the minimum distance to an object in the scene. To calculate ambient occlusion, I simply projected along the normal at a hit location and then calculated the proximity to objects in the scene. This proximity was used to determine how much to shade the current pixel.

#### Bunny rendered with ambient occlusion. Particularly visible where the bottom spheres approach the plane.

#### Left: Pokeball field without ambient occlusion. Right: With ambient occlusion.

I also added the ability to perform boolean subtraction with geometry. This can be seen in the images below.

Ray marching also makes cool bugs.