PDA

View Full Version : Reading the Z buffer.



bobrien
03-21-2001, 01:25 PM
I want to read the z buffer into an array.
How do I know the dimensions x and y of the
z buffer?

john
03-21-2001, 03:16 PM
you know it because you have to keep track of it when the window manager tells you.

if you're using glut, then the function ptr you give to glutReshapeFunction() (or, whatever it's exactly called; I can't remember) has two parameters representing the dimension of the window that you have been given.

store it. don't lose it. this info _is_ important. wrap it in cotton wall and store them in a global variable, or something.

cheers
John

bobrien
03-21-2001, 07:52 PM
Thanks that makes perfect sence.

bobrien
03-21-2001, 07:56 PM
By the way how does one interpret the z value that is read. Assuming I use a
16 bit short read of the z buffer the value
returned will be 0 to 65535 so how does this map to the actual z value? Is this some scaled value of the minimum and maximum z in the current z buffer? and hence is that mapping going to be the same for every frame of the animation?

john
03-21-2001, 10:55 PM
you need to convert your short into a float between 0.0 and 1.0 and then refer to the article posted by new...bie? newname, in fact, elsewhere. i just wrote an answer to it, so it can't be too far away =)

er, to convert to a float, you divide your z value by the maximum range of the type. so, in the case of a 16 bit integer, then you'd say:

unsigned short int z;
float d;

d=(float)z/(1<<15);

cheers
John

Roderic (Ingenu)
03-22-2001, 12:11 AM
Reading the ZBuffer is EVIL !
It's slow, ugly and never a good idea.
You'd better avoid it as much as possible.

mcraighead
03-22-2001, 08:58 AM
I wouldn't call it evil. It's just not a great thing for performance.

- Matt

andreiga
03-22-2001, 08:59 AM
Originally posted by bobrien:
I want to read the z buffer into an array.
How do I know the dimensions x and y of the
z buffer?

Dimensions are the same as the framebuffer dimensions (in pixels).

bobrien
03-22-2001, 09:51 AM
Evil??? http://www.opengl.org/discussion_boards/ubb/smile.gif
I know its slow but I'm not trying to do anything real time, just a test.
an evil, evil test. http://www.opengl.org/discussion_boards/ubb/smile.gif

zed
03-22-2001, 11:35 AM
slow? my lowly vanta can do depth buffer reads at 17 million pixels a second

bobrien
03-22-2001, 12:56 PM
Originally posted by john:
er, to convert to a float, you divide your z value by the maximum range of the type. so, in the case of a 16 bit integer, then you'd say:

unsigned short int z;
float d;

d=(float)z/(1<<15);

cheers
John

Great nice and simple but then must I scale this by the current scale factor? How else would this be converted into the real co-ordinates?

john
03-22-2001, 02:41 PM
check out the thread:
http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/002423.html

since you know v' (and the corresponding z' and w', where w'==1.0) and P, then you can compute z and w.

cheers
John