CS488 - Introduction to Computer Graphics - Lecture 13

Comments and Questions

  1. Due date for assignment 4
  2. List of project objectives

Ray Tracing

The idea is simple:

for each pixel
  calculate the eye/pixel ray
  project the ray into the scene
  apply illumination and shading calculations
  colour the pixel with the result

This calculation is linear in the number of pixels.


Now let's look at the parts of this algorithm

Eye-pixel ray

E + t*(P - E)

Find the First Intersection

closest = infinity
for each object in scene {
  if ( eye ray intersects ) calculate distance (t)
  if ( distance < closest ) closest = distance; set intersection
}

This calculation is linear in the number of objects

Object in scene

An object is a set of points {Q} satisfying

Solve the equation

The surface might be defined by an algorithm, or you may not be able to find an analytic solution. Then use a root-finding method

Object is planar, e.g. a triangle

Equation of the plane is \sum_i ai*xi = b. Where do the parameters (ai) come from?

Substitute eye ray into the plane equation and solve for t. This point is on the plane: is it inside the polygon?

  1. Triangle: calculate barycentric coordinates; if < 0 outside.
  2. Convex polygon: do n half-plane tests
  3. Clip the point against the polygon edges

Another idea: intersect in object coordinates

For a game application you can just use a bit mask


Shading for Ray Tracing

When we have found the intersection point we need to calculate a colour.

We know

  1. The eye ray, V
  2. Surface properties
  3. The normal vector

For each light

  1. Calculate illumination: RGB, l

    Accumulate outgoing light

How about shadows?

Use a line from the intersection point to the light source as an eye ray and do it all again.

How about reflection?

Calculate the deviation of the eye ray and continue following it.


Recursive Ray Tracing

Just what the name says, but why would you do it?

  1. Unusual light paths for illumination, such as colour bleeding, reflection

Surface Normals

Implicit surfaces, i.e., given by f(Q) = 0.

Transforming the normal vector

  1. Under an affine transformation, M, Q goes to MQ, and Q' goes to M(Q').
  2. The new tangent, n1, is defined by n1.M(Q'-Q) = 0.
  3. Notice the structure: contravariant versus covariant.

Constructive Solid Geometry (CSG)

Geometric primitives can make other geometric primitives by

  1. union
  2. intersection
  3. subtraction

The result is like sculpting; the problem is that describing the result is very difficult; the solution is


Texture Mapping

  1. Basic
    1. Start with a 2D image: pixellated or procedural
    2. Map 2D image onto primitive using a 2D affine transformation
      • Simple if the surface of the primitive is flat
      • otherwise, ...
      • Texture pixels normally do not match display pixels, so some image processing may be needed.
    3. Backwards map intersection point with ray into the image to get the surface properties
  2. Normal Mapping (Bump mapping)
    1. Start with a difference surface, defined with respect to the surface
    2. Calculate the normals to the difference surface and map them onto the surface of the primitive
    3. Use the mapped surface models for lighting
    4. No occlusion, shadows are wrong, silhouettes are wrong, nobody notices!
  3. Solid Textures
    1. Solution to mapping texture onto curved surfaces
    2. Usually procedural

Speeding Up Intersection Tests

  1. Bounding Volumes (usually Boxes)
    1. Find the smallest - or close to smallest - regular volume that encloses the object
    2. Use ray-intersect-volume as a pretest for fast negative results.
    3. Trade-off between
      • benefit of quicker `miss'detection
      • cost of getting a good bounding surface
      • Both increase as complexity of primitive increases

    Scene subdision

    1. Divide the scene volume into sub-volumes: many ways to do it, such as
      • quad-trees
      • oct-trees
      • BSP trees
      • ...
    2. List all primitives by sub-volume.
    3. Only test primitives in the sub-volumes through which a ray passes.


Return to: