PDA

View Full Version : Getting nearest Z value in hw?



chrispy
08-26-2003, 08:15 AM
When doing depth peeling it would be great to set a clipping plane with the nearest Z value from the previous stage. Do I have to read out the Z buffer or is it possible to find it in hw?

V-man
08-26-2003, 08:20 AM
I don`t think so. There is no "get me the lowest or highest value" for anything (color, z, stencil, ...)

Nakoruru
08-26-2003, 09:05 AM
I would love to be able to retrieve Maximums, Minimums, and Averages for each buffer.

For the Z-Buffer it would help with optimizing the precision. For color buffers it would be great for dynamically controlling the dynamic range like a real camera or eyeball.

At one time, I suggested to 3DLabs that they allow design pack/unpack programs so that they can write a register and a dummy buffer destination for downloading buffers. Then you could write a 'shader' which iterates over the whole buffer and returns a value or two (like the min, max, and average). The dummy destination buffer is so that the card doesn't have to actually send the data accross the graphics port if all you want is the results of the register.

But, a less generic solution, and likely faster, would be to be able to insert queries for the Min, Max, or Avg into the command stream and then get the results asyncronously later.

I'll write an example, its not perfect so don't criticize it too much.




glNewStat(&stat);

glBeginStats(stat);
// do some drawing
glEndStats(stat);

// calling glGetStat before the command
// stream reaches glEndStats will cause
// program to block
glGetStat(stat, GL_AVERAGE, &avg);
glGetStat(stat, GL_MAX, &max);
glGetStat(stat, GL_MIN, &min);


To prevent blocking, you could do something like always getting stats for the previous frame instead of the current one.

Whatever form such an extension takes, it should look a little like the occlusion query extension. Maybe I should reread that extension and reconsider this design.

Anyway, A feature like this is highest on my wish list for OpenGL.



[This message has been edited by Nakoruru (edited 08-26-2003).]

al_bob
08-26-2003, 10:31 AM
If your driver exposes the GL_ARB_imaging option to OpenGL, you can use glMinMax() to get the information you want.

Nakoruru
08-26-2003, 12:47 PM
Will glMinMax work if you do a ReadPixels with GL_DEPTH_COMPONENT as the format?

Is there a good MINMAX format for 24 and 32 bit depth buffers? (I assume that if the answer to the first question is yes, then ALPHA16 or LUMINANCE16 would work fine for 16-bit depth buffers).

chrispy
08-27-2003, 06:44 AM
My idea was to render textures with half of the resolution of the previous one and the smaller texture would get the minimum of four texels of the bigger texture. So it would require ten passes to find the minimum of a 1024x1024 texture. It requires n-1 comparisions.(you cannot do with less)

chrispy
08-27-2003, 06:56 AM
Reading the spec it looks like the minmax instruction works with DEPTH_COMPONENT.

By the way the farthest Z value could be read out from the top of the hierarchical Z buffer easily.