Processing math: 100%
up to Schedule & Notes

Clipping in the CCS

Points outside the view frustum must be clipped. The clipping could be done in almost any coordinate system, but it's best to do clipping in the CCS because:

  1. The canonical view volume in the CCS is independent of camera parameters. That means that clipping in the CCS can be implemented in hardware which doesn't have to be parameterized ... so it's fast. There's no point earlier in the sequence of transformations where clipping can be done in a camera-independent manner.
  2. After the perspective division (CCS-to-NDCS) some depth information is lost, which can result in improper clipping (as discussed below). So it doesn't make sense to clip after the CCS.

Example of Improper Clipping in the NDCS

In the figure below, the segment pq in the VCS is transformed to the segment pq in the NDCS. If we clip pq, the segment will appear to be exiting the far plane of the canonical view volume. But it should really exit the top plane!

For example, if q=[0,0,100,1]T and n=1,f=2,r=+1,l=1,t=+1,b=1 then q is behind the viewpoint (as above) and the projection matrix is

[1000010000340010]

Then q=Pq=[x,y,z,w]T=[0,0,304,100]T and, upon division by w we get [0,0,3.04]T, which is ahead of the viewer instead of behind, as the original q was.

For a better intuition, consider what happens to q as q is moved along the z axis of the VCS:

Proper Clipping in the CCS

If the point were in NDCS, we would clip against the six planes that define the faces of the canonical view volume:

xw=+1xw=1yw=+1yw=1zw=+1zw=1

The corresponding planes in the CCS are:

xw=0x+w=0yw=0y+w=0zw=0z+w=0

Given a segment pq in the CCS, we clip against each of the six planes. Note that these are planes in a 4D homogeneous space, but clipping works the same in any dimension, as we'll see below.

Clipping a Segment Against a Plane

A line segment ab has endpoints a and b. It can be written in parametric form as

(t)=a+t(ba)

For t[0,1], (t) is between a and b. For t outside this interval, (t) is not on the segment ab.

A plane π is defined by a normal, n, and a distance from the origin, d. All points x on the plane satisfy the implicit equation

π(x)=nxd=0

Points above the plane (i.e. on the side of the plane that n points to) will have π(x)>0. Points below the plane will have π(x)<0.

Segment ab is clipped by the plane if and only if its endpoints lie on different sides of the plane. So compute π(a) and π(b). Then ab intesects π if and only if π(a) and π(b) have different signs. (If one or both are equal to zero, ab is not clipped because it does not cross the plane.)

If ab is clipped by π, we need to find the point at which ab intersects π, to clip ab at that point.

To find the point of intersection, substitute the parametric segment equation into the implicit plane equation and solve for the parameter t:

0=π((t))0=π(a+t(ba))0=n(a+t(ba))dt=dnan(ba)

Then the intersection point is (t).

up to Schedule & Notes