1XXX - Dead -- couldn't convince the ARB. Use fragment_lighting & 2XXX separate_specular_color instead. 3XXX - Not complete yet!!! 4 5Name 6 7 SGIX_fragment_specular_lighting 8 9Name Strings 10 11 GL_SGIX_fragment_specular_lighting 12 13Version 14 15 $Date: 1998/07/06 19:51:38 $ $Revision: 1.2 $ 16 17Number 18 19 ?? 20 21Dependencies 22 23 OpenGL 1.1 is required. 24 SGIX_color_range affects the definition of this extension. 25 26Overview 27 28 This extension adds a new lighting stage to the OpenGL pipeline. This 29 stage occurs during fragment processing after the texture environment 30 has been applied and before fog has been applied. The extension 31 provides a mechanism for computing a post-texture specular lighting term. 32 This extension doesn't eliminate the specular term in vertex lighting, but 33 can be used to augment it. This extension provides the state framework for a 34 more general lighting model, but only includes the equation for computing 35 the specular contribution. The more general version is described in 36 SGIX_fragment_lighting. 37 38 39 40 Ct Cf 41 | |-------------------------------+ 42 | | | 43 ---------- | 44 | | | 45 | TexEnv | | 46 | | | 47 ---------- | 48 | | 49 ---------- | 50 | Clamp | Nf Lf Hf Ff | 51 ---------- | | | | | 52 | ----------------- | FragmentColorMaterial 53 | | | v 54 Cf' | FragmentLight |--o-<- Material {Sm,...} 55 | | | 56 | ----------------- 57 | | 58 | --------- 59 | | Clamp | 60 | --------- 61 | Cl | 62 | +---------------- 63 v v 64 ------------ 65 | | 66 | SUM | 67 | | 68 ------------ 69 | 70 --------- 71 | Clamp | 72 --------- 73 | 74 Cf'' 75 | 76 v 77 ------- 78 | | 79 | Fog | 80 | | 81 ------- 82 | 83 v 84 85IP Status 86 87 Silicon Graphics has filed for patent protection for some of the 88 techniques described in this extension document. 89 90Issues 91 92 * does this spec enable a reasonable evolution from a post-texture 93 specular highlight to a full blown per-pixel lighting computation? 94 95 * can we eliminate some commands and state now and allow the generality 96 to show up later? It doesn't seem like there is much harm in maintaining 97 extra state for computations that isn't actually used since it can be 98 maintained on the host. We eliminate the Lighting environment term 99 since it provides extra capability for how the lighting term is combined. 100 It can show up with the fragment_lighting extension. 101 102 * given the relaxation in the requirements for how the specular term is 103 computed, it is possible to support multiple specular lights but much 104 less likely to be able to support the same number of full blown fragment 105 lights. 106 107 108New Procedures and Functions 109 110 void FragmentLightModeliSGIX(enum pname, int param); 111 void FragmentLightModelfSGIX(enum pname, float param); 112 void FragmentLightModelivSGIX(enum pname, int *params); 113 void FragmentLightModelfvSGIX(enum pname, float *params); 114 115 void FragmentLightiSGIX(enum light, enum pname, int param); 116 void FragmentLightfSGIX(enum light, enum pname, float param); 117 void FragmentLightivSGIX(enum light, enum pname, int *params); 118 void FragmentLightfvSGIX(enum light, enum pname, float *params); 119 120 void GetFragmentLightivSGIX(enum light, enum value, int *data); 121 void GetFragmentLightfvSGIX(enum light, enum value, float *data); 122 123 void FragmentMaterialfSGIX(enum face, enum pname, const float param); 124 void FragmentMaterialiSGIX(enum face, enum pname, const int param); 125 void FragmentMaterialfvSGIX(enum face, enum pname, const float *params); 126 void FragmentMaterialivSGIX(enum face, enum pname, const int *params); 127 128 void FragmentColorMaterialSGIX(enum face, enum mode); 129 130 void GetFragmentMaterialfvSGIX(enum face, enum pname, float *data); 131 void GetFragmentMaterialivSGIX(enum face, enum pname, int *data); 132 133New Tokens 134 135 Accepted by the <cap> parameter of Enable, Disable, and IsEnabled, by 136 the <pname> parameter of GetBooleanv, GetIntegerv, GetFloatv, and 137 GetDoublev: 138 139 FRAGMENT_LIGHTING_SGIX XXXX 140 FRAGMENT_COLOR_MATERIAL_SGIX XXXX 141 FRAGMENT_COLOR_MATERIAL_FACE_SGIX XXXX 142 FRAGMENT_COLOR_MATERIAL_PARAMETER_SGIX XXXX 143 144 Accepted by the <pname> parameter of GetBooleanv, GetIntegerv, GetFloatv, 145 and GetDoublev: 146 147 MAX_FRAGMENT_LIGHTS_SGIX XXXX 148 MAX_ACTIVE_LIGHTS_SGIX XXXX 149 CURRENT_RASTER_NORMAL_SGIX XXXX 150 151 Accepted by the <light> parameter of FragmentLightfSGIX, 152 FragmentLightiSGIX, FragmentLightfvSGIX, and FragmentLightivSGIX, and by 153 the <cap> parameter of Enable, Disable, and IsEnabled, and by the <light> 154 parameter of GetFragmentLightfvSGIX and GetFragmentLightivSGIX: 155 156 FRAGMENT_LIGHT0_SGIX XXXX 157 . 158 . 159 . 160 FRAGMENT_LIGHT7_SGIX XXXX 161 162 Accepted by the <pname> parameter of FragmentLightModeliSGIX, 163 FragmentLightModelfSGIX, FragmentLightModelivSGIX, 164 FragmentLightModelfvSGIX, GetBooleanv, GetIntegerv, GetFloatv, and 165 GetDoublev: 166 167 FRAGMENT_LIGHT_MODEL_LOCAL_VIEWER_SGIX XXXX 168 FRAGMENT_LIGHT_MODEL_TWO_SIDE_SGIX XXXX 169 FRAGMENT_LIGHT_MODEL_AMBIENT_SGIX XXXX 170 FRAGMENT_LIGHT_MODEL_NORMAL_INTERPOLATION_SGIX XXXX 171 172Additions to Chapter 2 of the 1.1 Specification (OpenGL Operation) 173 174 Section 2.12 Current Raster Position 175 176 ... <paragraph 2> 177 The current raster position consists of three window coordinates xw, yw, 178 and zw, a clip corrdinate wc value, an eye coordinate distance, a valid 179 bit, and associated data consisting of a color, normal, and texture 180 coordinates. It is set ... 181 182 ... <paragraph 5> 183 The current raster position requires five single-precision floating point 184 values for its xw, yw, and zw window coordinates, its wc clip coordinate, 185 and its eye coordinate distance, a single valid bit, a color (RGBA and color 186 index), normal, and texture coordinates for associated data. In the initial 187 state, the coordinates and texture coordinates are both (0,0,0,1), the eye 188 coordinate distance is 0, the valid bit is set, the associated RGBA color is 189 (1,1,1,1), the associated color index is 1, and the associated normal is 190 (0,0,1). In RGBA mode, the associated color index always has its initial 191 value; in color index mode, the RGBA color always maintains its initial 192 value. 193 194 Section 2.13 Colors and Coloring 195 196 ... 197 Next vertex lighting, if enabled produces a color. If vertex lighting is 198 disabled, the current color is used in further processing. After vertex 199 lighting, RGBA colors are clamped to the range [0,1]. A color index is 200 converted to fixed-point and then its integer portion is masked (see 201 section 2.13.16). After clamping or masking, a primitive may be flatshaded, 202 indicating that all vertices of the primitive are to have the same color 203 (and normal). Finally, a primitive is clipped, then colors (texture 204 coordinates and normals) must be computed at the vertices introduced or 205 modified by clipping. 206 207Additions to Chapter 3 of the 1.1 Specification (Rasterization) 208 209 Section 3.6.3 Rasterization of Pixel Rectangles 210 211 Conversion to Fragments 212 213 ... <paragraph 2> 214 A fragment arising from a group consisting of color data takes on the color 215 index or color components of the group; the depth, normal and texture 216 coordinates are taken from the current raster position's associated data. 217 A fragment arising from a depth component takes the component's depth 218 value; the color, normal, and texture coordinate are given by those associated 219 with the current raster position. In both cases texture coordinates s, t, 220 and r are preplaced with s/q, t/q, and r/q, respectively. If q is less than 221 or equal to zero the results are undefined. Groups arising from DrawPixels 222 with a <format> of STENCIL_INDEX are treated specially and are described in 223 section 4.3.1. 224 225 226 Before Section 3.9 Fog insert: 227 228 Section 3.9 Fragment Lighting 229 230 If enabled, fragment lighting computes a color for each rasterized fragment 231 by applying an equation defined by a client-specified lighting model to 232 a collection of parameters that can include the fragment coordinates, the 233 coordinates of one or more light sources, the fragment normal, and 234 parameters defining the characteristics of the light source and current 235 fragment material. Fragment lighting is only defined for RGBA mode, it 236 has no effect in color index mode. 237 238 Fragment lighting may be in one of two states: 239 240 1. Lighting Off. In this state the color assigned to a fragment is the 241 rasterized fragment's post-texturing color. 242 243 2. Lighting On. In this state the color assigned to a fragment is the 244 result of summing the rasterized fragment's post-texturing color and 245 a color computed from the current fragment lighting parameters. 246 247 Fragment lighting is turned either on or off using the generic Enable or 248 Disable commands with the symbolic value FRAGMENT_LIGHTING_SGIX. 249 250 3.9.2 Lighting Operation 251 252 The desired general equation for the fragment illumination model is: 253 254 Cl = Em emissive 255 + Am*As ambient material*scene ambient color 256 SUM{_i = 0 through Nf-1} { 257 + Atten_i*SpotL_i*{ distance/spot light attenuation 258 + Am*Al_i ambient material*ambient light 259 + Dm*Dl_i*(N.L_i) diffuse material*diffuse light 260 + Sm*Sl_i*(N.H_i)^n specular material*specular light 261 } 262 } 263 264 Nf is the number of fragment light sources 265 N is the fragment normal vector 266 L_i is the direction vector from the fragment position to the light source 267 H_i is the half angle vector 268 n is the specular exponent (shininess) 269 270 Subset the equation to the specular term: 271 272 I[i] = Sm*Sl*(N.H_i)^n) 273 274 and 275 276 I' = SUM{i = 0 through Nf-1} I[i] (3.1) 277 278 279 Equation (3.1) is essentially the same as the specular term of the vertex 280 lighting equation described in section 2.13.1 for a single light source. 281 282 In order to compute the illumination terms for each fragment, the eye 283 coordinates of the fragment can be used to compute the light direction, 284 half angle vector, and attenuation factor in a manner similar to that used 285 in the vertex lighting computations. It is permissible for an 286 implementation to approximate these by computing these values as well as 287 the normal vector at the vertices and interpolating and renormalizing the 288 results, or by computing the entire equation at the vertices and 289 interpolating the color. 290 291 Fragment material state is maintained which is distinct from the 292 vertex material state. The fragment material state consists of 293 emission, ambient, diffuse, specular and shininess terms for both 294 the front and back face of a primitive though only the specular and 295 shininess terms are used by this extension. Unlike vertex lighting, the 296 fragment material state is constant across a primitive since 297 it is resolved during rasterization. The results of the back face 298 computation described in section 3.5.1 are used to determine whether 299 the front material or back material is used when two sided lighting 300 is enabled. 301 302 There is separate state for each fragment light source. The 303 fragment light source parameters are the same as the vertex light 304 source parameters described in section 2.13.1. The minimum number of 305 fragment light sources is 1. The number of available fragment light 306 sources can be queried by issuing the Get command with the <pname> 307 parameter set to MAX_FRAGMENT_LIGHTS_SGIX. 308 309 Distinct lighting model state is also maintained for vertex lighting and 310 fragment lighting. The lighting model state is described in section 311 2.13.1. Fragment lighting model state includes one additional parameter, 312 FRAGMENT_LIGHT_MODEL_NORMAL_INTERPOLATION_SGIX, which controls how normals 313 are selected for use in the fragment lighting computations for a primitive. 314 If FLAT is selected for the lighting model, the normal from the provoking 315 vertex (as described in Section 2.13.7 Flatshading) of the primitive for all 316 fragment lighting computations for the primitive. If SMOOTH is specified 317 a normal is computed for each fragment using the normals from all of the 318 vertices of the primitive. 319 320 Fragment lighting differs from vertex lighting in that all components 321 of lighting parameters which are of type color in Table 2.7 are clamped 322 to the range [0,1] when they are specified. 323 324 Equation 3.2 is evaluated for each light source and the resulting 325 colors are summed. The resulting color components are clamped to the 326 range [0,1] and then passed to the lighting environment computation. 327 328 329 3.9.3 Lighting Parameter Specification 330 331 GetFragmentMaterialfvSGIX and GetFragmentMaterialivSGIX. 332 The fragment material state can be set with the commands 333 FragmentMaterialfSGIX, FragmentMaterialfvSGIX, FragmentMaterialiSGIX, 334 FragmentMaterialivSGIX using the values AMBIENT, DIFFUSE, SPECULAR, 335 SHININESS and EMISSION. This state can be queried using the commands 336 GetFragmentMaterialfvSGIX and GetFragmentMaterialivSGIX. 337 338 Lighting parameters for fragment light i can be modified by issuing the 339 commands FragmentLightfSGIX, FragmentLightiSGIX, FragmentLightfvSGIX, and 340 FragmentLightivSGIX with the <light> parameter 341 set to FRAGMENT_LIGHTi_SGIX. The lighting parameters for fragment light i 342 can be queried by issuing the commands GetFragmentLightfvSGIX and 343 GetFragmentLightivSGIX with the <light> parameter set to FRAGMENT_LIGHTi_SGIX. 344 345 Lighting model parameters for fragment lighting can be modified using the 346 commands FragmentLightModel{T}SGIX, FragmentLightModel{T}vSGIX. The 347 lighting model parameters can be queried by issuing the Get command <pname> 348 parameter set to the appropriate fragment lighting model parameter: 349 FRAGMENT_LIGHT_MODEL_LOCAL_VIEWER_SGIX, FRAGMENT_LIGHT_MODEL_TWO_SIDE_SGIX, 350 FRAGMENT_LIGHT_MODEL_AMBIENT_SGIX or FRAGMENT_LIGHT_MODEL_NORMAL_INTERPOLATION_SGIX. 351 352 353 3.9.4 FragmentColorMaterial 354 355 It is possible to replace one or more fragment material properties terms in 356 Equation 3.1 with the fragment's pre-texturing color, causing these color 357 values to be used during the lighting computation. This behavior is enabled 358 and disabled by calling Enable and Disable with the symbolic value 359 FRAGMENT_COLOR_MATERIAL. 360 361 The command that controls which of these modes is selected is 362 363 void FragmentColorMaterial(enum face, enum mode); 364 365 <face> is one of FRONT, BACK, or FRONT_AND_BACK, indicating whether 366 the front material, back material, or both are affected by the 367 pre-texturing color. <mode> is one of EMISSION, AMBIENT, DIFFUSE, 368 SPECULAR, or AMBIENT_AND_DIFFUSE and specifies which material property 369 or properties are subsituted with the pre-texturing color. The substutions 370 do not affect the material state. When FragmentColorMaterial 371 is disabled the values in the fragment material state are used. 372 GetFragmentMaterial returns the fragment material last specified with 373 FragmentMaterial, regardless of whether FragmentColorMaterial is enabled. 374 Although all of the fragment material parameters may be substituted, only 375 substituting the SPECULAR material property will affect the result of 376 the lighting computation. 377 378 3.9.5 Interactions with Vertex Lighting 379 380 In order to allow implementions to share resources for vertex lighting and 381 fragment lighting, an implementation may limit the maximum number of combined 382 vertex and fragment lights to a number less than the sum of MAX_LIGHTS and 383 MAX_FRAGMENT_LIGHTS_SGIX. This limit can be queried using the Get command 384 with <pname> parameter MAX_ACTIVE_LIGHTS_SGIX. State for all 385 fragment and vertex lights is always maintained. When multiple 386 lights are enabled, priority is given to vertex lights starting with 387 LIGHT0 through LIGHT<n> where <n> is equal to MAX_LIGHTS, followed by 388 FRAGMENT_LIGHT0_SGIX through FRAGMENT_LIGHT<m>_SGIX where <m> is equal 389 to MAX_FRAGMENT_LIGHTS_SGIX. 390 391 392Additions to Chapter 4 of the 1.1 Specification (Per-Fragment Operations 393and the Frame Buffer) 394 395 None 396 397Additions to Chapter 5 of the 1.1 Specification (Special Functions) 398 399 None 400 401Additions to Chapter 6 of the 1.1 Specification (State and State Requests) 402 403 TBD 404 405Additions to the GLX Specification 406 407 TBD 408 409Dependencies on SGIX_color_range 410 411 If SGIX_color_range is implemented, then the components of lighting 412 parameters of type color, the result of evaluating the lighting 413 equation and the results of evaluating the lighting environment 414 are clamped to the extended color range rather than [0,1]. 415 416 417Errors 418 INVALID_ENUM is generated if FragmentMaterial{T}SGIX, 419 FragmentMaterial{T}vSGIX, or FragmentColorMaterialSGIX, parameter <face> is 420 not FRONT, BACK or FRONT_AND_BACK. 421 422 INVALID_ENUM is generated if FragmentMaterial{T}SGIX or 423 FragmentMaterial{T}vSGIX parameter <pname> is not AMBIENT, DIFFUSE, 424 SPECULAR, EMISSION, SHININESS, or AMBIENT_AND_DIFFUSE. 425 426 INVALID_ENUM is generated if GetFragmentMaterial{T}vSGIX parameter <face> 427 is not FRONT or BACK. 428 429 INVALID_ENUM is generated if GetFragmentMaterial{T}vSGIX parameter <pname> 430 is not AMBIENT, DIFFUSE, SPECULAR, EMISSION, or SHININESS, 431 432 INVALID_ENUM if FragmentColorMaterialSGIX parameter <mode> is not EMISSION, 433 AMBIENT, DIFFUSE, SPECULAR, or AMBIENT_AND_DIFFUSE 434 435 INVALID_ENUM if LightEnviSGIX parameter <pname> is not LIGHT_ENV_MODE_SGIX 436 or if parameter <mode> is not REPLACE, MODULATE, or ADD. 437 438 INVALID_ENUM is generated if FragmentLightModel{T}SGIX <pname> is not 439 FRAGMENT_LIGHT_MODEL_LOCAL_VIEWER_SGIX, FRAGMENT_LIGHT_MODEL_TWO_SIDE_SGIX 440 or FRAGMENT_LIGHT_MODEL_NORMAL_INTERPOLATION_SGIX or if 441 FragmentLightModel{T}vSGIX, parameter <pname> is not 442 FRAGMENT_LIGHT_MODEL_AMBIENT_SGIX, FRAGMENT_LIGHT_MODEL_LOCAL_VIEWER_SGIX 443 FRAGMENT_LIGHT_MODEL_TWO_SIDE_SGIX or 444 FRAGMENT_LIGHT_MODEL_NORMAL_INTERPOLATION_SGIX. 445 446 INVALID_ENUM is generated if FragmentLight{T}SGIX, FragmentLight{T}vSGIX, 447 or GetFragmentLight{T}vSGIX parameter <light> is not FRAGMENT_LIGHT0_SGIX 448 ... FRAGMENT_LIGHT<n>_SGIX where n is one minus the number of supported 449 fragment lights, or if FragmentLight{T}SGIX parameter <pname> is not 450 SPOT_EXPONENT, SPOT_CUTOFF, CONSTANT_ATTENUATION, LINEAR_ATTENUATION, or 451 QUADRATIC_ATTENUATION, or if FragmentLight{T}vSGIX or 452 GetFragmentLight{T}vSGIX parameter <pname> is not AMBIENT, DIFFUSE, 453 SPECULAR, POSITION, SPOT_DIRECTION, SPOT_EXPONENT, SPOT_CUTOFF, 454 CONSTANT_ATTENUATION, LINEAR_ATTENUATION, or QUADRATIC_ATTENUATION. 455 456 INVALID_VALUE is generated if FragmentLight{T}SGIX or FragmentLight{T}vSGIX 457 parameter <param> if a spot exponent value is specified outside the range 458 [0,128], or if spot cutoff is specified outside the range [0,90] (except 459 for the special value 180), or if a negative attenuation factor is 460 specified. 461 462 INVALID_OPERATION is generated if FragmentMaterial{T}SGIX, 463 FragmentMaterial{T}vSGIX, FragmentColorMaterialSGIX, 464 GetFragmentMaterial{T}vSGIX, LightEnviSGIX, FragmentLight{T}SGIX, 465 FragmentLight{T}vSGIX, FragmentLightModel{T}SGIX, 466 FragmentLightModel{T}vSGIX or GetFragmentLight{T}vSGIX is executed between 467 execution of Begin and the corresponding execution of End. 468 469New State 470 471 Get Value Get Command Type Initial Value Attribute 472 --------- ----------- ---- ------------- --------- 473 474 FRAGMENT_LIGHTING_SGIX IsEnabled B False lighting/enable 475 FRAGMENT_COLOR_MATERIAL_SGIX IsEnabled B False lighting/enable 476 FRAGMENT_COLOR_MATERIAL_PARAMETER_SGIX GetIntegerv Z5 AMBIENT_AND_DIFFUSE lighting 477 FRAGMENT_COLOR_MATERIAL_FACE_SGIX GetIntegerv Z3 FRONT_AND_BACK lighting 478 AMBIENT GetFragmentMaterialfvSGIX 2xC (0.2,0.2,0.2,1.0) lighting 479 DIFFUSE GetFragmentMaterialfvSGIX 2xC (0.8,0.8,0.8,1.0) lighting 480 SPECULAR GetFragmentMaterialfvSGIX 2xC (0.0,0.0,0.0,1.0) lighting 481 EMISSION GetFragmentMaterialfvSGIX 2xC (0.0,0.0,0.0,1.0) lighting 482 SHININESS GetFragmentMaterialfvSGIX 2xR 0.0 lighting 483 FRAGMENT_LIGHT_MODEL_AMBIENT_SGIX GetFloatv C (0.2,0.2,0.2,0.2) lighting 484 FRAGMENT_LIGHT_MODEL_LOCAL_VIEWER_SGIX GetBooleanv B False lighting 485 FRAGMENT_LIGHT_MODEL_TWO_SIDE_SGIX GetBooleanv B False lighting 486 FRAGMENT_LIGHT_MODEL_NORMAL_INTERPOLATION_SGIX GetIntegerv Z2 SMOOTH lighting 487 AMBIENT GetFragmentLightfvSGIX 1*xC (0.0,0.0,0.0,1.0) lighting 488 DIFFUSE GetFragmentLightfvSGIX 1*xC see 3.x lighting 489 SPECULAR GetFragmentLightfvSGIX 1*xC see 3.x lighting 490 POSITION GetFragmentLightfvSGIX 1*xP (0.0,0.0,1.0,0.0) lighting 491 CONSTANT_ATTENUATION GetFragmentLightfvSGIX 1*xR 1.0 lighting 492 LINEAR_ATTENUATION GetFragmentLightfvSGIX 1*xR+ 0.0 lighting 493 QUADRATIC_ATTENUATION GetFragmentLightfvSGIX 1*xR+ 0.0 lighting 494 SPOT_DIRECTION GetFragmentLightfvSGIX 1*xD (0.0,0.0,-1.0) lighting 495 SPOT_EXPONENT GetFragmentLightfvSGIX 1*xR+ 0.0 lighting 496 SPOT_CUTOFF GetFragmentLightfvSGIX 1*xR+ 180.0 lighting 497 FRAGMENT_LIGHTi_SGIX IsEnabled 1*xB False lighting/enable 498 LIGHT_ENV_MODE_SGIX GetIntegerv Z3 REPLACE lighting 499 500 CURRENT_RASTER_NORMAL_SGIX GetFloatv N (0,0,1) current 501 502New Implementation Dependent State 503 504 Get Value Get Command Type Minimum Value 505 --------- ----------- ---- ------------- 506 MAX_FRAGMENT_LIGHTS_SGIX GetIntegerv Z+ 1 507 MAX_ACTIVE_LIGHTS_SGIX GetIntegerv z+ MAX_LIGHTS 508