1Name 2 3 EXT_shader_texture_lod 4 5Name Strings 6 7 GL_EXT_shader_texture_lod 8 9Contributors 10 11 Benj Lipchak 12 Ben Bowman 13 14 and contributors to the ARB_shader_texture_lod spec, 15 which provided the basis for this spec. 16 17Contact 18 19 Benj Lipchak, Apple (lipchak 'at' apple.com) 20 21IP Status 22 23 No known IP issues. 24 25Status 26 27 Draft 28 29Version 30 31 Last Modified Date: February 24, 2011 32 Revision: 3 33 34Number 35 36 OpenGL ES Extension #77 37 38Dependencies 39 40 This extension is written against the OpenGL ES 2.0 Specification. 41 42 This extension is written against The OpenGL ES Shading Language, 43 Language Version 1.00, Document Revision 17. 44 45 This extension interacts with EXT_texture_filter_anisotropic. 46 47Overview 48 49 This extension adds additional texture functions to the 50 OpenGL ES Shading Language which provide the shader writer 51 with explicit control of LOD. 52 53 Mipmap texture fetches and anisotropic texture fetches 54 require implicit derivatives to calculate rho, lambda 55 and/or the line of anisotropy. These implicit derivatives 56 will be undefined for texture fetches occurring inside 57 non-uniform control flow or for vertex shader texture 58 fetches, resulting in undefined texels. 59 60 The additional texture functions introduced with 61 this extension provide explicit control of LOD 62 (isotropic texture functions) or provide explicit 63 derivatives (anisotropic texture functions). 64 65 Anisotropic texture functions return defined texels 66 for mipmap texture fetches or anisotropic texture fetches, 67 even inside non-uniform control flow. Isotropic texture 68 functions return defined texels for mipmap texture fetches, 69 even inside non-uniform control flow. However, isotropic 70 texture functions return undefined texels for anisotropic 71 texture fetches. 72 73 The existing isotropic vertex texture functions: 74 75 vec4 texture2DLodEXT(sampler2D sampler, 76 vec2 coord, 77 float lod); 78 vec4 texture2DProjLodEXT(sampler2D sampler, 79 vec3 coord, 80 float lod); 81 vec4 texture2DProjLodEXT(sampler2D sampler, 82 vec4 coord, 83 float lod); 84 85 vec4 textureCubeLodEXT(samplerCube sampler, 86 vec3 coord, 87 float lod); 88 89 are added to the built-in functions for fragment shaders 90 with "EXT" suffix appended. 91 92 New anisotropic texture functions, providing explicit 93 derivatives: 94 95 vec4 texture2DGradEXT(sampler2D sampler, 96 vec2 P, 97 vec2 dPdx, 98 vec2 dPdy); 99 vec4 texture2DProjGradEXT(sampler2D sampler, 100 vec3 P, 101 vec2 dPdx, 102 vec2 dPdy); 103 vec4 texture2DProjGradEXT(sampler2D sampler, 104 vec4 P, 105 vec2 dPdx, 106 vec2 dPdy); 107 108 vec4 textureCubeGradEXT(samplerCube sampler, 109 vec3 P, 110 vec3 dPdx, 111 vec3 dPdy); 112 113 are added to the built-in functions for vertex shaders 114 and fragment shaders. 115 116New Procedures and Functions 117 118 None 119 120New Tokens 121 122 None 123 124Additions to Chapter 2 of the OpenGL ES 2.0 Specification (OpenGL Operation) 125 126 None 127 128Additions to Chapter 3 of the OpenGL ES 2.0 Specification (Rasterization) 129 130 In Section 3.7.7, replace the final paragraph on p. 76 with: 131 132 "Let s(x, y) be the function that associates an s texture coordinate 133 with each set of window coordinates (x, y) that lie within a 134 primitive; define t(x, y) analogously. Let u(x, y) = wt * s(x, y) and 135 v(x, y) = ht * t(x, y), where wt and ht are equal to the width and height 136 of the level zero array. 137 138 Let 139 dUdx = wt*dSdx; dUdy = wt*dSdy; 140 dVdx = ht*dTdx; dVdy = ht*dTdy; (3.12a) 141 142 where dSdx indicates the derivative of s with respect to window x, 143 and similarly for dTdx. 144 145 For a polygon, rho is given at a fragment with window coordinates 146 (x, y) by 147 148 rho = max ( 149 sqrt(dUdx*dUdx + dVdx*dVdx), 150 sqrt(dUdy*dUdy + dVdy*dVdy) 151 ); (3.12b)" 152 153Additions to Chapter 4 of the OpenGL ES 2.0 Specification (Per-Fragment Operations and the Frame Buffer) 154 155 None 156 157Additions to Chapter 5 of the OpenGL ES 2.0 Specification (Special Functions) 158 159 None 160 161Additions to Chapter 6 of the OpenGL ES 2.0 Specification (State and State 162Requests) 163 164 None 165 166Additions to Appendix A of the OpenGL ES 2.0 Specification (Invariance) 167 168 None 169 170Additions to version 1.00.17 of the OpenGL ES Shading Language Specification 171 172 "A new preprocessor #define is added to the OpenGL Shading Language: 173 174 #define GL_EXT_shader_texture_lod 1 175 176 Including the following line in a shader can be used to control the 177 language features described in this extension: 178 179 #extension GL_EXT_shader_texture_lod : <behavior> 180 181 Where <behavior> is as specified in section 3.3." 182 183 184Additions to Chapter 8 of version 1.00.17 of the OpenGL ES Shading Language 185Specification 186 187 188 8.7 Texture Lookup Functions 189 190 Delete the last paragraph, and replace with: 191 192 "For the "Lod" functions, lod specifies lambda_base (see equation 3.11 in 193 The OpenGL ES 2.0 Specification) and specifies dSdx, dTdx = 0 and 194 dSdy, dTdy = 0 (see equation 3.12a in The OpenGL ES 2.0 Specification). 195 The "Lod" functions are allowed in a vertex shader. If enabled by the 196 preprocessor directive #extension, the "Lod" functions are also allowed in 197 a fragment shader. 198 199 For the "Grad" functions, dPdx is the explicit derivative of P with respect 200 to window x, and similarly dPdy with respect to window y. For the "ProjGrad" 201 functions, dPdx is the explicit derivative of the projected P with respect 202 to window x, and similarly for dPdy with respect to window y. For a two- 203 dimensional texture, dPdx and dPdy are vec2. For a cube map texture, 204 dPdx and dPdy are vec3. 205 206 Let 207 208 dSdx = dPdx.s; 209 dSdy = dPdy.s; 210 dTdx = dPdx.t; 211 dTdy = dPdy.t; 212 213 and 214 215 / 0.0; for two-dimensional texture 216 dRdx = ( 217 \ dPdx.p; for cube map texture 218 219 / 0.0; for two-dimensional texture 220 dRdy = ( 221 \ dPdy.p; for cube map texture 222 223 (See equation 3.12a in The OpenGL ES 2.0 Specification.) 224 225 If enabled by the preprocessor directive #extension, the "Grad" functions 226 are allowed in vertex and fragment shaders. 227 228 All other texture functions may require implicit derivatives. Implicit 229 derivatives are undefined within non-uniform control flow or for vertex 230 shader texture fetches." 231 232 Add the following entries to the texture function table: 233 234 vec4 texture2DGradEXT(sampler2D sampler, 235 vec2 P, 236 vec2 dPdx, 237 vec2 dPdy); 238 vec4 texture2DProjGradEXT(sampler2D sampler, 239 vec3 P, 240 vec2 dPdx, 241 vec2 dPdy); 242 vec4 texture2DProjGradEXT(sampler2D sampler, 243 vec4 P, 244 vec2 dPdx, 245 vec2 dPdy); 246 247 vec4 textureCubeGradEXT(samplerCube sampler, 248 vec3 P, 249 vec3 dPdx, 250 vec3 dPdy); 251 252Interactions with EXT_texture_anisotropic 253 254 The Lod functions set the derivatives ds/dx, dt/dx, dr/dx, 255 dx/dy, dt/dy, and dr/dy = 0. Therefore Rhox and Rhoy = 0 256 0, Rhomax and Rhomin = 0. 257 258Revision History: 259 2603 - 2011-02-24 261 * Assign extension number 262 2632 - 2010-01-20 264 * Naming updates 265 2661 - 2010-01-19 267 * Initial ES version 268