Introduction to Ray Tracing

HOME
FORUM
ARTICLES
TUTORIALS
SCRIPTS
LINKS
NEWS
MENTORS
TOOLS
REGISTER
Realistic Ray TracingFind out how ray tracers produce photorealistic graphics.

What is Ray Tracing?

Ray tracing is a very popular rendering technique, which consists of studying the path taken by light by following rays of light as they interact with optical surfaces.

Its primary applications are in 3D computer graphics, where scenes are rendered by following rays from the eyepoint to light sources.

Who uses this rendering technique?

Being one of the most popular techniques for rendering photorealistic images, ray tracing is used by 3D artists world wide—from home-users, to commercial organisations, such as Pixar Animation Studios.

This rendering approach is also used by game developers to aid in the production of photorealistic games; not to mention uses in other visual-based solutions, such as those used by Government organisations.

What are the alternatives?

There is a large number of rendering techniques, such as Reyes, Radiosity, and Global Illumination. Most of these algorithms however are varients of Ray Tracing—only taking a different approach, in order to give a slightly different result.

The specific technique which is common among most of these algorithms, is Ray Casting - which is explained later on.

So how good is this technique?

If what has been said already doesn't flaunt the quality of this technique, then here are some images produced using ray tracers:

Actions speak louder than words.

How does a Ray Tracer work then?

The 3D scene

Firstly, the machine must have a 3D scene to render. The 3D scene mostly consists of just polygons—as all models in a 3D environment are made up of polygons (more commonly, triangles).

It's easy to see that this is true when you compare more recent 3D games, to the older ones; you can see the characters and objects are very jagged, this is due to a low number of polygons.

Consider these two spheres—both of which have equal dimensions, the only difference is that the one on the left quite clearly has less polygons (90 polygons, in fact), whereas that on the right has many more (40,000):

Furthermore however, for realistic scenes, the shape and position of each polygon is not the only sort of data stored. Instead, the ray tracer must also know about the texture/colour of each surface, not to mention the shinyness (and other light properties).

More advanced techniques for producing realistic effects - such as bump maps - require even more data to be stored!

In addition to the polygons and models within the scene, such things as the light sources (position, size, brightness, colour, etc), and fog levels, cameras, and many other things, must too be accounted for.

Ray Casting

One of the most generic stages of rendering is performing a ray cast. This basically involves sending a ray of light through the scene (from the eyepoint) for each pixel in your resultant image.

What happens with these rays is explained next.

Ray Tracing

For each ray that is casted into the scene, it is followed through the entire scene until it's either shone into infinite and empty space, or it hits a light source.

However, the ray will almost certainly hit a surface at some point, so what happens then?

Well, this is where the math comes to use; when a ray of light hits a surface in real life, it is either reflected, refracted, (or both). Most materials also absorb some of the light—so energy is lost.

What the Ray Tracer must do here, is work out exactly what happens to that ray after it hits that particular surface, at that angle, with that energy level, etc, etc.

This is often down to very advanced Vector Analysis and many physics calculations.

In the event of a ray being reflected: that particular ray will be followed through the rest of the scene, perhaps bouncing off of other surfaces, until it is shone in a certain place and direction where it will not hit anything again (in which case, the pixel corresponding to that ray will become black, because there is no light that hits it).

If however, the ray hits a light source, then the path that the ray has taken, in addition to the light source that it hits will all be used to calculate what colour that rays corresponding pixel will be.

Likewise, if the light is refracted: it will also be followed through the rest of the scene until a colour for its corresponding pixel can be deduced (based on the above criteria).

Rays of light often reflect and refract at once. In the event of this, the single ray is broken up into two seperate rays. Each of which is followed round the scene etc, until a colour for it can be found.
Once a colour has been derived for each ray, they're used together in order to conclude a single colour for the pixel.

And that's it really.

A ray for each pixel is casted into the scene. It is then followed until it either hits a light source, or infinite. Reflection and Refraction is accounted for, and both the motion and destination of each light ray is used to conclude a colour for each pixel in the rendered image.

Feedback
If you spot any mistakes in this article, or wish to contribute, then feel free to post in our forum.
post to Dzone Digg this! Add to del.icio.us Googleize this Add to reddit Save to myYahoo Add to furl Add to Netvouz! Spurl this! Add to Linkroll! Save to Simpy Give if thumbs up on StumbleUpon Save to Blinklist Add to Tektag Save to Bibsonomy Submit to Tweako
Search ERT on the Tools Page
Did you know? You can discuss this article with the mentor who wrote it and others interested in the topic? You are invited to join the discussion with Go to the forum

Got a technical article or tutorial you want to publish on the Internet? Join Go to the forum in the Round Table Forum and let the Mentors know what you have. If it meets ERT standards, is factual and can help ERT visitors, then ERT Mentors and Editors can help you (without charge) polish your offering so it can be published and promoted by ERT. An article published on ERT may be read by as many as 10,000 visitors a week; promoting you, your site, and your ideas. Please note ERT does not publish re-prints; promotional handouts, or pieces consisting mainly of links. So original technical content only please. If you prefer you can email the Editor