Jump to content
  • Advertisement
Sign in to follow this  
zurekx

OpenGL Details about perspective projection

This topic is 3835 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

I want to know the details of OpenGL projection and clipping. All I know so far is that in order to make a perspective projection, one divides the vertex with the z-coordinate. But OpenGL has a projection matrix, what is this used for? Where in the process is the vertex divided by the z-coordinate? Any good resources on the entire process? (I just know OpenGL does some projection with a matrix which transforms the vertices into something called clip space, and after that I have no idea what happens).

Share this post


Link to post
Share on other sites
Advertisement
The details are not too complex... I guess a quick search on a good search engine with Google will give you better results.

But basically, all the transformations together maps a 3D position to a position on the screen. In other words they map the world objects onto the screen.

Here's a quick and simple explanation:

First, you have a "viewport" transform which will map a projected scene to the screen. It will map the "default" pixel positions to the ones defined by the screen or surface you render to.

Next, is the projection transform, this one maps 3D position to a 2D position which I called the "default" pixel position in the previous step. This is usually mapped to [-1, 1] horizontally and vertically (if I'm not mistaken) or something similar.

If you are in DirectX, here you'd have the view transform which corresponds to the "camera".

After that, you have the model/world transform which "moves" the objects in the scene from the origin (0,0,0) to the position, rotation and scaling it should be. In OpenGL the model transform also contains the view transform that corresponds to the camera.

All these transforms can be seen one way or the other depending on what you are working with.



Another way to see that, in OpenGL, instead of moving a camera, you are moving the entire scene. So all the objects are moved so the camera is looking in the direction -Z (or Z, I'm never sure what OpenGL is). Now from that, the projection transform projects the points on a coordinate system that goes from [-1, 1] horizontally and vertically and the remaining step is to map those to the area you are rendering to.

Projection transform can be perspective or orthogonal, perspective is the /z you were talking about.

I'm not sure about what OpenGL does but clip space is probably just the space all polygons that are not inside the area rendered are clipped.

If you need help, just say so... I'll try to find more informations on that. The OpenGL book (the "red book" I think) is probably a good reference for that.

JFF

Share this post


Link to post
Share on other sites
Actually, there's not really a division by z, it's a division by w ( the 4. homogenous coordinate). You have to use the projection matrix to 'move' the scaled and biased z component to w for the perspective effect. The division always happens right after the vertices are processed by the projection matrix (or your vertex shader). All the 3 remaining coordinates are then in the [-1,1] range, and this is where clipping and primitive assembly happens (at least theoretically, drivers and GPUs are of course free to use early-outs).

HTH

Share this post


Link to post
Share on other sites
Thanks guys, I understand it much better now when I see that you move the z-coordinate to the w and divide by w after projection. I didnt know the vertices were diveded by w before :)

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!