Ray Tracing

I don’t have time for a full fledged post today due to school work. However, I do have the time to quickly describe my latest lab in my CS class, Parallel Computing.

I’ll start out with a short summary of the class. Essentially, first semester focused on distributing computing across multiple machines. We used MPI with C to solve both ‘trivial’ (each computation is independent) and ‘complex’ (computations require communication between workers). We mostly used a top down framework with a manager machine coordinating workers. Second semester is focusing on multi-threading on one machine, including harnessing GPUs and multicore CPUs.

The problem I’ve been working on is actually a lead up to the parallelization; that is, it isn’t running in parallel yet. We are doing ray tracing within a 3D space to determine shadows. Because it doesn’t particularly matter how complex the scene is, we are rendering spheres and planes only. The way it works is like this:

A point in space acts as a camera. The “screen” is actually represented as a plane. For each “pixel” on the screen, a vector is created that runs from the camera to the middle of the pixel (or other fractions if you are anti-aliasing) and then normalized. Next, you work out whether the vector passes through each sphere and choose the solution closest to the camera. That determines which sphere or plane (if any) is rendered. To determine color, two normalized vectors are created. One goes from the center of the sphere to the point that is being rendered. The other runs from the point being rendered to a light source. If the cosine of the angle between them (dot product over the product of the magnitudes) is negative, the point is in the sphere’s own shadow. If it is positive, then you check whether or not the point-to-light vector intersects a sphere. If it does, then the point is in a shadow. If it has line of sight to the light, then you merely multiply the color of the sphere by the cos of the angle to produce falloff. A point in shadow uses the product of the sphere’s color and the scene’s ambient color. If a point doesn’t interest a plane or sphere, it is rendered with the environment color (usually black).

So far we haven’t implemented reflectivity or made the code run in parallel. Anyways, back to work!

Advertisements

Say something! Do it!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: