I've been trying to understand perspective projection transformation in openGL. Why is it that the z coordinates typically get mapped non-linearly (considering issues with z-fighting), rather than linearly into the canonical view volume? Is it simply because linear mapping can't be cast nicely by a matrix multiply and a w-divide?
Thanks,
Tobey
Perspective Projection Transformation
Started by tobeythorn, Dec 10 2008 11:19 PM
7 replies to this topic
#1
Posted 10 December 2008 - 11:19 PM
#2
Posted 11 December 2008 - 02:37 AM
You can certainly do a linear mapping if you want, using a slightly different than standard projection matrix. However, you put your finger on the issue - z-fighting. You generally want things that are closer to be more sensitive to depth differences than things that are further away, as things that are closer tend to be bigger in screen space. It's a tradeoff.
reedbeta.com - developer blog, OpenGL demos, and other projects
#3
Posted 11 December 2008 - 09:20 AM
Reedbeta said:
You can certainly do a linear mapping if you want, using a slightly different than standard projection matrix. However, you put your finger on the issue - z-fighting. You generally want things that are closer to be more sensitive to depth differences than things that are further away, as things that are closer tend to be bigger in screen space. It's a tradeoff.
Z-fighting is not the reason behind the projection matrix being the way that it is. The reason is perspective-correct rasterization. The fact that there is more z precision closer to the camera is simply a benign side effect of the requirement that 1/z be interpolated across a triangle instead of z. For a thorough understanding of all this, I recommend reading Sections 4.4 and 4.5 of my book Mathematics for 3D Game Programming and Computer Graphics.
#4
Posted 11 December 2008 - 09:41 AM
I don't think you can linearize z-buffer with different projection matrix, but you can do it in vertex shader by multiplying z with w. Anyway, even though this makes z values linear at vertices I believe it makes them non-linear inbetween due to perspective projection, so you would have to do this in pixel shader (i.e. write to oDepth) which would be a performance killer.
#5
Posted 11 December 2008 - 11:03 AM
i just use linear z in my application and it worked fine, but i have a question - is the z value from the projection matrix the 1/z?
cause i dont know either. and what is its purpose, how does the clipper fit into this, because once a vertex is projected how are you supposed
to clip it with the near plane, i did it with a separate transform with the view matrix and clip that first, then do the rest in quick 2d.
cause i dont know either. and what is its purpose, how does the clipper fit into this, because once a vertex is projected how are you supposed
to clip it with the near plane, i did it with a separate transform with the view matrix and clip that first, then do the rest in quick 2d.
#6
Posted 11 December 2008 - 12:23 PM
rouncer said:
i just use linear z in my application and it worked fine, but i have a question - is the z value from the projection matrix the 1/z?
#7
Posted 11 December 2008 - 05:42 PM
elengyel said:
Z-fighting is not the reason behind the projection matrix being the way that it is. The reason is perspective-correct rasterization.
Ah, yes. You're right of course - sorry!
reedbeta.com - developer blog, OpenGL demos, and other projects
#8
Posted 05 February 2009 - 03:58 PM
I know it's been a while since I asked my initial question, but I was finally able to get elengyel's book,"Mathematics for 3D Game Programming and Computer Graphics" from my university's library. It's great, and concise without sacrificing explanation. Thanks!
-Tobey
-Tobey
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












