Articles.....

Ray Tracing

Introduction:

The aim of computer graphics is to generate photorealistic images. Rendering programs are used to generate the image from the 3d model.  Rendering algorithms renders the informations e.g. geometry, texture, lighting, shading and viewpoint. The main rendering techniques are scanline rendering and rasterization, raycasting, radiosity and raytracing.

Raytracing technique is used to generate photorealistic images. The idea behind the raytracing is to compute the direct illumination (direct light) and indirect illumination (bounce light) coming on the object. The raytracing technique was developed by Turner Whitted in 1979. In this technique a ray travels from the pixel and calculate the color of the visible object through that pixel. When a ray intersect the object then three ray are generated from intersection point i.e. Reflection Ray, Transparency Ray and Shadow rays. The color of the intersection point is sum of the direct illumination, reflected color, transparency value and shadow.  If the ray does not hit any object then background color is returned to the pixel.

Raytrace Model (Courtesy Intel Corporation)

Shadow Ray:

Shadow ray travels toward the light source. If the ray intersects any object before reaching to the light source then the previous intersection point (starting point of shadow ray) is treated as a shadow area.

Reflected Ray:

When a ray hits an object then along with shadow rays the reflection ray is also generated. When a reflected ray intersects the object than at the intersection point local illumination is calculated and the result is applied on the previous intersection point (origin of the reflection ray).

Transparency Ray:

It has similar concept as reflected ray. As it intersect the object, then at intersection point the local illumination model is computed and the result is applied on the previous intersection point (origin of transparency ray). 

Basic Ray tracing Algorithm:

The algorithm is basically finite recursive algorithm. It should stop after given number of loops.

  1. Shoot a ray from the pixel.
  2. Find the nearest intersection point;
  3. Compute the direct illumination for each light source at the intersection point.
  4. Shoot the secondary rays : Reflection, Transparency and Shadow
  5. Calculate the intensities (color) of the point.
  6. Start new rays.

The pseudo code for a reflective object:

for each pixel of the screen
{
  Final color = 0;
  Ray = { starting point, direction };
  Repeat 
  {
    for each object in the scene
    {
      determine closest ray object/intersection;
    }  
    if intersection exists 
    {
      for each light in the scene
      {
        if the light is not in shadow of another object
        {
          add this light contribution to computed color;
        }      
      }
    }
    Final color = Final color + computed color * previous reflection factor;
    reflection factor = reflection factor * surface reflection property;
    increment depth;
  } until reflection factor is 0 or maximum depth is reached;

 

Basic algorithm can be divided into two parts

  1. Direct Illumination computation at the intersection point.
  2. Tracing. It calls direct illumination and then again trace

Direct Illumination:

Intersection is;
Color direct_illumination (is) {
           
            Color pointColor=black;
            for (n=1, n<=number_of_lights, n++) {
           
                         Ray shadowRay;
                        If ( intersection is not in shadow)
                                    pointColor+=get_color(is);      

}
            return pointColor;
}

 

Trace method:

Color trace(Ray ray){

// whether it hits an objects present in the scene
bool hit;

// intersection point between ray and object and has information about normal, // position, material, object name.

Intersection is;

//Initialize the color
Color pointColor, reflectedColor, transparencyColor;

 

hit = intersectScene(ray,is); // True or false

 if (hit && (depth <recursion_depth)) {

pointColor=direct_illumination(is);

if (object_is_reflective){
            reflectedColor=trace(reflectedRay);
            pointColor= (1- objReflectivity) * pointColor + objReflectivity *    
                                                                     reflectedColor;
}
           
if (object_is_transparent){
            transparentColor=trace(transparentRay);
            pointColor= (1- objTransparency) * pointColor + objTransparency
                                                                                         * transparentColor;
}
}
else {
            pointColor=backgroundColor;
}
return pointColor;

}

Ray Tracing by Brajesh Lal


Top
 
Disclaimer: The text; articles; photographs, on this website could be taken from various sources and is only for information purpose. It has no commercial usage, whatsoever
www.GraphicImaage.com      l      www.Indianartbazar.com      l      www.bollywoodstaff.com      l      © The animation News 2007-08