Tuesday 31 May 2011

Friday 21 September 2007

How does Ray Tracing Work?

A clue to the underlying rendering technique used in ray tracing is obtained from it’s very name. A ray is ‘…a formal term for a line that has one end point fixed’ (Glassner 1993:8). The fixed end point for the line is ultimately the human eye. For computational efficiency, rays are followed (or traced) backwards ‘…through a pixel in the image plane into the scene to determine what it hits.’ (Owen 1999). Tracing rays backwards as opposed to following them forwards from the light source, ensures that the ray will make a contribution to some extent in what is being viewed in the view plane. Ray tracing uses recursion to generate secondary rays from ray surface intersections. In order to make ray tracing more conceptually understandable Glassner divides rays into three groups shadow, reflection and transparency, stating that these they are the ‘…principle ways light arrives at (and leaves from) a surface’ (Glassner 1993:10).

The diagram in fig 1 shows the backwards tracing of a ray through the virtual screen (or view panel). When ray hits the object in the scene another ray called the shadow ray is generated and sent towards the light source. If on the way to the light source it hits any other objects it can be concluded that this point on the surface is in shadow from the light source. If a shadow ray reaches the light source then it stops being a shadow ray and can be ‘…thought of as a illumination ray which carries light to us from the light source’ (Glassner 1993:11).

Figure 1: Principle of Ray Tracing

This explanation of how a shadow ray behaves is what would happen if the ray hits a object with matt or opaque material properties. Depending on the objects reflective material properties when a ray hits an object a reflected ray for that point is generated whose angle of reflection is equal to its angle of incidence as seen in the fig 2. To determine the colour of this ray it is followed ‘…backwards to find from which object it began’ (Glassner 1993:13). For point P on the object we need to know the colour of ray A as this is the light ray which is bounced off the object into the image plane and from there into our eye.


Figure 2

If the material properties of the object intersected by the ray are transparent a transmitted ray is generated (Owen 1999). This ray is traced backwards through the object where the light ray may bend because of refraction which is the slowing down of light. This refraction of light is computed using Snell’s law. Hence ray tracing can be seen as modeling the real world physics of transparent objects.

The main difference between scan conversion and ray tracing is that ray tracing algorithms are applied to every pixel on a viewable surface. Scan conversions approach is that the 3D world is constructed entirely of convex polygons and lighting values are only calculated at their vertices and interpolated across scanned lines. This model

of illumination is local because only light that is directly reflected from the surface is considered. In ray tracing a tree structure (fig 3) is spawned for every pixel and by moving up the tree to the root node combining each leaf nodes light intensity on the way as determined by the Phong illumination model, the pixel value is obtained (Langbein). By using this tree structure ray tracing is using global illumination model because light that as reflected of other objects in the scene is taken account of in the rendering.

Fig 3

In contrast to ray tracing, scan conversion uses three steps to render an image these are projection of the vertices into 3D space, scan conversion and hidden surface removal. The ray tracing algorithm inherently performs hidden surface removal using the tree structure seen in fig 3 where as scan conversion uses an additional algorithm to compute this such as the depth buffer algorithm.

Thursday 20 September 2007

Test post 1

The is a first test post