Depth buffer values

Depth buffer values

Post by Ralph Vinc » Sun, 12 May 2002 02:29:05



I have a zNear value of 5.0, and a zFar value of 60.0.
When I click on an object in my scene, and call:

glReadPixels(x,y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&selectedThingZ);

I get a value of 0.95 for my selectedThingZ.

What, actually, is that z value given my zNear and zFar (I have loked at the
FAQ, but find nothing on this). Also, what would happen in glOrthoMode?
Thanks, Ralph

 
 
 

Depth buffer values

Post by George Ziniewic » Sun, 12 May 2002 02:57:41



> I have a zNear value of 5.0, and a zFar value of 60.0.
> When I click on an object in my scene, and call:

> glReadPixels(x,y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&selectedThingZ);

> I get a value of 0.95 for my selectedThingZ.

> What, actually, is that z value given my zNear and zFar (I have loked at the
> FAQ, but find nothing on this). Also, what would happen in glOrthoMode?

   The redbook fig. 3-18 shows that depth coord values are in the range of 0->1 and not linear.

   I'm no mathematician, if I'm not mistaken the z-buffer value is a number representing the non-linear location in zNear-zFar
space, so I would guess, that .95 squared of the z range + the znear is the actual worldspace location, i.e.:

    znear+pow(.95,2)*(zfar-znear)

      5  +   .9025  *( 60 -  5  ) or 54.6375?

   pow may not be the precise way to convert the z value but it looks about right.

zin

 
 
 

Depth buffer values

Post by César Blecua Udía » Sun, 12 May 2002 03:34:21




> > I have a zNear value of 5.0, and a zFar value of 60.0.
> > When I click on an object in my scene, and call:

> > glReadPixels(x,y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&selectedThingZ);

> > I get a value of 0.95 for my selectedThingZ.

> > What, actually, is that z value given my zNear and zFar (I have loked at the
> > FAQ, but find nothing on this). Also, what would happen in glOrthoMode?

>    The redbook fig. 3-18 shows that depth coord values are in the range of 0->1 and not linear.

>    I'm no mathematician, if I'm not mistaken the z-buffer value is a number representing the non-linear location in zNear-zFar
> space, so I would guess, that .95 squared of the z range + the znear is the actual worldspace location, i.e.:

>     znear+pow(.95,2)*(zfar-znear)

>       5  +   .9025  *( 60 -  5  ) or 54.6375?

>    pow may not be the precise way to convert the z value but it looks about right.

The exact maths for doing this are described at the OpenGL SIGGRAPH
courses:

http://www.opengl.org/developers/code/sig99/advanced99/notes/node403....

Csar

 
 
 

Depth buffer values

Post by George Ziniewic » Sun, 12 May 2002 04:43:48





> > > I have a zNear value of 5.0, and a zFar value of 60.0.
> > > When I click on an object in my scene, and call:

> > > glReadPixels(x,y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&selectedThingZ);

> > > I get a value of 0.95 for my selectedThingZ.

> > > What, actually, is that z value given my zNear and zFar (I have loked at the
> > > FAQ, but find nothing on this). Also, what would happen in glOrthoMode?

> >    The redbook fig. 3-18 shows that depth coord values are in the range of 0->1 and not linear.

> >    I'm no mathematician, if I'm not mistaken the z-buffer value is a number representing the non-linear location in zNear-zFar
> > space, so I would guess, that .95 squared of the z range + the znear is the actual worldspace location, i.e.:

> >     znear+pow(.95,2)*(zfar-znear)

> >       5  +   .9025  *( 60 -  5  ) or 54.6375?

> >    pow may not be the precise way to convert the z value but it looks about right.

> The exact maths for doing this are described at the OpenGL SIGGRAPH
> courses:

> http://www.opengl.org/developers/code/sig99/advanced99/notes/node403....

   Like I said, I'm no mathematician.

   I can't get a resaonable value, can you/someone compute the example provided?

zin

 
 
 

Depth buffer values

Post by Ralph Vinc » Sun, 12 May 2002 06:05:45


Hi George,

Hmmm....I'm thinking, after all this, its not what I need anyhow, for the
third parameter to gluUnProject(). Sorry to give everyone the runaround. I
thought I needed an actual Z value. My problem must reside elsewhere -- and
I was surethis was it.

BTW, do you need this function yourself? I'll be glad to look t it and put
it into code for the group if  anyone really needs it. -Ralph





> > > > I have a zNear value of 5.0, and a zFar value of 60.0.
> > > > When I click on an object in my scene, and call:

> > > > glReadPixels(x,y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&selectedThingZ);

> > > > I get a value of 0.95 for my selectedThingZ.

> > > > What, actually, is that z value given my zNear and zFar (I have
loked at the
> > > > FAQ, but find nothing on this). Also, what would happen in
glOrthoMode?

> > >    The redbook fig. 3-18 shows that depth coord values are in the

range of 0->1 and not linear.
Quote:

> > >    I'm no mathematician, if I'm not mistaken the z-buffer value is a

number representing the non-linear location in zNear-zFar
Quote:> > > space, so I would guess, that .95 squared of the z range + the znear

is the actual worldspace location, i.e.:
Quote:

> > >     znear+pow(.95,2)*(zfar-znear)

> > >       5  +   .9025  *( 60 -  5  ) or 54.6375?

> > >    pow may not be the precise way to convert the z value but it looks
about right.

> > The exact maths for doing this are described at the OpenGL SIGGRAPH
> > courses:

http://www.opengl.org/developers/code/sig99/advanced99/notes/node403....

- Show quoted text -

Quote:

>    Like I said, I'm no mathematician.

>    I can't get a resaonable value, can you/someone compute the example
provided?

> zin

 
 
 

Depth buffer values

Post by George Ziniewic » Sun, 12 May 2002 06:47:43



> Hi George,

> Hmmm....I'm thinking, after all this, its not what I need anyhow, for the
> third parameter to gluUnProject(). Sorry to give everyone the runaround. I
> thought I needed an actual Z value. My problem must reside elsewhere -- and
> I was surethis was it.

> BTW, do you need this function yourself? I'll be glad to look t it and put
> it into code for the group if  anyone really needs it. -Ralph

   Thanks, I can write the func if I need it, which I don't.   I used project/unproject once.

   I would however like to see someone do the calculation on your data, since I got a ridiculous number. (and no point writing a
func if I can't do it on paper first!)

zin

 
 
 

Depth buffer values

Post by César Blecua Udía » Sun, 12 May 2002 18:28:12




[...]

> > http://www.opengl.org/developers/code/sig99/advanced99/notes/node403....

>    Like I said, I'm no mathematician.

>    I can't get a resaonable value, can you/someone compute the example provided?

Yes: (5.0 * 60.0) / ((60.0 - 5.0)*0.95 -60.0) = -38

Note that for Zwin=0.0, Zeye=-5, and for Zwin=1.0, Zeye=-60

I guess you don't like the negative values :) They're correct! The Zeye
is expected to be negative. However, if you search GoogleGroups, you may
find a different version of this formula, which returns positive values
instead of negative. I already posted some comments about this last
year. Here's a link to the thread in Google (although you may need to
fix it if the link line gets splitted in several lines):

http://groups.google.com/groups?hl=en&threadm=3AE06581.AAADFC27%40ina...

Csar

 
 
 

Depth buffer values

Post by Ralph Vinc » Sun, 12 May 2002 22:17:53


Wait a minute Cesar,

That .95 value is coming from clicking with the mouse on an object on the
screen, then performing a
glReadPixels(x,y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&selectedThingZ);
THe .95 is the value returned for selectedThingZ, and SHOULD represent NOT
the Zeye, BUT, the Z value for WHERE on the element I click on is. THats
what I was looking to obtain anyhow. Are you saying here the Eye is 38 back
from this thing? If so, how do I determine then the Z value of the point I
clicked on? Thanks -Ralph





> [...]

http://www.opengl.org/developers/code/sig99/advanced99/notes/node403....
Quote:

> >    Like I said, I'm no mathematician.

> >    I can't get a resaonable value, can you/someone compute the example
provided?

> Yes: (5.0 * 60.0) / ((60.0 - 5.0)*0.95 -60.0) = -38

> Note that for Zwin=0.0, Zeye=-5, and for Zwin=1.0, Zeye=-60

> I guess you don't like the negative values :) They're correct! The Zeye
> is expected to be negative. However, if you search GoogleGroups, you may
> find a different version of this formula, which returns positive values
> instead of negative. I already posted some comments about this last
> year. Here's a link to the thread in Google (although you may need to
> fix it if the link line gets splitted in several lines):

http://groups.google.com/groups?hl=en&threadm=3AE06581.AAADFC27%40ina...
rnum=1&prev=/groups%3Fas_q%3Dblecua%2520depth%26as_ugroup%3Dcomp.sys.sgi.gra
phics%26hl%3Den

- Show quoted text -

> Csar


 
 
 

Depth buffer values

Post by César Blecua Udía » Sun, 12 May 2002 23:03:52



> Wait a minute Cesar,

> That .95 value is coming from clicking with the mouse on an object on the
> screen, then performing a
> glReadPixels(x,y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&selectedThingZ);
> THe .95 is the value returned for selectedThingZ, and SHOULD represent NOT
> the Zeye, BUT, the Z value for WHERE on the element I click on is. THats
> what I was looking to obtain anyhow. Are you saying here the Eye is 38 back
> from this thing? If so, how do I determine then the Z value of the point I
> clicked on? Thanks -Ralph

Ralph,

(Supposing you don't modify the default values of glDepthRange)

Zwin is in range [0,1]
Zeye is in range [near,far]

glReadPixels returns Zwin (not Zeye).

I think you said you want this for calling gluUnProject. In that case,
you don't need to care about Zeye, because gluUnProject expects Zwin
values.

Hope this helps,

Csar

 
 
 

Depth buffer values

Post by César Blecua Udía » Sun, 12 May 2002 23:10:10



> Wait a minute Cesar,

> That .95 value is coming from clicking with the mouse on an object on the
> screen, then performing a
> glReadPixels(x,y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&selectedThingZ);
> THe .95 is the value returned for selectedThingZ, and SHOULD represent NOT
> the Zeye, BUT, the Z value for WHERE on the element I click on is. THats
> what I was looking to obtain anyhow. Are you saying here the Eye is 38 back
> from this thing? If so, how do I determine then the Z value of the point I
> clicked on? Thanks -Ralph

Oops! On a second read, I realize you may be misunderstanding the
meaning of Zeye and Zwin. Zeye is NOT the Z of the eye, but the Z of a
fragment in eye coordinates. Zwin is the Z of a fragment in window
coordinates. Both of them define the Z of a pixel, but in a different
coordinate space.

Csar

 
 
 

Depth buffer values

Post by George Ziniewic » Mon, 13 May 2002 01:33:56




> > Wait a minute Cesar,

> > That .95 value is coming from clicking with the mouse on an object on the
> > screen, then performing a
> > glReadPixels(x,y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&selectedThingZ);
> > THe .95 is the value returned for selectedThingZ, and SHOULD represent NOT
> > the Zeye, BUT, the Z value for WHERE on the element I click on is. THats
> > what I was looking to obtain anyhow. Are you saying here the Eye is 38 back
> > from this thing? If so, how do I determine then the Z value of the point I
> > clicked on? Thanks -Ralph

> Oops! On a second read, I realize you may be misunderstanding the
> meaning of Zeye and Zwin. Zeye is NOT the Z of the eye, but the Z of a
> fragment in eye coordinates.

   Of course!  I assume the final z in the buffes, i.e. .95.

Quote:> Zwin is the Z of a fragment in window
> coordinates.

   World space?

Quote:> Both of them define the Z of a pixel, but in a different
> coordinate space.

   I'm still waiting for an answer to the problem given that is more accurate than the one I provided w/ my non-mathematician
formula! (not to say it is correct!)

zin

 
 
 

Depth buffer values

Post by George Ziniewic » Mon, 13 May 2002 01:36:05





> [...]

> > > http://www.opengl.org/developers/code/sig99/advanced99/notes/node403....

> >    Like I said, I'm no mathematician.

> >    I can't get a resaonable value, can you/someone compute the example provided?

> Yes: (5.0 * 60.0) / ((60.0 - 5.0)*0.95 -60.0) = -38

> Note that for Zwin=0.0, Zeye=-5, and for Zwin=1.0, Zeye=-60

> I guess you don't like the negative values :)

   I try to be positive!  38 doesn't sound right w/ a .95 value being so close to 1.0

Quote:> They're correct! The Zeye
> is expected to be negative. However, if you search GoogleGroups, you may
> find a different version of this formula, which returns positive values
> instead of negative. I already posted some comments about this last
> year. Here's a link to the thread in Google (although you may need to
> fix it if the link line gets splitted in several lines):

> http://groups.google.com/groups?hl=en&threadm=3AE06581.AAADFC27%40ina...

   will check it thanks.

zin

 
 
 

Depth buffer values

Post by Ralph Vinc » Mon, 13 May 2002 05:08:28


Ok, I et it now, thanks. -Ralph
 
 
 

Depth buffer values

Post by César Blecua Udía » Mon, 13 May 2002 19:00:54






> > [...]

> > > > http://www.opengl.org/developers/code/sig99/advanced99/notes/node403....

> > >    Like I said, I'm no mathematician.

> > >    I can't get a resaonable value, can you/someone compute the example provided?

> > Yes: (5.0 * 60.0) / ((60.0 - 5.0)*0.95 -60.0) = -38

> > Note that for Zwin=0.0, Zeye=-5, and for Zwin=1.0, Zeye=-60

> > I guess you don't like the negative values :)

>    I try to be positive!  38 doesn't sound right w/ a .95 value being so close to 1.0

Just draw the Zwin/Zeye curve yourself. The endpoints (0.0 and 1.0)
return the expected results (-5 and -60, respectively).

Csar

 
 
 

Depth buffer values

Post by César Blecua Udía » Mon, 13 May 2002 19:08:12





> > > Wait a minute Cesar,

> > > That .95 value is coming from clicking with the mouse on an object on the
> > > screen, then performing a
> > > glReadPixels(x,y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&selectedThingZ);
> > > THe .95 is the value returned for selectedThingZ, and SHOULD represent NOT
> > > the Zeye, BUT, the Z value for WHERE on the element I click on is. THats
> > > what I was looking to obtain anyhow. Are you saying here the Eye is 38 back
> > > from this thing? If so, how do I determine then the Z value of the point I
> > > clicked on? Thanks -Ralph

> > Oops! On a second read, I realize you may be misunderstanding the
> > meaning of Zeye and Zwin. Zeye is NOT the Z of the eye, but the Z of a
> > fragment in eye coordinates.

>    Of course!  I assume the final z in the buffes, i.e. .95.

> > Zwin is the Z of a fragment in window
> > coordinates.

>    World space?

No, window coordinates (ie: after modelview, projection and viewport
tranformations). I think there's a graph in the red book or the OpenGL
spec which explains all the coordinate systems used across the vertex
transformation pipeline.

Csar

 
 
 

1. Coying Depth Buffer Values

Hello,

I am wondering how to get at the depth buffer.  The reason is I want to
make a stereogram of some renderings I have.  I'd like to be able to
simpily copy the depth buffer into an array of floats and use the array
or write it to a file or something.

Is there a way to do this?

Thanks,
Matt Cohen

2. FS: Specular Infini-D 3.5

3. Displaying Z (Depth) Buffer Values

4. Does GTK+ 1.2 mean GIMP 1.2 is close?

5. Reading Depth Buffer Values and the OpenGL Spec

6. bitmap <-----> ascii converter

7. actual depth values from pick/z-buffer depth values

8. Alias WaveFront Maya 3.0 and others for the best price!!!

9. Increasing bit depth of depth buffer

10. Problem with stencil buffer and depth buffer

11. Depth buffer as a stencil buffer?

12. OpenGL depth buffer = Z buffer ?

13. question about depth buffers and stencil buffers