We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Reading the z-buffer value of a pixel
Page Index Toggle Pages: 1
Reading the z-buffer value of a pixel (Read 1130 times)
Reading the z-buffer value of a pixel
Nov 1st, 2005, 11:17pm
 
I can read the color of a pixel with get().
Is there a way to also read the z-buffer value?
Re: Reading the z-buffer value of a pixel
Reply #1 - Nov 2nd, 2005, 1:20pm
 
It's possible, but a bit more difficult, and only works with P3D I think.

Code:

PGraphics3 pg3;

void setup()
{
size(400,400,P3D);
pg3=(PGraphics3)g;
}

void draw()
{
.. stuff ..
color c=get(x,y);
float z=pg3.zbuffer[x+y*width]; // z-value is a float
}


However the value of the zbuffer is a bit hard to fathom out.. though thing further away have bigger z-values from near ones, and undrawn points have z values equal to MAX_FLOAT.

Oh and the range of z-values seems to depend somehow on the height of the sketch... I've still to work out how they're calculated from x/y/z coordinates...
Re: Reading the z-buffer value of a pixel
Reply #2 - Nov 2nd, 2005, 1:41pm
 
Some helpful links...

Wikipedia
Love thy Z-Buffer (although this is more focussed on some integer based caveats of Z-buffers (i.e. in OpenGL mode) - P3D is using float's with slightly different outcome)
Re: Reading the z-buffer value of a pixel
Reply #3 - Nov 4th, 2005, 2:21pm
 
John,
Thank you. This helps.
I now need to workout the inverse transformation to get the corresponding 3D point in model space from the pixel coordinates and the zbuffer value.
- Jarek
Page Index Toggle Pages: 1