1Name 2 3 ARB_fragment_program_shadow 4 5Name Strings 6 7 GL_ARB_fragment_program_shadow 8 9Contributors 10 11 Pat Brown 12 Benj Lipchak 13 Eric Werness 14 15 and contributors to the ARB_vertex_program and 16 ARB_fragment_program working groups, the products 17 of which provided the basis for this spec. 18 19Contact 20 21 Bill Licea-Kane, AMD (bill.licea-kane 'at' amd.com) 22 23Notice 24 25 Copyright (c) 2003-2013 The Khronos Group Inc. Copyright terms at 26 http://www.khronos.org/registry/speccopyright.html 27 28Specification Update Policy 29 30 Khronos-approved extension specifications are updated in response to 31 issues and bugs prioritized by the Khronos OpenGL Working Group. For 32 extensions which have been promoted to a core Specification, fixes will 33 first appear in the latest version of that core Specification, and will 34 eventually be backported to the extension document. This policy is 35 described in more detail at 36 https://www.khronos.org/registry/OpenGL/docs/update_policy.php 37 38IP Status 39 40 Unknown, but Microsoft claims to own intellectual property 41 related to ARB_fragment_program. This extension is 42 an extension to ARB_fragment_program. 43 44Status 45 46 Complete. Approved by ARB on December 16, 2003 47 48Version 49 50 Last Modified Date: November 4, 2006 51 Revision: 6 52 53Number 54 55 ARB Extension #36 56 57Dependencies 58 59 The extension is written against the OpenGL 1.3 Specification. 60 61 ARB_fragment_program is required. 62 63 ARB_shadow is required. 64 65 EXT_texture_rectange affects the definition of this extension. 66 67Overview 68 69 This extension extends ARB_fragment_program to remove 70 the interaction with ARB_shadow. 71 72 This extension defines the program option 73 "ARB_fragment_program_shadow". 74 75 If a fragment program specifies the option "ARB_fragment_program_shadow" 76 77 SHADOW1D, SHADOW2D, SHADOWRECT 78 79 are added as texture targets. When shadow map comparisons are 80 desired, specify the SHADOW1D, SHADOW2D, or SHADOWRECT texture 81 targets in texture instructions. 82 83 Programs must assure that the comparison mode for each depth 84 texture (TEXTURE_COMPARE_MODE) and/or the internal texture 85 format (DEPTH_COMPONENT) and the targets of the texture lookup 86 instructions match. Otherwise, if the comparison mode 87 and/or the internal texture format are inconsistent with the 88 texture target, the results of the texture lookup are undefined. 89 90Issues 91 92 (1) What should this extension be called? 93 94 RESOLVED: ARB_fragment_program_shadow. Shadow support 95 is the only new feature. The name ARB_fragment_program2 96 should be used for a far more major revision to 97 ARB_fragment_program. ARB_fragment_program1_1 is 98 less descriptive. 99 100 (2) Should this extension use the header string "!!ARBfp1.1" or 101 a program option "ARB_fragment_program_shadow"? 102 103 RESOLVED: Program option "ARB_fragment_program_shadow". 104 105 (3) What form should the ARB_fragment_program_shadow option take? 106 107 a. New sampler instructions. 108 SHX result.color.a, fragment.texcoord[1], texture[0], 2D; 109 110 b. New texture modifiers. 111 TEX result.color.a, fragment.texcoord[1], texture[0], 2D,SHADOW; 112 113 c. New texture targets. 114 TEX result.color.a, fragment.texcoord[1], texture[0], SHADOW2D; 115 116 d. New sampler instructions AND new texture modifiers. 117 SHX result.color.a, fragment.texcoord[1], texture[0], 2D,SHADOW; 118 119 e. New sampler instructions AND new texture targets. 120 SHX result.color.a, fragment.texcoord[1], texture[0], SHADOW2D; 121 122 RESOLVED: Choose the simplest option c, add new texture targets. 123 124 All of the above forms are functionally equivalent. 125 126 An earlier draft proposed option a, adding six new shadow 127 instructions. The required shadow instructions are 128 three variants of shadow instruction (non-projective, projective, 129 and biased), and the same instructions with the modifier _SAT. 130 131 Option b adds texture modifiers but requires additional semantic 132 restrictions. 133 134 Option c adds texture targets only. It is a sufficient 135 and simple change to one grammar rule. 136 137 Option d and e are listed for completeness. They require 138 additional instructions and additional semantic restrictions. 139 140 Note that option e is most similar to the resolution of 141 this issue by ARB_fragment_shader and the OpenGL Shading Language. 142 The OpenGL Shading Language has both built-in texture and 143 shadow functions and sampler types, analogous to texture 144 instructions and texture targets. The resolution here 145 drops the added reduntancy and potential error checking 146 in favor of simplicity, but is otherwise consistent. 147 This resolution is also consistent with the precident 148 already established in ARB_fragment_program, since 149 we have a TEX instruction, not a TEX1D, TEX2D, TEXCUBE, 150 TEX3D, TEXRECT instructions. 151 152 (4) How should ARB_fragment_program_shadow function? 153 154 a. Simply remove the interaction with ARB_shadow so that 155 TEXTURE_COMPARE_MODE behaves exactly as specified in the 156 OpenGL 1.4 specification. 157 158 b. Add "SHADOW" targets to texture lookup instructions. 159 TEXTURE_COMPARE_MODE is ignored. For samples from a SHADOW target 160 TEXTURE_COMPARE_MODE is treated as COMPARE_R_TO_TEXTURE; 161 otherwise, it is treated as NONE. 162 163 c. Like (b), but with undefined results if TEXTURE_COMPARE_MODE and/or 164 the internal format of the texture does not match the target. 165 166 d. A hybrid of (a) and (b), where the SHADOW target means to use the 167 TEXTURE_COMPARE_MODE state. 168 169 RESOLVED - Option c, undefined behavior when the target and 170 mode do not match. 171 172 Program text is not simply loaded, it is compiled, optimized and 173 then loaded. Options a and d would remove information from the optimizer. 174 Which components of the texture coordinate are required for the sample? 175 Specifically, is the r component of the texture coordinate required? 176 Options b and c are both sufficient and retain the information 177 required by optimizers. Option c is consistent with the resolution 178 chosen by ARB_fragment_shader. 179 180 (5) What if additional texture compare modes are added by 181 future extensions to ARB_SHADOW? 182 183 We do not anticipate future extensions adding additional 184 texture compare modes. Only the additional mode COMPARE_T_TO_TEXTURE 185 has even marginal utility, and then only for SHADOW1D targets. 186 However, a future extension adding additional texture compare 187 modes is not precluded. The language in this specification 188 is carefully, if somewhat awkwardly, written to say the 189 TEXTURE_COMPARE_MODE either "is NONE" or "is not NONE. 190 191 (6) Does EXT_shadow_funcs interact with this extension? 192 193 RESOLVED: It doesn't. ARB_shadow supports LEQUAL or GEQUAL 194 comparison functions. EXT_shadow_funcs simply adds 195 the additional functions LESS, GREATER, EQUAL, NOTEQUAL, 196 ALWAYS, and NEVER. Whichever function is specified will 197 be used for the comparison function. 198 199 (7) Does ARB_shadow_ambient interact with this extension? 200 201 RESOLVED: It doesn't. ARB_shadow returns a result 202 in the range [0,1]. ARB_shadow_ambient simply 203 maps this range to [TEXTURE_COMPARE_FAIL_ARB, 1]. 204 The result will be returned in the specified range. 205 206 (8) How would an existing fragment program be ported to use the 207 program option ARB_fragment_program_shadow? 208 209 RESOLVED: Fairly simply, but with a caveat on undefined behavior. 210 211 !!ARBfp1.0 212 # A simple example of shadow map (R <= Dt) 213 # 214 # SHOULD make sure that the 2D texture bound to texture unit 0: 215 # texture format of DEPTH_COMPONENT (for highest quality comparison) 216 # TEXTURE_MAG_FILTER is NEAREST 217 # TEXTURE_MIN_FILTER is NEAREST or NEAREST_MIPMAP_NEAREST 218 # Assumes DEPTH_TEXTURE_MODE is LUMINANCE or INTENSITY 219 # 220 TEMP Result; 221 ALIAS Dt = Result; 222 TEX Dt, fragment.texcoord[0], texture[0], 2D; 223 SGE Result, Dt.x, fragment.texcoord[0].z; # R <= Dt 224 225 !!ARBfp1.0 226 OPTION ARB_fragment_program_shadow; 227 # A simple example of shadow map (R<= Dt) 228 # 229 # MUST make sure that the 2D texture bound to texture unit 0: 230 # texture format of DEPTH_COMPONENT and a 231 # TEXTURE_COMPARE_MODE of COMPARE_R_TO_TEXTURE 232 # Otherwise, the Result is undefined. 233 # 234 # Remember also that to get R <= Dt to set: 235 # TEXTURE_COMPARE_FUNC of LEQUAL 236 # 237 # A single compare equivalent to the above example will result if: 238 # TEXTURE_MAG_FILTER is NEAREST 239 # TEXTURE_MIN_FILTER is NEAREST or NEAREST_MIPMAP_NEAREST 240 # Otherwise, percent closer filtering may be applied. 241 # 242 TEMP Result; 243 TEX Result, fragment.texcoord[0], texture[0], SHADOW2D; 244 245New Procedures and Functions 246 247 None 248 249New Tokens 250 251 None 252 253Additions to Chapter 2 of the OpenGL 1.3 Specification (OpenGL Operation) 254 255 None 256 257Additions to Chapter 3 of the OpenGL 1.3 Specification (Rasterization) 258 259 Modify Section 3.11.2 Fragment Program Grammar and Semantic Restrictions 260 261 Replace <texTarget> grammar rule with 262 263 <texTarget> ::= "1D" 264 | "2D" 265 | "3D" 266 | "CUBE" 267 | "RECT" 268 | <shadowTarget> (if program option is present) 269 270 <shadowTarget> ::= "SHADOW1D" 271 | "SHADOW2D" 272 | "SHADOWRECT" 273 274 Add Section 3.11.4.5.3 Fragment Program Shadow Option 275 276 If a fragment program specifies the "ARB_fragment_program_shadow" 277 program option, the <texTarget> rule is modified to add the 278 texture targets SHADOW1D, SHADOW2D and SHADOWRECT (See Section 3.11.2). 279 280 Modify Section 3.11.6 Fragment Program Texture Instruction Set 281 282 (replace 1st through 4th paragraphs with the following paragraphs) 283 284 The first three texture instructions described below specify the 285 mapping of 4-tuple input vectors to 4-tuple output vectors. 286 The sampling of the texture works as described in section 3.8, 287 except that texture environments and texture functions are not 288 applicable, and the texture enables hierarchy is replaced by explicit 289 references to the desired texture target (i.e., 1D, 2D, 3D, cube map, 290 rectangle). These texture instructions specify how the 4-tuple is 291 mapped into the coordinates used for sampling. The following function 292 is used to describe the texture sampling in the descriptions below: 293 294 vec4 TextureSample(float s, float t, float r, float lodBias, 295 int texImageUnit, enum texTarget); 296 297 Note that not all three texture coordinates, s, t, and r, are 298 used by all texture targets. In particular, 1D texture targets only 299 use the s component. 2D and RECT (non-power-of-two) texture 300 targets only use the s and t components. SHADOW1D texture 301 targets only use the s and r components. The descriptions of the 302 texture instructions below supply all three components, as would 303 be the case with CUBE, 3D, SHADOW2D, and SHADOWRECT targets. 304 305 If a fragment program samples from a texture target on a texture 306 image unit where the bound texture object is not complete, as 307 defined in section 3.8.9, the result will be the vector 308 (R, G, B, A) = (0, 0, 0, 1). 309 310 If a fragment program does not specify the "ARB_fragment_program_shadow" 311 program option, and if a fragment program samples from a texture 312 target of 1D, 2D, or RECT, it is as if TEXTURE_COMPARE_MODE_ARB is NONE. 313 314 If a fragment program specifies the "ARB_fragment_program_shadow" 315 program option, the result returned of a sample from a texture target on 316 a texture image unit is undefined if: 317 318 the texture target is 1D, 2D, or RECT, and 319 the texture object's internal format is DEPTH_COMPONENT_ARB, and 320 the TEXTURE_COMPARE_MODE_ARB is not NONE; 321 322 or 323 324 the texture target is SHADOW1D, SHADOW2D, SHADOWRECT, and 325 the texture object's internal format is DEPTH_COMPONENT_ARB, and 326 the TEXTURE_COMPARE_MODE_ARB is NONE; 327 328 or 329 330 the texture target is SHADOW1D, SHADOW2D, SHADOWRECT, and 331 the texture object's internal format is not DEPTH_COMPONENT_ARB. 332 333 A fragment program will fail to load if it attempts to sample from 334 multiple texture targets on the same texture image unit. For 335 example, the following programs would fail to load: 336 337 !!ARBfp1.0 338 TEX result.color.rgb, fragment.texcoord[0], texture[0], 2D; 339 TEX result.color.a, fragment.texcoord[1], texture[0], 3D; 340 END 341 342 !!ARBfp1.0 343 OPTION ARB_fragment_program_shadow; 344 TEX result.color.rgb, fragment.texcoord[0], texture[0], 2D; 345 TEX result.color.a, fragment.texcoord[1], texture[0], SHADOW2D; 346 END 347 348Additions to Chapter 4 of the OpenGL 1.3 Specification (Per-Fragment Operations and the Frame Buffer) 349 350 None 351 352Additions to Chapter 5 of the OpenGL 1.3 Specification (Special Functions) 353 354 None 355 356Additions to Chapter 6 of the OpenGL 1.3 Specification (State and State Requests) 357 358 None 359 360Additions to Appendix A of the OpenGL 1.3 Specification (Invariance) 361 362 None 363 364Additions to the AGL/GLX/WGL Specifications 365 366 None 367 368Dependencies on EXT_texture_rectangle 369 370 If EXT_texture_rectangle is not supported: 371 372 Section 3.11.2 should be modified by removing the line: 373 374 | "SHADOWRECT" 375 376 from the <shadowTarget> grammar rule; 377 378 and Section 3.11.6 should be modified by removing the discussion 379 of the rectangle shadow texture target. 380