
Title:
Clipping  Interactive 3D Graphics

Description:

I left out a step that happens after projection and before division by W.

Clipping. Say we have 2 points: 0, 4, negative 6 after perspective

transformation that turns into 0, 4, 5, 6 and 0, 6, negative 4, which turns

into this value. They form a line segment. These two points in this line

segment are shown on this zoomed in part of our frustum. The second point is

outside of the frustum. We want to have all coordinates inside our final view

volume in NDC space so that we can render them. Clipping is done for line

segments and triangle edges that poke out through the frustum. An edge can be

clipped by any numbers of faces of the frustum. What happens here is that all

the coordinates between the two points get linearly interpolated. For our

example the point on the frustum faces halfway between our two points. The

interpolated point is then 0, 5, 3.85. We then divide this point by W as usual

to get a point in normalized device coordinates. Here's a rough overview of how

clipping can work. You start with a triangle that's poking out through the

frustum. Say the left face of the frustum first cuts the triangle. This creates

two triangles. Later, the top face of the frustum chops off the other part of

the triangle. This create three triangles total that will then be rasterized

separately by the GPU. You as a user don't really have to know or care much

about this clipping process. It happens automatically. It's worth knowing about

mostly if you need to do similar testing operations on the CPU side. In

computer graphics we often make a big deal about how we store 3D points in

vectors as homogeneous coordinates, with the fourth element W. In reality, for

almost every operation, the W value is either 0, meaning a vector, or 1,

meaning a point. It's only after projection and during clipping that the W

value is anything but 1. Once clipping is done and we're using normalized

device coordinates, we're done with homogeneous coordinates. However, these

homogeneous coordinates are important in that they're what the vertex shader

produces. When the coordinate is transformed by the projection matrix, but

before the division is performed, the coordinates are called clip coordinates.

The vertex shader can produce other intermediate results, such as computing

location once the model and view matrices are applied. It is required that the

vertex shader produce a position on the screen for the vertex. This position is

a homogeneous coordinate. The rasterizer then takes this position and performs

clipping.