Skip to content
Near-Plane Clipping
step 1/5

Reading — step 1 of 5

Read

~2 min readRasterization

Near-Plane Clipping

A vertex with negative w after the projection multiply means it's behind the camera. Naively dividing by w flips the geometry inside-out: the triangle wraps around through infinity. You can see this bug in homemade renderers as a single triangle suddenly painting the entire screen when you walk past it.

The fix is near-plane clipping: before perspective divide, clip every triangle against the near plane (z = -near in eye space, or equivalently -w <= z in clip space).

Sutherland-Hodgman polygon clipping against one plane:

1. Iterate edges of the input polygon (V0->V1, V1->V2, V2->V0).
2. For each edge from A to B:
   inside_A = A is on the visible side of the plane?
   inside_B = B is on the visible side of the plane?
   case (inside_A, inside_B):
     (T, T): emit B
     (T, F): emit intersection(A, B)
     (F, T): emit intersection(A, B); emit B
     (F, F): emit nothing
3. The output is a polygon (could be triangle, quad, or pentagon).
4. Fan-triangulate the result if downstream wants triangles.

For the near plane in eye space (z = -near), the intersection between A and B is:

t = (A.z + near) / (A.z - B.z)              # parameter on [0, 1]
P = A + t * (B - A)                          # position
attr_P = lerp(attr_A, attr_B, t)            # for color, UV, normal, etc.

Why one triangle becomes a quad: chopping a triangle with a single plane can produce 3, 4, or 0 vertices. The 4-vertex case (one vertex behind plane, two in front) is the common one; you must split the resulting quad into two triangles before the rasterizer can swallow it.

Why not just discard triangles where any vertex is behind? Half-on-screen triangles vanish — a wall ten feet in front of you blinks out. Clipping preserves the visible portion.

This routine plus a full frustum clip (six planes: near, far, left, right, top, bottom) is what makes a real-time renderer crash-free as the camera moves through the world.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…