Last Updated April 19, 2010
Once the scene has been projected and normalized, we must do some post-processing in order to display a view of the model.
Post-processing involves:
We need to traverse the model and check each polygon to see if it is visible. For each face of an object we can calculate the 'outward' normal by normalizing the cross product of two non-collinear vectors lying on the polygon face. Alternatively, we can use Newell's method to calculate the face normal. This method works for non-planar polygons and we do not need to test for collinarity. Graphics Gems III, David Kirk (editor), Academic Press, 1992, ISBN: 0124096735
\[ \vec{\mathbf{n}}=|\vec{\mathbf{a}} \times \vec{\mathbf{b}}| \]Once the outward normal has been calculated, we need to choose any point $ \vec{q} $ on the face.
We are interested in the angle $\theta$ , between the vector $(\vec{e} -\vec{q} )$ and the normal vector $\vec{n} $ (figure below). If this angle is greater than $90^{\circ}$ , then the face is a backface (the face is oriented away from the eye). We can perform this test with a simple dot product, the dot product of two vectors is related to the angle between them. A face is a backface if the following holds true:
\[ \vec{n} .(\vec{e} -\vec{q} )<0 \]If this expression is zero then the face lies parallel to the line of sight and is therefore visible.
We can now process the model to remove the backfaces, typically removing backfaces will halve the number of polygons to involved in further processing.
Before we start filling polygons, we must clip them to the edges of the view volume. We can do this with the Sutherland-Hodgeman polygon clipping algorithm. This process involves clipping individual edges against the sides of the 'clipping polygon'. A separate algorithm is available for edge clipping, this is called the Cohen-Sutherland algorithm.
As with most graphics procedures, edge clipping needs to be very efficient, as there are typically thousands of edges in a scene. Edge clipping involves testing a line segment against a clipping rectangle and then clipping the line segment until it lies entirely within the clipping rectangle.
We must first determine if the end points of the edge lie inside or outside the clipping rectangle (window). Each edge of the window defines an infinite line that divides the plane in to an inside and outside half-space.
For each end-point (x,y), we associate a 4-bit code, with one bit for each edge of the window. This code will be used to record if the end-point is in any of the 4 outside half-spaces. The bits will be set as follows;
This allows us to make the following two tests;
In all other cases, the line-segment needs to be clipped against the window. A divide and conquer strategy is used. The line segment is clipped against one of the edges, this produces a new line segment. The new line segment is the subjected to the tests above. This process continues until the line-segment is rejected or accepted according to the tests above. A line segment needs to be clipped against an edge, if the corresponding bit has been set for one of its end-points.
In the figure above, we wish to clip the line segment $P_{1}(x_{1},y_{1}), P_{2}(x_{2},y_{2})$ to the clipping edge given as $x_{right}$ . The desired line segment is $A(x_{a}, y_{a}), P_{2}$ . We know that$ x_{a}\equiv x_{right}$ . Using the equation of a line where $m$ is the slope;
\[ a_{y}=m(x_{right}-x_{2})+y_{2} \]We can use similar reasoning in order to clip against other edges. The full clipping algorithm can now proceed as follows;
This algorithm, like the Cohen-Sutherland edge clipping algorithm, uses a divide an conquer approach and uses the edges of the clipping rectangle to divide space into inside and outside half space.
The basic operation is to clip the polygon against one edge of the clipping rectangle, this operation produces a new (clipped) polygon (see figure below), which we then clip against the remaining edges in turn. To clip the polygon against one edge, we simply clip all the edges of the polygon against the edge of the clipping rectangle. As each edge is clipped, new vertices are output according to certain rules. Each edge has and start point $s$ , and an end point $f$ , there are 4 possible configurations between and edge and the inside/outside half-spaces;
The set of vertices output after traversing the polygon becomes the new (partially clipped polygon) for the next clipping edge.
© Ken Power 1996-2016