Thank you for visiting Blazing Games

Casting Rays

The human visual system is rather complex. Essentially when photons within the visible light wavelengths enter the eye, the energy is captured by the cones and rods that line our retina. Rods capture low level light but do not give us any color information. Rods are what allow us to see in fairly dark rooms. Cones come in three flavors. These roughly correspond to red, green and blue not chocolate, vanilla, and strawberry. They require fairly intensive light to function which is why we do not see colour in the dark.

When computer scientists started playing around with creating realistic graphics, thoughts about how the human vision system works came to mind. Recreating rays of light coming off of objects into the eye was not a realistic solution as most of the light bouncing around us never actually reaches our eyes. Instead, the researchers decided to take the ray from the eye and follow it backwards into the scene. Once the ray of light intersects an object in the scene, the ray can then be traced back to the light source(s) that light up the object. More advanced algorithms can even handle reflections, refractions, and other distortions that happen to light as it passes through different materials.

While ray tracing can result in photo-realistic images, there is a price to pay. All of this tracing of light requires a vast number of calculations. In fact, when I first started to play around with ray-tracing on my Amiga, it use to take hours to generate even the simplest of images. Even today, with computers that are many orders of magnitude faster than my Amiga was, ray tracing is still fairly slow. With the advent of multi-core computers, the concept of real-time ray tracing is no longer a day dream and is being done by hard-core graphics enthusiasts. Still, it will probably be quite a while before the average user will have a computer that can handle real-time ray tracing.

ActionScript 3 is faster than earlier versions of ActionScript but it is still way too slow to consider real-time ray tracing. When you consider that ActionScript doesn't even support threading it is not a good contender for writing a fast ray tracing program. So why the talk about ray tracing? While a full-blown ray tracer is out of the question, we can strip down the algorithm quite a bit to get something that can be useful.

First, if we have a flat surface and all objects on the surface are cubes of the same size oriented in the same direction, we can get away with casting only a single ray per vertical line of pixels. Second, if we go with a simplified lighting algorithm, there is no need to trace the ray back to the light source. This eliminates an enormous amount of calculations. This technique is also not new but is actually rather old and is known as ray casting.

Previous page
Chapter 31 Page 3

About - Privacy Policy - Contact - Links - FAQ
Copyright © 2009 Blazing Games Inc. All Rights Reserved