Jump to content
  • Advertisement
Sign in to follow this  
NathanRidley

The 3D graphics pipeline: I don't understand why clip space is a cube, or how it relates to normalized device coordinates

This topic is 2098 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In the graphics pipeline, I understand that we take our models, which have localized coordinate systems that are really only relative to themselves, and we project them into our world view, by transforming their coordinates appropriately.
 
I also understand that we have a camera and we transform the vertices in the world view so that they are relative to the camera, as though the camera were a fixed object and we are moving the world around relative to the camera in order to create the illusion of a moving camera.
 
I think I kind of also get that we have "clip space", which seems to be the area of vertices that we'll see, because they are inside the perspective projection from the front clipping plane (the camera lens, effectively) to the back clipping plane. And this clipped perspective area is I guess sort of a truncated pyramid in shape.
 
Is clip space a cube because we kind of un-distort the aforementioned truncated pyramid volume back into a cube? And if so, why do we need to then scale by W to get normalized device coordinates? Wouldn't the conversion of the perspective projection to a clip space cube automatically scale the things at the back down to a smaller size?
 
I'm probably understanding this all wrong. Any help to understand this part of the pipeline would be much appreciated.

Share this post


Link to post
Share on other sites
Advertisement

The clip space is not a cube(not always). http://www.lighthouse3d.com/tutorials/view-frustum-culling/

 

The w component division i needed because you represent vertices not in 3D space but in a homogenous space. (in homogenus space p( 2,4,8, 2) and v(1,2,4,1) are the same point in 3D space..., really read a book about it. That is really important)

 

To find the real answers to your questions, you must read a book(or at least an article) about linear algebra.( can't give you good sources in engish).

Edited by imoogiBG

Share this post


Link to post
Share on other sites

The clip space is not a cube(not always). http://www.lighthouse3d.com/tutorials/view-frustum-culling/

 

The w component division i needed because you represent vertices not in 3D space but in a homogenous space. (in homogenus space p( 2,4,8, 2) and v(1,2,4,1) are the same point in 3D space..., really read a book about it. That is really important)

 

To find the real answers to your questions, you must read a book(or at least an article) about linear algebra.( can't give you good sources in engish).

The images at your link shows a outsider's view of the view space, not the clip space. The projection matrix transforms that view space into clip space, which often has the shape of a cuboid. In OpenGL, the visible coordinate range in clip space is from -1 to 1 along all three axes, forming a cube. Another common setup is a visible range of -1 to 1 along X and Y, but 0 to 1 along the Z-axis, thus almost making it a cube.

 

edit: Actually, the cube in clip space is formed by [X,Y,Z]/W. That may have been what you were talking about with the perspective division.

Edited by Brother Bob

Share this post


Link to post
Share on other sites

Thanks for the responses, though I don't think they break things down enough to properly address what I was asking

 

@imoogiBG - "read a book"? No suggestions? I actually have two books on order, though the first is a game dev math book, so maybe that will help.

 

@Brother Bob - I get the impression your response was more for imoogiBG than for me, as you recite facts that I've read already, but don't properly understand just yet. e.g. "which often has the shape of a cuboid" ... could you elaborate? Are we simply scaling down the back clipping plane of the view space so that it has the same dimensions as the front clipping plane?

Share this post


Link to post
Share on other sites

Thanks for the responses, though I don't think they break things down enough to properly address what I was asking

 

@imoogiBG - "read a book"? No suggestions? I actually have two books on order, though the first is a game dev math book, so maybe that will help.

 

@Brother Bob - I get the impression your response was more for imoogiBG than for me, as you recite facts that I've read already, but don't properly understand just yet. e.g. "which often has the shape of a cuboid" ... could you elaborate? Are we simply scaling down the back clipping plane of the view space so that it has the same dimensions as the front clipping plane?

 

 

Well I read books about math in my native laguage. But almost any book about math will help you.

Share this post


Link to post
Share on other sites

@Brother Bob - I get the impression your response was more for imoogiBG than for me, as you recite facts that I've read already, but don't properly understand just yet. e.g. "which often has the shape of a cuboid" ... could you elaborate? Are we simply scaling down the back clipping plane of the view space so that it has the same dimensions as the front clipping plane?

The transformation is a bit more elaborate than that. If you look at the first image in imoogiBG's link and visualize that the camera icon is pulled back towards infinity, then the projection lines (the edges of the frustum) becomes parallel, and the view volume takes the shape of a cuboid. That's what the projection matrix and the perspective division do.

 

There are some additional linear scales applied as well to transform the cuboid into a unit shape. For example, OpenGL defines a point [X, Y, Z, W] as visible in clip space if:

  1. -W < X < W
  2. -W < Y < W
  3. -W < Z < W

After perspective division, the inequalities become:

  1. -1 < X/W < 1
  2. -1 < Y/W < 1
  3. -1 < Z/W < 1

which has the shape of a cube since it extends from -1 to 1 along all three axes. I believe Direct3D defines, or did at least, define the third inequality as 0 < Z/W < 1 instead, which is not a cube since all since all dimensions are not equal in size.

Share this post


Link to post
Share on other sites

Perhaps a small addition to Brother Bob's explanation:  The reason you want to end up with a cube is so that you can easily map the coordinates in that space to a rectangular region which is your render target.  Since the typical perspective views through a rectangular window is actually a frustum, it isn't trivial to know what vertices map to which coordinates (in fact that is what ray tracing does - definitely non-trivial).

 

In addition to easing this mapping, it also greatly simplifies clipping and culling of primitives at that stage of the pipeline.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!