CS184 Lecture 38 summary

Clipping

Clipping is the process of computing the parts of a scene that fit in a viewing window or volume. It usually proceeds the other stages of rendering, because some geometry can be removed completely during clipping, which eliminates computation later on.

Line Clipping

Say that a line segment P1P2 in the plane (assume its been projected) is given as

P = (1 - u) P1 + u P2

and assume that P1 is the left endpoint. Then to clip against a rectangular region, we clip in turn against each boundary of the region. Lets start with the left edge, which is defined by x = xmin. Using P1 = (x1, y1) and P2 = (x2, y2), we have that

xmin = (1 - u) x1 + u x2

and solving for u gives:

ux = (xmin - x1) / ( x2 - x1)

Now if is ux < 0, the intersection is outside the line segment, and the line does not change after clipping. If 0 < ux < 1, then the left part of the line is clipped. We replace P1 with

P'1 =  (1 - ux) P1 + ux P2

as the left endpoint of the edge. If ux > 1, then the segment is entirely to the left of, and outside of the clipping region.

Polygon Clipping

Relies on polygon orientation. Polygons are normally oriented counter-clockwise. The material of the polygon is on the left side as you walk around the boundary ccw. When we clip a polygon, we can do it by clipping the individual line segments that comprise the polygon. But that leaves dangling endpoints at the clipping boundary. To join these, we walk along the boundary, and each time we hit a segment endpoint, we (i) start a segment if the edge direction points out of the clipping region or (ii) finish a segment if the edge direction points into the clipping region. The result should be closed polygons with a ccw orientation.

Clipping is normally done by clipping against each boundary in turn. That way, new vertices at the corners of the clipping region will be automatically created if necessary. Examples

Clipping Volumes

For 3D environments, a clipping volume is used. The volume is usually either a box or a frustrum (volume of the rectangular cone through the viewing window that lies between front and back planes normal to the viewer). To clip polyhedral objects, you clip each of their faces against one of the clipping planes. Clipping a 3D polygon against a plane is just like clipping a 2D polygon against a line. You work in the plane of the polygon, and intersect the clipping plane with it, giving a clipping line. Clip the polygon in the usual way against this line.

After all polygons have been clipped in this way, you have a new set of objects which will not be solid any more if they have been clipped. To close them off, new polygons are added in the clipping plane. Each of these polygons has edges which were created when one of the original polygons was clipped. Those edges will form boundary loops for the new polygons, but we still need to determine their orientation (i.e. inside-outside). To do that, we use the surface normals of the original polygons. The normals point out of the surface by convention. So when a new polygon is created out of clipping plane edges, we orient those edges so that the material side (inside) of the polygon is on the opposite side from the normal.