Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does the transition from clip space to screen coordinates happen?

I was studying the rendering pipeline and when I got to the clipping stage it was explained that from the view (eye or camera) space we have to pass to the clip space, also called normalized device space (NDC), that is a cubic space from -1 to 1.

However, now I don't understand when the passage from this space to the screen coordinates space happens:

  1. Right after clipping and before rasterization?

  2. After rasterization and before scissor and z-test?

  3. At the end just before writing on the frame buffer?

like image 510
StrG30 Avatar asked Feb 17 '14 23:02

StrG30


People also ask

Is clip space the same as screen space?

Clip space is what you get when you apply the projection matrix. This gets a bit complicated, but basically it gets things ready for rasterization by putting what will appear on screen in -w to +w range. Screen space is clip space after rasterization, which is clipPos.

What are clip space coordinates?

The clip coordinate system is a homogeneous coordinate system in the graphics pipeline that is used for clipping. In OpenGL, clip coordinates are positioned in the pipeline just after view coordinates and just before normalized device coordinates (NDC).

How matrices are used to transform local space coordinates to clip space?

To transform vertex coordinates from view to clip-space we define a so called projection matrix that specifies a range of coordinates e.g. -1000 and 1000 in each dimension. The projection matrix then transforms coordinates within this specified range to normalized device coordinates ( -1.0 , 1.0 ).

What are NDC coordinates?

Normalized device coordinate or NDC space is a screen independent display coordinate system; it encompasses a cube where the x, y, and z components range from −1 to 1. Although clipping to the view volume is specified to happen in clip space, NDC space can be thought of as the space that defines the view volume.


2 Answers

No, clip space and NDC space are not the same thing.

Clip space is actually one step away from NDC, all coordinates are divided by Clip.W to produce NDC. Anything outside of the range [-1,1] in resulting NDC space corresponds to a point that is outside of the clipping volume. There is a reason the coordinate space before NDC is called clip space ;)

Strictly speaking, however, NDC space is not necessarily cubic. It is true that NDC space is a cube in OpenGL, but in Direct3D it is not. In D3D the Z coordinate in NDC space ranges from 0.0 to 1.0, while it ranges from -1.0 to 1.0 in GL. X and Y behave the same in GL and D3D (that is, they range from -1.0 to 1.0). NDC is a standard coordinate space, but it has different representation in different APIs.

Lastly, NDC space to screen space (AKA window space) occurs during rasterization and is defined by your viewport and depth range. Fragment locations really would not make sense in any other coordinate space, and this is what rasterization produces: fragments.


Update:

Introduced in OpenGL 4.5, the extension GL_ARB_clip_control allows you to adopt D3D's NDC convention in GL.

Traditional OpenGL behavior is:

glClipControl (GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE); 

Direct3D behavior can be achieved through:

glClipControl (GL_UPPER_LEFT, GL_ZERO_TO_ONE); // Y-axis is inverted in D3D 
like image 198
Andon M. Coleman Avatar answered Sep 28 '22 05:09

Andon M. Coleman


Clip space and NDC (normalized device coordinates) are not the same thing, otherwise they wouldn't have different names.

Clip space is where the space points are in after the point transformation by the projection matrix, but before the normalisation by w.

NDC space is the space points are in after the normalisation by w.

http://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/projection-matrix-GPU-rendering-pipeline-clipping

Camera space -->  x projection matrix --->  Clip space (before normalisation) ---> Clipping --->  Normalisation by w (x/w, y/w, z/w) ---> NDC space (in the range [-1, 1] in x and y) 
like image 35
user18490 Avatar answered Sep 28 '22 05:09

user18490