6.1.08

Computer Graphics: Part Two

The sun shoots out a light ray that hits a blue ball. The blue ball reflects the blue ray and absorbs all the other colors. That blue light ray enters your eye and that is how you see. Computer Graphics follows this same method, only backwards, and the method is called ray tracing.
First, a ray is generated for each pixel. This ray shoots out into the virtual scene being rendered. Then you test whether or not the ray hits an object. If it does, the pixel color is the color of the object. If not, the pixel color is black.

When the pixel's ray intersects a ball, you can use a ray from the light source (vL), the surface normal of the ball (n), and vector math to determine how that pixel ought to be shaded. There are several different shading methods, including Lambertian and Phong (Lambertian is shown to the left).

What the objects still lack are shadows. after the pixel's ray hits an object, you check if ray vL is blocked by an object. If it is, this point on the ball is being cast into shadow by another object, and therefore must be black.

After a while spheres can become pretty dull. What else can you render with ray tracing? Anything that can be represented mathematically (remember, you have to mathematically calculate where a line and your object intersect). Unfortunately even simple shapes like a donut become difficult to model mathematically. Instead, complicated shapes are modeled using triangles.

Modeling glass objects provides another interesting challenge. When you look at glass, you're seeing not only the colors through the glass, but also the colors reflected by the glass. It makes sense then that in ray tracing, when a ray hits glass, it splits into two rays, one that reflects off the surface and one the refracts into the surface. If there are several glass objects in the scene, you can imagine the recursive nightmare that takes place. This problem is usually circumvented by specifying a maximum recursion depth.

Last semester my partner and I had to make a ray tracer for our course in computer science (thanks to Professor James for his slides). Below are some renders:


4 comments:

Phil Harnish said...

I've seen your group's 3D rendering program and it's incredible how many features you two implemented in a semester. Your post really makes it seem easy.

Where do you think ray tracing is heading? I'm holding my breath for real time rendering!

Phil Harnish said...

Just a follow up to my own comment, this Slashdot article did a great job of answering my own question :D

From what I gathered, the direction things are taking is even better than ray tracing.

esbie said...

Better than Ray Tracing? At first, I was skeptical that real-time ray tracing was even possible within the next decade. But with CPU makers going into a multi core frenzy and Ray Tracing being highly parallelizable, it looks like we're really on our way!

Phil Harnish said...

Another article on real time raytracing popped up at Coding Horror. It seems like Jeff is pretty skeptical, if not optimistic.