CSC 473 Final Project - Winter 2010

Distributed Raytracing & Texture Mapping

Nick Moresco

Introduction

Distributed ray tracing is a modification of the normal ray tracing procedure to allow advanced rendering techniques such as soft shadows, anti aliasing, motion blur, and more. It works by casting multiple rays per pixel and averaging the values together to get the final pixel color. For this project, I focused on anti aliasing and soft shadows, and then added texture mapping. So let's get to it!

Anti Aliasing

The problem with any digital representation of an image is that the smallest unit possible is a pixel. Since a ray tracer uses mathematically-defined primitives, their resolution is theoretically infinite. Problems can arise when the edge of one shape crosses only part of a pixel. If the ray tracer registers a pixel as "hitting" an object, the ray tracer will paint that entire pixel the color of the object when in reality the object barely touches that pixel. This can produce jagged edges ("jaggies") along an object. Especially on curved surfaces.

Jaggies are the bane of 3D modelers everywhere.

Luckily, we can use distributed ray tracing to minimize jaggies and make our pictures as smooth as a baby's bottom. By taking a sampling of pixels around the pixel we're currently painting, we can produce an average that will smooth out the whole picture. In order to minimize weird artifacts, we don't take a simple uniform sampling or a purely random sampling. Instead, we take a hybrid of the two known as Monte Carlo sampling. Within a grid of pixels surrounding our pixel, we take a random sampling from each square.

From the ray tracing chapter of Shirley.

Once these are all averaged together, the edges will have been averaged with the colors behind them, and the jaggies will be removed!

Niice and smooth!

Soft Shadows

In a normal ray tracer, shadows are either on or off. There's a very rigid transition between the two. This is because our ray tracer models light as a single point instead of an area. That's not really how light works in real life. Lights take up space just ike any other object and have varying intensities along their surface, resulting in aesthetically pleasing gradients along shadows. So we need some way to model that. Since we're talking about distributed ray tracing, its probably not too surprising that this is how we can model soft shadows too.

The lighting is quite soft on the spheres, but the shadows are really harsh. Not so pretty.

An easy to approximate an area light is to make the point light into a parallelogram with the original point being the center. Just like anti aliasing, we take a random sampling of pixels. However, this time we take them not only on the objects, but along the light too. It is best if these two sets of random samples do not match, so generating the random points once and then shuffling them into two arrays is an efficient way to remove correlation.

Pretty!

Texture Mapping

While single colored objects are pretty cool, it sure would be nice if we could give our objects textures so they can have more than one color. Texture mapping allows us to take flat 2d images and apply them to 3d objects.

This texture has no idea it's about to get a 3rd dimension applied to it.

In order to map a texture to a sphere, we define a coordinate system (u,v) along the texture that allows us to easily index into the texture. (0,0) is the top left of the image, and (1,1) is the bottom right. So now we just have to figure out what (u, v) coordinate corresponds to what point on the sphere. There are a number of projection methods to do this with varying amounts of distortion. A simple one is to use the normals calculated at that point as such:

u = asin(Nx)/PI + 0.5
v = asin(Ny)/PI + 0.5

This is a relatively efficient projection because we already calculated the normals for lighting although it does cause some distortion.

Close, but not quite.

I found the equation Shirley gives to be a better alternative. (Theta = v and Phi = u)

These equations produce results from (-pi, pi) so they need to be scaled to (0, 1) before they can be used.

With all these calculations, it's easy to misplace a parenthesis...

Someone off the coast of Indonesia divided by 0.

But it looks pretty good once you get it right!

Home, sweet home.


Here's a picture of the culmination of my efforts:

I realize Pluto is not technically a planet anymore. But it should be.

References

1) Fundamentals of Computer Graphics by Peter Shirley
2) MVPS.org - Article of spherical mapping with normals.
3) www.cs.darthmouth.edu - PDF on distributed ray tracing.