[Plib-devel] Ancient history....depth buffer queries
Brought to you by:
sjbaker
From: Scott M. <mcm...@ca...> - 2000-05-16 17:39:19
|
Steve: I was going through some very old info-performer archives on depth/range calculations and I came across your formula again, and I have a question. Here's what you wrote (I think...as formatting has garbled the equation): > This comes up about every 6 months....here is the stock reply... > > The 'official' SGI solution to this is... > > z = value in z buffer after rendering (input) > range = distance to pixel in database units (output) > > np = distance to near clipping plane > fp = distance far clipping plane > > nz = near-clip z value > fz = far-clip z value > (as read from glGetIntegerv ( GL_DEPTH_RANGE,...) for OpenGL) > > For each Z-buffer value: > > fp*np(fz-nz) > ------------ > fp-np > - range = -------------------------- > (fp+np)(fz-nz) fz+nz > z - -------------- - ----- > 2(fp-np) 2 > My questions are: 1) has this formatting been restored correctly? 2) Could you explain the nz/fz equations more clearly... Did you really mean glGetIntegerv, or do I do something like the following?: float depth_range[2]; glGetFloatv(GL_DEPTH_RANGE, depth_range); nz = near_clip - depth_range[0]; // indices fz = far_clip - depth_range[1]; With integers I get 0,2147482496 (not MAX_INT) With floats I get 0,1 3) What format should I read the depth buffer in in the first place? Note that I am querying the depth buffer as floats with the following: GLfloat *depthData3 = (GLfloat *) malloc(sizeX*sizeY*sizeof(GLfloat)); glReadPixels(0, 0, sizeX, sizeY, GL_DEPTH_COMPONENT, GL_FLOAT, depthData3); Any help is greatly appreciated, scott -- Scott McMillan mailto:mcm...@ca... SGL Home Page: http://sgl.sourceforge.net DynaMechs Home Page: http://dynamechs.sourceforge.net |