Mazy

06-01-2003, 03:30 AM

Is it possibe to reverse the calculation of a perspective matris to get the distance between znear and zfar?

View Full Version : extract (zfar-znear) from projection matrix

Mazy

06-01-2003, 03:30 AM

Is it possibe to reverse the calculation of a perspective matris to get the distance between znear and zfar?

Csiki

06-01-2003, 04:25 AM

Originally posted by Mazy:

Is it possibe to reverse the calculation of a perspective matris to get the distance between znear and zfar?

Yes, but not a good idea. The glPerspective has a fix expression for the matrix, but it might be driver specific (not exact).

Is it possibe to reverse the calculation of a perspective matris to get the distance between znear and zfar?

Yes, but not a good idea. The glPerspective has a fix expression for the matrix, but it might be driver specific (not exact).

Mazy

06-01-2003, 05:43 AM

ok, but i think i still want to try it out.. have any calculation?

Csiki

06-01-2003, 05:58 AM

Originally posted by Mazy:

ok, but i think i still want to try it out.. have any calculation?

The NVIDIA use this matrix:

2n/(r-l) 0 0 0

0 2n/(t-b) 0 0

(l+r)/(r-l) (t+b)/(t-b) (n+f)/(n-f) -1

0 0 (2nf)/(n-f) 0

So a=(n+f)/(n-f), b=(2nf)/(n-f).

(1/((a+1)(a-1)))/b=c=(n-f)/2

(a+1)/c=n, (a-1)/c=f

Check it.

ok, but i think i still want to try it out.. have any calculation?

The NVIDIA use this matrix:

2n/(r-l) 0 0 0

0 2n/(t-b) 0 0

(l+r)/(r-l) (t+b)/(t-b) (n+f)/(n-f) -1

0 0 (2nf)/(n-f) 0

So a=(n+f)/(n-f), b=(2nf)/(n-f).

(1/((a+1)(a-1)))/b=c=(n-f)/2

(a+1)/c=n, (a-1)/c=f

Check it.

Zengar

06-01-2003, 06:28 AM

Wasn't there something like glGet(GL_ZNEAR)??? I've got the specs at another computer, so I'm unable to check it now.

john

06-01-2003, 08:16 PM

Yes, but not a good idea. The glPerspective has a fix expression for the matrix, but it might be driver specific (not exact).

The opengl specification describes what projection matrix to create when calling and glFrustum. I'd be very, ~very~ surprised if a driver deviated from this specification. At the end of the day, however, points are projected to the unit cube coordinate system and you can easily reverse that process as soon as you know P.

The opengl specification describes what projection matrix to create when calling and glFrustum. I'd be very, ~very~ surprised if a driver deviated from this specification. At the end of the day, however, points are projected to the unit cube coordinate system and you can easily reverse that process as soon as you know P.

Ostsol

06-01-2003, 09:22 PM

Originally posted by Zengar:

Wasn't there something like glGet(GL_ZNEAR)??? I've got the specs at another computer, so I'm unable to check it now.

The glGet* token is GL_DEPTH_RANGE. Two values are returned, the first being the near clipping distance and the second being the far.

Wasn't there something like glGet(GL_ZNEAR)??? I've got the specs at another computer, so I'm unable to check it now.

The glGet* token is GL_DEPTH_RANGE. Two values are returned, the first being the near clipping distance and the second being the far.

Mazy

06-01-2003, 10:16 PM

Well, that doenst help me, since im trying to extract it in a vertexprogram http://www.opengl.org/discussion_boards/ubb/smile.gif

Csiki

06-01-2003, 10:29 PM

Originally posted by Mazy:

Well, that doenst help me, since im trying to extract it in a vertexprogram http://www.opengl.org/discussion_boards/ubb/smile.gif

Then give it as a parameter.

It is good to count the znear and zfar parameters from the projection matrix at each vertex???

Well, that doenst help me, since im trying to extract it in a vertexprogram http://www.opengl.org/discussion_boards/ubb/smile.gif

Then give it as a parameter.

It is good to count the znear and zfar parameters from the projection matrix at each vertex???

Mazy

06-01-2003, 11:13 PM

I know that i can send it as a parameter http://www.opengl.org/discussion_boards/ubb/smile.gif

I just wanted to try go get it in the vertexprogram anyway... Im not aiming for 800+ fps here, and i dont have so many vertices that it really matters..

add: And GL_DEPTH_RANGE doenst gice you near/far plane, it only gives you the values set by glDepthRange.

[This message has been edited by Mazy (edited 06-02-2003).]

I just wanted to try go get it in the vertexprogram anyway... Im not aiming for 800+ fps here, and i dont have so many vertices that it really matters..

add: And GL_DEPTH_RANGE doenst gice you near/far plane, it only gives you the values set by glDepthRange.

[This message has been edited by Mazy (edited 06-02-2003).]

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.