1Name 2 3 EXT_depth_bounds_test 4 5Name Strings 6 7 GL_EXT_depth_bounds_test 8 9Contact 10 11 Cass Everitt, NVIDIA Corporation (cass 'at' nvidia.com) 12 Mark J. Kilgard, NVIDIA Corporation (mjk 'at' nvidia.com) 13 14Notice 15 16 Copyright NVIDIA Corporation, 2002, 2003. 17 18Status 19 20 Implemented in GeForce FX 5900 (NV35) drivers as of June 2003. 21 22 Also supported by GeForce FX 5700 (NV36) and GeForce6 (NV4x). 23 24Version 25 26 Last Modified Date: 2004/05/17 27 NVIDIA Revision: 5 28 29Number 30 31 297 32 33Dependencies 34 35 Written based on the wording of the OpenGL 1.3 specification. 36 37Overview 38 39 This extension adds a new per-fragment test that is, logically, 40 after the scissor test and before the alpha test. The depth bounds 41 test compares the depth value stored at the location given by the 42 incoming fragment's (xw,yw) coordinates to a user-defined minimum 43 and maximum depth value. If the stored depth value is outside the 44 user-defined range (exclusive), the incoming fragment is discarded. 45 46 Unlike the depth test, the depth bounds test has NO dependency on 47 the fragment's window-space depth value. 48 49 This functionality is useful in the context of attenuated stenciled 50 shadow volume rendering. To motivate the functionality's utility 51 in this context, we first describe how conventional scissor testing 52 can be used to optimize shadow volume rendering. 53 54 If an attenuated light source's illumination can be bounded to a 55 rectangle in XY window-space, the conventional scissor test can be 56 used to discard shadow volume fragments that are guaranteed to be 57 outside the light source's window-space XY rectangle. The stencil 58 increments and decrements that would otherwise be generated by these 59 scissored fragments are inconsequential because the light source's 60 illumination can pre-determined to be fully attenuated outside the 61 scissored region. In other words, the scissor test can be used to 62 discard shadow volume fragments rendered outside the scissor, thereby 63 improving performance, without affecting the ultimate illumination 64 of these pixels with respect to the attenuated light source. 65 66 This scissoring optimization can be used both when rendering 67 the stenciled shadow volumes to update stencil (incrementing and 68 decrementing the stencil buffer) AND when adding the illumination 69 contribution of attenuated light source's. 70 71 In a similar fashion, we can compute the attenuated light source's 72 window-space Z bounds (zmin,zmax) of consequential illumination. 73 Unless a depth value (in the depth buffer) at a pixel is within 74 the range [zmin,zmax], the light source's illumination can be 75 pre-determined to be inconsequential for the pixel. Said another 76 way, the pixel being illuminated is either far enough in front of 77 or behind the attenuated light source so that the light source's 78 illumination for the pixel is fully attenuated. The depth bounds 79 test can perform this test. 80 81Issues 82 83 Where should the depth bounds test take place in the OpenGL 84 fragment processing pipeline? 85 86 RESOLUTION: After scissor test, before alpha test. In practice, 87 this is a logical placement of the test. An implementation is 88 free to perform the test in a manner that is consistent with the 89 specified ordering. 90 91 Importantly, the depth bounds test occurs before any fragment 92 operation that has a side-effect such as stencil and/or depth buffer 93 writes (ie, the stencil or depth test). This makes it possible 94 to discard incoming fragment's without concern for preserving such 95 side-effects. 96 97 Is the depth bounds test consistent with early depth rejection? 98 99 Yes. If an OpenGL implementation supports some conservative bounds 100 on depth values in subregions of the depth buffer (hierarchical 101 depth buffers, etc), the depth bounds test can reject fragments 102 based on these conservative bounds. 103 104 How are the depth bounds specified? 105 106 RESOLUTION: Normalized window-space depth values. This means 107 the depth values are specified in the range [0.0, 1.0] similar 108 to glDepthRange. 109 110 Can the zmin bound be greater than the zmax bound? 111 112 RESOLUTION: zmin must be less than or equal to zmax or an 113 INVALID_VALUE error is generated. 114 115 Another way to interpret this situation is to have zmin>zmax reject 116 all fragments where the corresponding pixel's depth value is between 117 zmin and zmax. But this does not seem useful enough to specify. 118 119 What should the glDepthBoundsEXT routine mimic? 120 121 RESOLUTION: glDepthBoundsEXT should mimic glDepthRange in parameter 122 types and clamping, excepting that zmin must be less than zmax. 123 124 Do the depth bounds have anything to do with the depth range? 125 126 RESOLUTION: No. These are totally independent pieces of state. 127 To reinforce the point, having a depth range and depth bounds with 128 no overlap is perfectly well-defined (even if a little odd). 129 130 What push/pop attrib bits should affect the depth bounds test enable? 131 132 RESOLUTION: GL_ENABLE_BIT and GL_DEPTH_BUFFER_BIT. 133 134 How does depth bounds testing interact with polygon offset 135 or depth replace operations (say from ARB_fragment_program, 136 NV_texture_shader, or NV_fragment_program)? 137 138 RESOLUTION: There are NO interactions. The depth bounds test has 139 NO dependency on the incoming fragment's depth value so it doesn't 140 matter if there is a polygon offset or depth replace operation. 141 142 Does depth bounds testing affect bitmap/draw/copy pixels operations 143 involving depth component pixels? 144 145 RESOLUTION: Yes, depth bounds testing affects all rasterized 146 primitives (just like all other fragment operations). 147 148 How does depth bounds test interact with multisampling? 149 150 RESOLUTION: The depth bounds test is performed per-sample when 151 multisampling is active, just like the depth test. 152 153 At what precision is the depth bounds test carried out? 154 155 RESOLUTION: For the purposes of the test, the bounds are converted to 156 fixed-point as though they were to be written to the depth buffer, and 157 the comparison uses those quantized bounds. 158 159 Can you have the depth test disabled and still have the depth bounds 160 test enabled? 161 162 RESOLUTION: Yes. The two tests operate independently. 163 164 How does the depth bounds test operate if there is no depth buffer? 165 166 RESOLUTION: It is as if the depth bounds test always passes 167 (analogous to the depth test). 168 169New Procedures and Functions 170 171 void DepthBoundsEXT(clampd zmin, clampd zmax); 172 173New Tokens 174 175 Accepted by the <cap> parameter of Enable, Disable, and IsEnabled, 176 and by the <pname> parameter of GetBooleanv, GetIntegerv, 177 GetFloatv, and GetDoublev: 178 179 DEPTH_BOUNDS_TEST_EXT 0x8890 180 181 Accepted by the <pname> parameter of GetBooleanv, GetIntegerv, 182 GetFloatv, and GetDoublev: 183 184 DEPTH_BOUNDS_EXT 0x8891 185 186Additions to Chapter 2 of the OpenGL 1.3 Specification (OpenGL Operation) 187 188 None 189 190Additions to Chapter 3 of the OpenGL 1.3 Specification (Rasterization) 191 192 None 193 194Additions to Chapter 4 of the OpenGL 1.3 Specification (Per-Fragment Operations 195and the Framebuffer) 196 197 -- Figure 4.1 Per-fragment operations 198 199 Add a block for the "depth bounds test" after the scissor and before 200 the alpha test. 201 202 -- Section 4.1.X Depth Bounds Test (following Section 4.1.2 Scissor Test) 203 204 "The depth bounds test determines whether the depth value (Zpixel) 205 stored at the location given by the incoming fragment's (xw,yw) 206 location lies within the depth bounds range defined by two values. 207 These values are set with 208 209 void DepthBoundsEXT(clampd zmin, clampd zmax); 210 211 Each of zmin and zmax are clamped to lie within [0,1] (being of 212 type clampd). If zmin <= Zpixel <= zmax, then the depth bounds test 213 passes. Otherwise, the test fails and the fragment is discarded. 214 The test is enabled or disabled using Enable or Disable using the 215 constant DEPTH_BOUNDS_TEST_EXT. When disabled, it is as if the depth 216 bounds test always passes. If zmin is greater than zmax, then the 217 error INVALID_VALUE is generated. The state required consists of 218 two floating-point values and a bit indicating whether the test is 219 enabled or disabled. In the initial state, zmin and zmax are set 220 to 0.0 and 1.0 respectively; and the depth bounds test is disabled. 221 222 If there is no depth buffer, it is as if the depth bounds test always 223 passes." 224 225 -- Section 4.10 Additional Multisample Fragment Operations 226 227 Add depth bounds test to the list of operations affected by 228 multisampling. Amend the 1st and 2nd sentences in the 2nd paragraph 229 to read: 230 231 "If MULTISAMPLE is enabled, and the value of SAMPLE_BUFFERS is one, 232 the depth bounds test, alpha test, depth test, blending, and dithering 233 operations are performed for each pixel sample, rather than just once 234 for each fragment. Failure of the depth bounds, alpha, stencil, or 235 depth test results in termination of the processing of the sample, 236 rather than discarding of the fragment." 237 238 Amend the 1st sentence in the 3nd paragraph to read: 239 240 "Depth bounds, stencil, depth, blending, and dithering operations 241 are performed for a pixel sample only if that sample's fragment 242 coverage bit is a value of 1." 243 244 Amend the 3rd sentence in the 4th paragraph to read: 245 246 "An implementation may choose to identify a centermost sample, and 247 to perform depth bounds, alpha, stencil, and depth tests on only 248 that sample." 249 250Additions to Chapter 5 of the OpenGL 1.3 Specification (Special Functions) 251 252 None 253 254Additions to Chapter 6 of the OpenGL 1.3 Specification (State and State Requests) 255 256 None 257 258Additions to the AGL/GLX/WGL Specifications 259 260 None 261 262GLX Protocol 263 264 A new GL rendering command is added. The following command is sent to the 265 server as part of a glXRender request: 266 267 DepthBoundsEXT 268 2 12 rendering command length 269 2 4229 rendering command opcode 270 4 FLOAT32 zmin 271 4 FLOAT32 zmax 272 273Errors 274 275 If zmin is greater than zmax, then the error INVALID_VALUE is 276 generated. 277 278New State 279 280(table 6.15 "Pixel Operation) 281 282Get Value Type Get Command Initial Value Description Sec Attribute 283--------------------- ---- ----------- ------------- ------------ ----- ------------------- 284DEPTH_BOUNDS_TEST_EXT B IsEnabled False Depth bounds 4.1.X depth-buffer/enable 285 test enable 286DEPTH_BOUNDS_EXT 2xR+ GetFloatv 0,1 Depth bounds 4.1.X depth-buffer 287 zmin & zmax 288 289New Implementation Dependent State 290 291 None 292 293Revision History 294 295 NVIDIA exposed a functionally and enumerant identical version of 296 this extension under the name NV_depth_bounds_test. NVIDIA drivers 297 after May 2003 support the EXT_depth_bounds_test name only. 298 299 Mesa and NVIDIA agreed to make this an EXT extension in April 2003. 300 301 8/27/2003 - GLX protocol specification added. 302