Archived

This topic is now archived and is closed to further replies.

z-buffer depth value...

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

hey. For quite a while now I''ve been ripping my hair out trying to work this out but I''m having no luck and havn''t been able to dig anything up elsewhere.. What I''d like to know is, given standard z-buffering, on standard 3d hardware, and the following: distance from the cameras plane to a vertex, the near clip plane distance, the far clip plane distance, the projection matrix, view/modelview, etc, then what will be the computed depth value to be stored in the depth buffer for that vertex? I''ve tried many combinations of expressions, some getting pretty huge, but none seem to match the result, or they do, but only for certain values of the near/far clip plane... the closest seem to be along the lines of 1-x/zDist... With x being some constant related to the near and far clip planes... and does this differ depending on api (GL/D3D) - I''m currently assuming it doesn''t... And I''m also ignoring w-buffering, btw. thanks in advance. :-) <-- smile :-)
Project-X

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
gluProject(vertex.x, vertex.y, vertex.z, modelviewMatrix, projectionMatrix, viewPort, &result.x, &result.y, &result.z);
Use glGetDoublev() to get modelview and projection matices
and glGetIntegerv() to get viewport matrix.

Share this post


Link to post
Share on other sites
I''ve looked at that in the past,
but according to what I''ve read the returned z value is:

((position*(Modelview*Projection)*viewPortSize).z+1)/2,

not the 0-1 clamped value stored in the depth buffer.. but I''ll still look into it tomorrow. (although I would also need a solution for D3D)

<-- smile :-)

Project-X

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
gluProject returns z value clamped between 0 and 1. 0 is the near plane and 1 is far plane. x and y are simply the screen position. z is depth.

Share this post


Link to post
Share on other sites
ok. thanks.

It didn't seem right seeing as if I duplicated the maths behind it (according to pages such as this) I got completly different results. (I'm trying to get a solution that will work for both D3D and GL, and any future renderers, so I really need the maths behind it unfortunatly.)

[edited by - RipTorn on October 23, 2002 9:04:51 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by RipTorn
According to what I''ve read the returned z value is:

((position*(Modelview*Projection)*viewPortSize).z+1)/2,




You are aware, I imagine, that matrix mltiplication is not commutative. Also, OpenGL transforms positions my multiplying the matrix on the left of the position column vector. So the above should read:

z=((projection*modelview)*position).z

This returns a value in [-1,1], at least for points in the view frustum. Now this is scaled/biased into the depth range. If this is [0,1], we do:

z=(z+1)/2

http://users.ox.ac.uk/~univ1234

Share this post


Link to post
Share on other sites