Clipping Against the View Frustum

After culling objects against the view frustum, we know all objects whose bounding spheres lie at least partially within the frustum. We can then process these objects as normal—performing back-face culling, perspective projection, clipping to the 2D view window, and rasterization.

However, with the addition of the 3D view frustum, we now can make a change to one step: the clip against the 2D view window. Recall that projection of a polygon from 3D into 2D can lead to vertices which lie outside of the 2D view window. Our solution up to this point was to clip the projected polygons in 2D against the view window to ensure that only the part lying within the window would be drawn.

But clipping projected polygons in 2D to the view window has some quirks. In particular, the new vertices that may be generated from a 2D clipping operation do not directly result from a 3D to 2D projection of an original vertex in the polygon. We've mentioned this fact in a number of places before. This lack of original 3D information for the vertices generated by 2D clipping led us to develop a reverse projection strategy to obtain the corresponding 3D coordinate for such 2D vertices. We needed this for the Mesa/OpenGL texture mapping strategy of Chapter 2. Furthermore, clipping texture coordinates in 2D required us to clip u/z, v/z, and 1/z, instead of u and v, because u/z, v/z, and 1/z can be linearly interpolated and clipped in 2D, whereas u and v cannot.

Reverse projection and the linearity of u/z, v/z, and 1/z in 2D screen space are important topics to understand, but we can sidestep these issues by performing clipping in 3D instead of in 2D. Instead of clipping projected polygons against the 2D view window, we can now clip world space polygons in 3D against the planes of the 3D view frustum. Mathematically, this produces exactly the same results as the clip in 2D to the 2D view window. In 2D, we clip against the edges of the view window; in 3D, we clip against the planes, computed via reverse projection, passing through these same edges and the eye. But by performing the clipping in 3D, we can directly clip the u and v values instead of u/z, v/z, and 1/z. We saw this in the class l3d_polygon_3d_textured. Furthermore, this means that all polygon vertices in 2D directly result from the projection of a 3D vertex. This would eliminate the need for certain reverse projection operations that we used for the Mesa/OpenGL texture mapping strategy.

Personally, I feel that there are arguments for both 2D and 3D clipping, so you can choose whichever seems more comfortable to you. The next sample program eliminates 2D clipping entirely and does all clipping in 3D, so you can see how it is done.

toJ) CAUTION Do not confuse culling against the view frustum, which is a possibly hierarchical inside/outside classification operation, with clipping against the view frustum, which is an actual change of the underlying geometry of an object to ensure that only the part inside the frustum remains.

Was this article helpful?

0 0

Post a comment