# Perspective Projection Matrix Generation

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

## Recommended Posts

Hi, community.

The post is the following

https://nbertoa.wordpress.com/2017/01/13/how-can-i-find-the-pixel-space-coordinates-of-a-3d-point-part-2-perspective-projection-matrix-generation/

I tried to explain in detail about its generation and answer several question I had in the process.

If you have any suggestions (things to add, modify, things that are wrong, corrections, etc) please let me know, because the intention of this post (in addition to helping people with the same doubts than me) is to learn if my knowledge is correct or not.

Hope you find it useful!

##### Share on other sites

I only skimmed it, but one thing you may want to add: D3D uses the convention that the NDC z axis ranges from 0.0 to 1.0, but OpenGL uses the convention that the NDC z axis ranges from -1.0 to 1.0... So OpenGL users must construct their projection matrices differently.

Also, it's standard practice these days to map the far-plane to 0.0 and the near-plane to 1.0, as this gives better numerical precision due to quirks of floating point encoding -- the perspective division biases precision towards the near plane, and floating point numbers bias precision towards 0. With the typical mapping of near=0, this gives waaaaay too much precision at the near plane, and absolutely terrible precision at the far plane. With the alternative mapping of near=1, these two biases mostly cancel each other out and you end up with a mostly linear distribution of precision from near to far.

Edited by Hodgman

##### Share on other sites

I only skimmed it, but one thing you may want to add: D3D uses the convention that the NDC z axis ranges from 0.0 to 1.0, but OpenGL uses the convention that the NDC z axis ranges from -1.0 to 1.0... So OpenGL users must construct their projection matrices differently.

I explained that in Part 1, but it will be useful to repeat that in Part 2 too. Thanks!

Also, it's standard practice these days to map the far-plane to 0.0 and the near-plane to 1.0, as this gives better numerical precision due to quirks of floating point encoding -- the perspective division biases precision towards the near plane, and floating point numbers bias precision towards 0. With the typical mapping of near=0, this gives waaaaay too much precision at the near plane, and absolutely terrible precision at the far plane. With the alternative mapping of near=1, these two biases mostly cancel each other out and you end up with a mostly linear distribution of precision from near to far.

Thanks for that suggestion. I planned to talk about it in the next post about depth buffer, but I will mention this stuff in the part I want to map [nZ, fZ] ---> [0.0, 1.0]

1. 1
2. 2
Rutin
21
3. 3
4. 4
A4L
15
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633737
• Total Posts
3013607
×