Changeset 3598 for trunk/src/opengl/mesa/shade.c
- Timestamp:
- May 23, 2000, 10:41:28 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/opengl/mesa/shade.c
r2938 r3598 1 /* $Id: shade.c,v 1. 1 2000-02-29 00:50:10 sandervlExp $ */1 /* $Id: shade.c,v 1.2 2000-05-23 20:40:53 jeroen Exp $ */ 2 2 3 3 /* 4 4 * Mesa 3-D graphics library 5 * Version: 3. 15 * Version: 3.3 6 6 * 7 7 * Copyright (C) 1999 Brian Paul All Rights Reserved. … … 32 32 #include "all.h" 33 33 #else 34 #ifndef XFree86Server 35 #include <math.h> 36 #include <stdio.h> 37 #else 38 #include "GL/xf86glx.h" 39 #endif 34 #include "glheader.h" 40 35 #include "light.h" 41 36 #include "macros.h" … … 51 46 52 47 53 #define GET_SHINE_TAB_ENTRY( tab, dp, result ) 54 do { 55 int k = (int) (dp * SHINE_TABLE_SIZE); 56 result = tab->tab[k]; 48 #define GET_SHINE_TAB_ENTRY( tab, dp, result ) \ 49 do { \ 50 int k = (int) (dp * SHINE_TABLE_SIZE); \ 51 result = tab->tab[k]; \ 57 52 } while(0) 58 53 … … 203 198 if (ctx->Visual->RGBAflag) { 204 199 if (ctx->Light.NeedVertices) { 205 206 207 208 209 idx = SHADE_RGBA_VERTICES; 200 if (ctx->Texture.Enabled && 201 ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR) 202 idx = SHADE_RGBA_SPEC; 203 else 204 idx = SHADE_RGBA_VERTICES; 210 205 } 211 206 else 212 207 idx = SHADE_RGBA_NORMALS; 213 208 } 214 209 else … … 230 225 */ 231 226 void gl_shade_rastpos( GLcontext *ctx, 232 233 234 235 227 GLfloat vertex[4], 228 GLfloat normal[3], 229 GLfloat Rcolor[4], 230 GLuint *index ) 236 231 { 237 232 GLfloat (*base)[3] = ctx->Light.BaseColor; … … 254 249 255 250 if (!(light->Flags & LIGHT_POSITIONAL)) { 256 257 251 COPY_3V(VP, light->VP_inf_norm); 252 attenuation = light->VP_inf_spot_attenuation; 258 253 } 259 254 else { 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 255 GLfloat d; 256 257 SUB_3V(VP, light->Position, vertex); 258 d = LEN_3FV( VP ); 259 260 if ( d > 1e-6) { 261 GLfloat invd = 1.0F / d; 262 SELF_SCALE_SCALAR_3V(VP, invd); 263 } 264 attenuation = 1.0F / (light->ConstantAttenuation + d * 265 (light->LinearAttenuation + d * 266 light->QuadraticAttenuation)); 267 268 if (light->Flags & LIGHT_SPOT) 269 { 270 GLfloat PV_dot_dir = - DOT3(VP, light->NormDirection); 271 272 if (PV_dot_dir<light->CosCutoff) { 273 continue; 274 } 275 else 276 { 277 double x = PV_dot_dir * (EXP_TABLE_SIZE-1); 278 int k = (int) x; 279 GLfloat spot = (GLfloat) (light->SpotExpTable[k][0] 280 + (x-k)*light->SpotExpTable[k][1]); 281 attenuation *= spot; 282 } 283 } 289 284 } 290 285 291 286 if (attenuation < 1e-3) 292 287 continue; 293 288 294 289 n_dot_VP = DOT3( normal, VP ); 295 290 296 291 if (n_dot_VP < 0.0F) { 297 298 292 ACC_SCALE_SCALAR_3V(color, attenuation, light->MatAmbient[0]); 293 continue; 299 294 } 300 295 … … 304 299 305 300 if (light->IsMatSpecular[0]) { 306 307 308 309 310 311 312 313 314 315 316 317 318 301 if (ctx->Light.Model.LocalViewer) { 302 GLfloat v[3]; 303 COPY_3V(v, vertex); 304 NORMALIZE_3FV(v); 305 SUB_3V(VP, VP, v); 306 h = VP; 307 normalized = 0; 308 } 309 else if (light->Flags & LIGHT_POSITIONAL) { 310 h = VP; 311 ACC_3V(h, ctx->EyeZDir); 312 normalized = 0; 313 } 319 314 else { 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 315 h = light->h_inf_norm; 316 normalized = 1; 317 } 318 319 n_dot_h = DOT3(normal, h); 320 321 if (n_dot_h > 0.0F) { 322 struct gl_material *mat = &ctx->Light.Material[0]; 323 GLfloat spec_coef; 324 GLfloat shininess = mat->Shininess; 325 326 if (!normalized) { 327 n_dot_h *= n_dot_h; 328 n_dot_h /= LEN_SQUARED_3FV( h ); 329 shininess *= .5; 330 } 331 332 if (n_dot_h>1.0) { 333 spec_coef = (GLfloat) pow( n_dot_h, shininess ); 334 } 340 335 else { 341 342 343 344 345 346 347 348 349 350 336 struct gl_shine_tab *tab = ctx->ShineTable[0]; 337 GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec_coef ); 338 } 339 340 if (spec_coef > 1.0e-10) { 341 ACC_SCALE_SCALAR_3V( contrib, spec_coef, 342 light->MatSpecular[0]); 343 specular += spec_coef * light->sli * attenuation; 344 } 345 } 351 346 } 352 347 … … 368 363 + specular * s_a; 369 364 if (ind > mat->SpecularIndex) { 370 365 ind = mat->SpecularIndex; 371 366 } 372 367 *index = (GLuint) (GLint) ind;
Note:
See TracChangeset
for help on using the changeset viewer.