Demystifying the 3D Rendering Pipeline — Part 2: Clipping & Projection

Nipun David
XRPractices
Published in
5 min readMar 26, 2024

Welcome to the second installment of this series, “Demystifying the 3D Rendering Pipeline.” In this segment, we delve into the crucial concepts of clipping and projection within the 3D rendering process. If you’re keen on enhancing your understanding of these integral components, continue reading. However, if you’re yet to explore Part 1 of this series, I recommend reviewing it first for a comprehensive foundation.

3. Clipping

An essential optimization step that removes geometry or part of geometry lying outside the camera’s view frustum. Imagine the camera’s view frustum as a pyramid-shaped volume defining what’s visible on screen. Clipping eliminates objects or part of this object outside this frustum, preventing wasted processing power on rendering unseen geometry.

https://commons.wikimedia.org/wiki/File:Frustum_clipping.svg

Common Clipping Algorithms

Several algorithms handle clipping effectively, with two prominent ones being:

Cohen-Sutherland Algorithm: This algorithm works by iteratively checking each vertex of a polygon against the six planes defining the view frustum (near, far, left, right, top, and bottom). Vertices inside the frustum are retained, while those outside are clipped or discarded. The algorithm efficiently calculates the intersection points where the polygon edges pierce the frustum planes, generating new vertices if needed to define the clipped polygon.

Sutherland-Hodgman Algorithm: This algorithm builds upon the Cohen-Sutherland algorithm and is particularly useful for clipping complex polygons that may have self-intersections. It handles situations where an entire polygon might lie outside the frustum but still contributes visible lines or points to the final image.

Benefits of Clipping:

  • Improved Performance: By eliminating unseen geometry, clipping significantly reduces the number of calculations required for rendering, leading to smoother frame rates and better performance.
  • Reduced Memory Usage: Clipping minimizes the amount of geometric data the GPU needs to store and process, freeing up valuable memory resources.

Clipping in the Rendering Pipeline:

Clipping typically occurs after the model and camera transformations have been applied but before the perspective projection stage. This ensures we clip objects in their final transformed positions relative to the camera’s view.

4. Projection

Projection transforms 3D coordinates into 2D coordinates for rendering onto a 2D screen. Perspective projection and orthographic projection are two common techniques used in computer graphics. Perspective projection mimics the human eye’s perspective, while orthographic projection maintains parallel lines.

Types of Projection

Perspective Projection: This is the most common projection type used in 3D graphics as it mimics real-world vision. It creates the illusion of depth by making farther objects appear smaller. Objects closer to the camera appear larger, and parallel lines in the 3D world converge towards a vanishing point on the horizon as distance increases.

Orthographic Projection: This type of projection creates a parallel view of the scene as if looking at a blueprint. Objects retain their relative size regardless of their distance from the camera.

Choosing the Right Projection

  • Perspective projection: Ideal for creating realistic scenes with a sense of depth, perfect for 3D games, simulations, and cinematic experiences.
  • Orthographic projection: Preferred for applications where accurate representation of size and relative positioning is essential, like architectural modeling, user interface (UI) elements, or 2D game levels.

Unlike clipping which relies on algorithms like Cohen-Sutherland, projection itself doesn’t involve specific algorithms. It’s a mathematical transformation that takes a 3D point and converts it to a corresponding 2D point on the screen based on the chosen projection type.

Perspective Projection Example:

Imagine a long hallway with evenly spaced columns. In perspective projection, the columns will appear to shrink as they recede into the distance, converging towards a vanishing point on the horizon. This creates the illusion of depth, mimicking how our eyes perceive the scene.

Orthographic Projection Example:

Imagine a toy box filled with various building blocks. In orthographic projection, each block would be displayed as if looking directly at its front, top, or side face, depending on the chosen orthographic view.

Handling Projection in the Pipeline:

Projection typically occurs after clipping and before rasterization. Here’s how it’s handled:

  1. Camera Definition: The camera’s position, orientation, and field of view (FOV) are established. The FOV defines the horizontal angle of the scene captured by the camera.
  2. Transformation Matrix Creation: Based on the camera parameters, a projection matrix is calculated. This matrix encodes the mathematical formulas for transforming 3D points into 2D based on the chosen projection type (perspective or orthographic).
  3. Vertex Transformation: Each vertex of the model is multiplied by the projection matrix. This transforms the vertex from its 3D world space coordinates into a 2D homogeneous clip space coordinate.
  4. Perspective Division: In perspective projection, an additional step called perspective division is often performed. This further refines the clip space coordinates, accounting for the camera’s FOV and ensuring proper depth representation.

After Projection:

The resulting 2D clip space coordinates are then used in the subsequent stages of the rendering pipeline, such as rasterization, where they are converted into actual screen pixels which we will cover in part 3.

In this segment, I’ve focused exclusively on two pivotal phases of the rendering pipeline: clipping and projection. However, it’s essential to note that the rendering process comprises several additional critical steps beyond these. These encompass rasterization, visibility determination, shading, texturing, and ultimately, rendering.

References -

--

--