1Name 2 3 EXT_post_depth_coverage 4 5Name Strings 6 7 GL_EXT_post_depth_coverage 8 9Contact 10 11 Jeff Bolz, NVIDIA Corporation (jbolz 'at' nvidia.com) 12 Pat Brown, NVIDIA Corporation (pbrown 'at' nvidia.com) 13 14Contributors 15 16 Jeff Bolz, NVIDIA 17 Pat Brown, NVIDIA 18 James Helferty, NVIDIA 19 20Status 21 22 Shipping 23 24Version 25 26 Last Modified Date: March 27, 2015 27 Revision: 2 28 29Number 30 31 OpenGL Extension #461 32 OpenGL ES Extension #225 33 34Dependencies 35 36 This extension is written against the OpenGL 4.3 specification 37 (Compatibility Profile). 38 39 This extension is written against version 4.30 of the OpenGL 40 Shading Language Specification. 41 42 This extension interacts with NV_fragment_program4. 43 44 This extension interacts with OpenGL ES 3.1 45 46 If implemented in OpenGL ES 3.1, OES_sample_variables (providing 47 gl_SampleMaskIn) is required. 48 49Overview 50 51 This extension allows the fragment shader to control whether values in 52 gl_SampleMaskIn[] reflect the coverage after application of the early 53 depth and stencil tests. This feature can be enabled with the following 54 layout qualifier in the fragment shader: 55 56 layout(post_depth_coverage) in; 57 58 To use this feature, early fragment tests must also be enabled in the 59 fragment shader via: 60 61 layout(early_fragment_tests) in; 62 63New Procedures and Functions 64 65 None. 66 67New Tokens 68 69 None. 70 71Additions to Chapter 15 of the OpenGL 4.3 (Compatibility Profile) Specification 72(Rasterization) 73 74 Modify Section 15.1 Fragment Shader Variables, p. 508 75 76 (modify the third paragraph on p. 509) 77 78 ...When interpolating variables declared using "centroid in", the variable 79 is sampled at a location within the pixel covered by the primitive 80 generating the fragment. The fragment shader layout qualifier 81 "post_depth_coverage" (Section 15.2.2) does not affect the determination of the 82 centroid location. 83 84 Modify Section 15.2.2 Shader Inputs, p. 511 85 86 (modify the first paragraph on p. 513) 87 88 ...Bit <n> of element <w> in the array is set if and only if the sample 89 numbered <32w + n> is considered covered for this fragment shader 90 invocation. If the fragment shader specifies the "early_fragment_tests" and 91 "post_depth_coverage" layout qualifiers, then the sample is considered covered 92 if and only if the sample is covered by the primitive and the sample passes 93 the early fragment tests (as described in Section 15.2.4). If these layout 94 qualifiers are not specified, then the sample is considered covered if the 95 sample is covered by the primitive, regardless of the result of the 96 fragment tests. ... 97 98 99New Implementation Dependent State 100 101 None. 102 103New State 104 105 None. 106 107Additions to the AGL/GLX/WGL Specifications 108 109 None. 110 111GLX Protocol 112 113 None. 114 115Modifications to the OpenGL Shading Language Specification, Version 4.30 116 117 Including the following line in a shader can be used to control the 118 language features described in this extension: 119 120 #extension GL_EXT_post_depth_coverage : <behavior> 121 122 where <behavior> is as specified in section 3.3. 123 124 New preprocessor #defines are added to the OpenGL Shading Language: 125 126 #define GL_EXT_post_depth_coverage 1 127 128 129 Modify Section 4.4.1.3 Fragment Shader Inputs (p. 58) 130 131 (replace the discussion of early_fragment_tests on p. 59) 132 133 Fragment shaders also allow the following layout qualifiers on "in" only (not 134 with variable declarations) 135 136 layout-qualifier-id 137 early_fragment_tests 138 post_depth_coverage 139 140 For example, 141 142 layout(early_fragment_tests) in; 143 layout(post_depth_coverage) in; 144 145 "early_fragment_tests" requests that fragment tests be performed before 146 fragment shader execution, as described in section 15.2.4 "Early Fragment 147 Tests" of the OpenGL Specification. If this is not declared, per-fragment 148 tests will be performed after fragment shader execution. 149 "post_depth_coverage" requests that the built-in "gl_SampleMaskIn[]" will 150 reflect the result of the early fragment tests, as described in section 151 15.2.2 "Shader Inputs" of the OpenGL Specification. 152 153 Only one fragment shader (compilation unit) need declare these, though 154 more than one can. If at least one fragment shader declares one of these, 155 then it is enabled. If any fragment shader declares "post_depth_coverage" 156 and none declare "early_fragment_tests", a link-time error will occur. 157 158 159Dependencies on NV_fragment_program4 160 161 Modify Section 2.X.6.Y of the NV_fragment_program4 specification 162 163 (add new option section) 164 165 + Post-depth Coverage (EXT_post_depth_coverage) 166 167 If a fragment program specifies the "EXT_post_depth_coverage" option, the 168 sample mask will reflect the result of the early fragment tests, as 169 described in Section 15.2.2 "Shader Inputs". If a fragment program 170 specifies the EXT_post_depth_coverage option and not the 171 NV_early_fragment_tests option, it will fail to compile. 172 173 174Interactions with OpenGL ES 3.1 175 176 If OpenGL ES 3.1 is supported, edits similar to those above are applied to 177 OpenGL ES 3.1 and GLSL ES 3.10 specifications. 178 179 Modify the edits under "Fragment Shader Inputs" as follows: 180 181 Add the following to the paragraph discussing behavior when 182 "early_fragment_tests" is enabled to reflect a pre-existing error not 183 shared with GLSL 4.30: 184 185 It is an error to statically write to gl_FragDepth in the fragment 186 shader. 187 188 Change the paragraph beginning "Only one fragment shader (compilation unit) 189 need declare..." to the following, since GLSL ES 3.10 does not support 190 linking multiple shaders of the same type: 191 192 If a fragment shader declares "post_depth_coverage" and doesn't declare 193 "early_fragment_tests", a link-time error will occur. 194 195Errors 196 197 None. 198 199Issues 200 201 (1) Should the determination of a fragment's centroid use the pre-depth or 202 post-depth coverage? 203 204 RESOLVED: In this extension, it uses the pre-depth coverage. This way the 205 centroid location (and hence the result of shading) does not depend on the 206 rendering order, which is almost certainly the desired result for 3D 207 rendering. 208 209 For path rendering, it would be desirable to use post-depth centroid since 210 the stencil test really determines whether samples are inside the primitive 211 rather than whether samples are "occluded," and guaranteeing attributes 212 are sampled inside the path would be nice. 213 214Revision History 215 216 Revision 2, 2015/03/27 217 - Add ES interactions 218 219 Revision 1, September 12, 2014 (jbolz, pbrown, jhelferty) 220 221 Internal spec development. 222