0
\$\begingroup\$

A vertex shader is basically a transformation function that converts a vertex in your world space to a space that can be rendered on screen.

Since the screen is a 2 dimensional surface whats the purpose of the intermediate clip space? Why not have the vertex shader directly transform a 3d vertex to a 2d point on the raster surface?

\$\endgroup\$
5
\$\begingroup\$

There are a few reasons it's valuable to retain a third dimension of information.

  1. Depth Buffering

    To get near content to show up in front of far content, we need to retain some information about what pixels are "near" or "far." Without this information, we'd only be able to layer objects in the order that we draw them, reducing our ability to batch content and breaking the illusion of 3D content in cases that can't be solved by sorting (like two interpenetrating triangles).

  2. Z Clipping

    Our depth buffer only has so much precision, and a perspective projection has a singularity at the camera's location, so to keep the projection and sorting well-behaved we need to clamp the depth range of geometry we draw, and exclude content too close to the camera or too far away. This is done in clip space.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.