Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm currently learning OpenGL and haven't been able to find an answer to this question.

After the projection matrix is applied to the view space, the view space is "normalized" so that all the points lie within the range [-1, 1]. This is generally referred to as the "canonical view volume" or "normalized device coordinates".

While I've found plenty of resources telling me about how this happens, I haven't seen anything about why it happens.

What is the purpose of this step?

share|improve this question
add comment

5 Answers 5

up vote 5 down vote accepted

The most important is that it converts yours points(vertices) from 3D world space to 2D screen space.

That means that after vertex is multiplied with this matrix X and Y coords are position on the screen (between [-1, 1]) and Z is the depth. Z is used for depth-buffer and identifies how far is vertex (or fragment) from your cameras near plane.

Projection means that vertices which are more near from near plane are more far from middle of the screen -> triangle more near to camera appears to be bigger that one that is far. And this is based on yours field of view - you are entering it in some createProjectionMatrix function or createFrustum. It works that it shears and scales yours camera frustum and vertices in it into unit cube. Values that are greater than 1 and smaller than -1 are not displayed.

Also keeps pixel aspect ratio, so pixel can be sqaure. That is simple. It just shears camera frustum like this: more wider screen -> more vertical shear and vice versa.

Simple answer:
It defines yours camera frustum and is good to:

  • make objects which are near to you look bigger than objects that are far from you.
  • keep pixel aspect ratio - Everybody likes square pixel right? :)
share|improve this answer
    
I don't see any part where he asks what the projection matrix does. He just seems to wonder what the normalized device coordinates are for. –  Christian Rau Aug 24 '11 at 12:17
    
The projection matrix defines the camera frustum. But this doesn't explain the reason for having [-1,1] as the canonical viewing volume. Why not have [-100,100] instead? –  bobobobo Dec 1 '12 at 19:45
    
because 1 is "more common number" than 100 :D (0 is even more common, but cube 0x0x0 is not very interesting...) –  Ivan Kuckir Feb 20 '13 at 22:15
add comment

This answer is long after the fact, but since I found this on google maybe this will still help someone. I just want to clarify what JasonD and Notabene were saying: It is a lot easier to do clipping calculations (figure out what you should see and what you shouldn't see because of which way you are looking, how far away it is, ect.). Instead of checking if things intersect the planes on the borders of your view frustum, you simply compare the x,y,z of everything to xMax, xMin, yMax, ect. , since you simply have a cube. It is a little more complicated if you want to only have part of something showing, but the math is still better with a unit cube than with a frustum.

A couple things I found misleading in other answers:

-You aren't shearing the sides off of the view frustum, you are sort of warping it into a cube using homogeneous matrix transformations.

-We aren't converting to a 2D screen with this step. This step isn't necessary to do so. Theoretically we could do all our work without converting the frustum to a cube first, which would be more intuitive but harder math - but graphics is all about doing calculations really fast since there are a LOT of calculations per second for the average game/whatever.

More detail: It isn't necessarily a unit cube we are converting to, it just has to be a rectangular box for our max-min calculations to work out. In fact in class we used a box where the camera faces down the z-axis, z goes from 0 to 1, x goes from -1 to 1, and y goes from -1 to 1. In general in math 1, 0, and -1 are good numbers for making calculations easier, I assume that is why we don't go from -100 to 100 or something.

TLDR: It makes clipping easier.

Edit: bobobobo has the gist of it. Everything is triangles, generally :D.

Source: Taking a university graphics class

share|improve this answer
add comment

I believe this is because OpenGL can't make assumptions about how the image is to be displayed (aspect ratio or resolution, hardware details, etc). It renders and image into an intermediate form which the operating system or driver or whatever scales to the correct resolution/size.

share|improve this answer
    
You are not correct when you are speeking about hardware details. There are non. Also if you are writing you own rastarizator on cpu (why to do it? To learn how this stuff works :)) you are using same matrices as on gpu. You are lucky that i still dont have privileques to vote down :) –  Notabene Dec 7 '10 at 23:12
    
Doesn't it need to know the aspect ratio? From what I understand, it stores the scaling factors for X and Y so that the image will have the correct aspect ratio later on. –  breadjesus Dec 7 '10 at 23:44
2  
Correct me if I am wrong, but he is talking about after you project points, and thus we are talking 2D. If this is the case, then OpenGL doesn't know where on the screen you are putting this image, nor about how it is going to be displayed. It creates an image which is then easy to scale and place correctly, but it does not do that for you. I do agree that hardware details was a bad name for it, I simply meant the above. Also, you can specify a projection matrix with an aspect ratio, but that ratio does not have to be the same as your monitor's. –  Chewy Gumball Dec 8 '10 at 0:21
3  
I have to say that i really enjoy this conversation. You are near to be right. Lets go deeper. There are is no image after multiplacation vertices by projMat. Result is just set of 2D point with depth. Than rastarization begins and it creates images. (if on cpu it would draw lines between triangles verts and fill it (and shade it-whatever) ... on gpu it is performed just before pixel/fragment shader). And aspect ratio puts points which should be "scaled away" to values bigger than 1 or smaller than -1 and they will not be displayed. –  Notabene Dec 8 '10 at 0:44
2  
AHHH! I see the issue here. He said "This is generally referred to as the "canonical view volume" or "normalized device coordinates"." I was answering as if he was asking about normalized device coordinates, however he wasn't actually asking about those at all. They are, in fact, two completely different things and that is why we are at odds here. Perhaps that should be clarified so people don't make the same mistake I did. –  Chewy Gumball Dec 8 '10 at 20:40
show 2 more comments

I note an answer has already been accepted, but it's generally useful for clipping to have the view frustum transformed into a unit cube.

share|improve this answer
    
True, i little edited my answer to be more clear about this. –  Notabene Dec 8 '10 at 23:00
add comment

I've also been wondering this. There are a couple of things to consider.

First, yes, everything in the world gets transformed to that unit cube [-1,1] centered around the origin. If something isn't in that unit cube then it isn't going to be displayed.

The nice thing about this is now, you can cull triangles pretty easily. (If all 3 vertices of a triangle have x > 1 or x < -1 then that triangle can be culled).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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