PDA

View Full Version : glDepthRange()



debonair
10-04-2014, 11:19 PM
I am bit confused with working of glDepthRange(). I have following doubts:
1. does it specify the accuracy or resolution of depth buffer values. for example, range 0..2000 will have more accurate depth values than range 0..200 ? and these mapping will finally transform values from 0..1.?

2. does it provide any sort of clipping? range 0..0.3 will clip if depth value is > 0.3 ?

Aleksandar
10-05-2014, 04:25 AM
Well, almost all your assumptions are wrong, except one. glDepthRange does affect precision.

Near and far clip-planes are set with projection matrix. Parameters of glDepthRange just say how to map near and far distances to [0..1] range, and they cannot be greater than 1.0.
Therefore, if you call glDepthRange(0.1, 0.6), near clip-plane distance will be mapped to 0.1 and far to 0.6. You'll use just 50% of the range.

Answer to your second question is obvious; glDepthRange() does not perform any clipping. It is used just to manage how depth buffer values are calculated.

GClements
10-06-2014, 03:13 AM
The depth range is just a final affine transformation applied to the z coordinate after the model-view and projection transformations and after clipping. The values after the depth range transformation (which will always be between 0 and 1) are converted to the fixed-point representation used by the depth buffer.

glDepthRange() allows you to allocate a portion of the depth range to a particular rendering phase. So if you were rendering a view from inside a building with scenery visible through a window, you might render the scenery with glDepthRange(0.5, 1.0) and render the interior with glDepthRange(0.0, 0.5), so the interior is always in front of the scenery. Or if you wanted a 3D GUI overlay, you could render the scene with glDepthRange(0.1, 1.0) and use glDepthRange(0.0, 0.1) for the GUI, so that the scene never intersects or obscures the GUI

Alternatively, you could just clear the depth buffer between phases, but this requires that the phases are disjoint, i.e. you complete one before starting the next, which may not always be straightforward. Also, clearing the depth buffer used to have a non-trivial cost (to the extent that programs would sometimes use a fraction of the depth range for each frame, only clearing the depth buffer once every N frames).