Clipping and introduction to the rendering pipeline (Oct 16 lecture)
      course notes and homework due Oct 23 before class

This week we talked about z-clipping and introduced the general framework of the rendering pipeline.

Clipping:

Within an N dimensional space you can embed an unbounded N-1 manifold that divides the space into two parts. For example, a plane can be divided in two by a line or by a circle (ie: into inside the circle and outside the circle). Similary, 3D space can be divided in two by a plane or some other unbounded surface (eg: paraboloid, ellipsoid, etc).

"Clipping" is an operation in which you throw away everything in the space that is on one side of the manifold. When rendering scenes in computer graphics, it is very useful to use planes to clip away those parts of 3D space that are out of view. In particular, it is useful to clip away everything that is not in front of the camera.

A plane in 3D space can be defined by using a linear equation:

f(P) = aPx + bPy + cPz + d
The plane contains those points P for which f(P) = 0. Let's say we want to clip our objects prior to rendering, throwing away all parts of the object where f(P) > 0, and keeping all parts of the object where f(P) <= 0. As we discussed in class, the key to this will be to clip the model one triangle at a time - before applying perspective.

We want to keep everything for which z <= -ε, where ε is some small number such as 0.001. So our clipping function will be:

f(P) = 0Px + 0Py + 1Pz + ε

As we said in class, clipping one triangle by a plane will produce one of the following shapes:

To clip a triangle by a plane, first it is necessary to learn how to clip a line segment [A,B] from point A to point B by the plane where linear function f(P) = 0.

First the two trivial cases: If f(A) <= 0 and f(B) <= 0 then the result is just [A,B]. If f(A) > 0 and f(B) > 0 then the result is nothing.

Suppose that f(A) <= 0 and f(B) > 0. We want to find a point C where f(C) = 0, and return the result [A,C]. Similarly, if f(A) > 0 and f(B) <= 0. We would return the result [C,B].

Finding C is done in two steps:

More formally: t = (f(C) - f(A)) / (f(B) - f(A)), which can also be written as: -f(A) / (f(B) - f(A)).

Given the above machinery, we can clip a triangle by going round the triangle, vertex by vertex, to construct a new polygon. Here is the procedure:

  For each triangle vertex A:
     Let B be the next vertex around the triangle after A

     • If f(A) <= 0
        • Add A to the new polygon

     • If A and B are on opposite sides of the clip plane (in other words, if f(A) * f(B) < 0)
        • Compute the point C where edge [A,B] crosses the clip plane
	• Add C to the new polygon
When you are done, you will have either 0, 3 or 4 vertices in the new polygon. If you end up with 4 vertices, then split the polygon into two triangles, and proceed onto the rest of the rendering pipeline with each of these two new triangles.

Homework:

Your assignment, due by next class, is two-fold: