2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 cvar_t r_lightmodels = {"r_lightmodels", "1"};
30 void r_light_shutdown()
36 Cvar_RegisterVariable(&r_lightmodels);
37 R_RegisterModule("R_Light", r_light_start, r_light_shutdown);
40 int r_dlightframecount;
47 void R_AnimateLight (void)
53 // 'm' is normal light, 'a' is no light, 'z' is double bright
54 i = (int)(cl.time*10);
55 for (j=0 ; j<MAX_LIGHTSTYLES ; j++)
57 if (!cl_lightstyle[j].length)
59 d_lightstylevalue[j] = 256;
62 k = i % cl_lightstyle[j].length;
63 k = cl_lightstyle[j].map[k] - 'a';
65 d_lightstylevalue[j] = k;
70 =============================================================================
74 =============================================================================
82 void R_OldMarkLights (vec3_t lightorigin, dlight_t *light, int bit, int bitindex, mnode_t *node)
89 if (node->contents < 0)
92 dist = PlaneDiff(lightorigin, node->plane);
94 if (dist > light->radius)
96 if (node->children[0]->contents >= 0) // LordHavoc: save some time by not pushing another stack frame
98 node = node->children[0];
103 if (dist < -light->radius)
105 if (node->children[1]->contents >= 0) // LordHavoc: save some time by not pushing another stack frame
107 node = node->children[1];
113 if (node->dlightframe != r_dlightframecount) // not dynamic until now
115 node->dlightbits[0] = node->dlightbits[1] = node->dlightbits[2] = node->dlightbits[3] = node->dlightbits[4] = node->dlightbits[5] = node->dlightbits[6] = node->dlightbits[7] = 0;
116 node->dlightframe = r_dlightframecount;
118 node->dlightbits[bitindex] |= bit;
121 surf = cl.worldmodel->surfaces + node->firstsurface;
122 for (i=0 ; i<node->numsurfaces ; i++, surf++)
124 if (((surf->flags & SURF_PLANEBACK) == 0) == ((PlaneDist(lightorigin, surf->plane)) >= surf->plane->dist))
126 if (surf->dlightframe != r_dlightframecount) // not dynamic until now
128 surf->dlightbits[0] = surf->dlightbits[1] = surf->dlightbits[2] = surf->dlightbits[3] = surf->dlightbits[4] = surf->dlightbits[5] = surf->dlightbits[6] = surf->dlightbits[7] = 0;
129 surf->dlightframe = r_dlightframecount;
131 surf->dlightbits[bitindex] |= bit;
135 if (node->children[0]->contents >= 0)
137 if (node->children[1]->contents >= 0)
139 R_OldMarkLights (lightorigin, light, bit, bitindex, node->children[0]);
140 node = node->children[1];
145 node = node->children[0];
149 else if (node->children[1]->contents >= 0)
151 node = node->children[1];
156 void R_NoVisMarkLights (vec3_t lightorigin, dlight_t *light, int bit, int bitindex, model_t *model)
158 R_OldMarkLights(lightorigin, light, bit, bitindex, model->nodes + model->hulls[0].firstclipnode);
162 void R_VisMarkLights (vec3_t lightorigin, dlight_t *light, int bit, int bitindex, model_t *model)
164 mleaf_t *pvsleaf = Mod_PointInLeaf (lightorigin, model);
166 if (!pvsleaf->compressed_vis)
167 { // no vis info, so make all visible
168 R_OldMarkLights(lightorigin, light, bit, bitindex, model->nodes + model->hulls[0].firstclipnode);
174 msurface_t *surf, **mark;
176 byte *in = pvsleaf->compressed_vis;
177 int row = (model->numleafs+7)>>3;
178 float low[3], high[3], radius;
180 radius = light->radius * 4.0f;
181 low[0] = lightorigin[0] - radius;low[1] = lightorigin[1] - radius;low[2] = lightorigin[2] - radius;
182 high[0] = lightorigin[0] + radius;high[1] = lightorigin[1] + radius;high[2] = lightorigin[2] + radius;
191 l = model->numleafs - (k << 3);
194 for (i=0 ; i<l ; i++)
198 leaf = &model->leafs[(k << 3)+i+1];
199 leaf->lightframe = lightframe;
200 if (leaf->visframe != r_visframecount)
202 if (leaf->contents == CONTENTS_SOLID)
204 // if out of the light radius, skip
206 if (leaf->minmaxs[0] > high[0] || leaf->minmaxs[3] < low[0]
207 || leaf->minmaxs[1] > high[1] || leaf->minmaxs[4] < low[1]
208 || leaf->minmaxs[2] > high[2] || leaf->minmaxs[5] < low[2])
211 if (leaf->dlightframe != r_dlightframecount) // not dynamic until now
213 leaf->dlightbits[0] = leaf->dlightbits[1] = leaf->dlightbits[2] = leaf->dlightbits[3] = leaf->dlightbits[4] = leaf->dlightbits[5] = leaf->dlightbits[6] = leaf->dlightbits[7] = 0;
214 leaf->dlightframe = r_dlightframecount;
216 leaf->dlightbits[bitindex] |= bit;
217 if ((m = leaf->nummarksurfaces))
219 mark = leaf->firstmarksurface;
223 if (surf->visframe != r_framecount || surf->lightframe == lightframe)
225 surf->lightframe = lightframe;
226 if (((surf->flags & SURF_PLANEBACK) == 0) == ((PlaneDist(lightorigin, surf->plane)) >= surf->plane->dist))
228 if (surf->dlightframe != r_dlightframecount) // not dynamic until now
230 surf->dlightbits[0] = surf->dlightbits[1] = surf->dlightbits[2] = surf->dlightbits[3] = surf->dlightbits[4] = surf->dlightbits[5] = surf->dlightbits[6] = surf->dlightbits[7] = 0;
231 surf->dlightframe = r_dlightframecount;
233 surf->dlightbits[bitindex] |= bit;
255 void R_PushDlights (void)
260 r_dlightframecount = r_framecount + 1; // because the count hasn't advanced yet for this frame
262 if (!r_dynamic.value)
267 for (i=0 ; i<MAX_DLIGHTS ; i++, l++)
269 if (l->die < cl.time || !l->radius)
271 // R_MarkLights (l->origin, l, 1<<(i&31), i >> 5, cl.worldmodel->nodes );
272 R_VisMarkLights (l->origin, l, 1<<(i&31), i >> 5, cl.worldmodel);
278 =============================================================================
282 =============================================================================
285 mplane_t *lightplane;
288 extern cvar_t r_ambient;
291 int RecursiveLightPoint (vec3_t color, mnode_t *node, vec3_t start, vec3_t end)
293 float front, back, frac;
297 if (node->contents < 0)
298 return false; // didn't hit anything
300 // calculate mid point
301 front = PlaneDiff (start, node->plane);
302 back = PlaneDiff (end, node->plane);
304 // LordHavoc: optimized recursion
305 if ((back < 0) == (front < 0))
306 // return RecursiveLightPoint (color, node->children[front < 0], start, end);
308 node = node->children[front < 0];
312 frac = front / (front-back);
313 mid[0] = start[0] + (end[0] - start[0])*frac;
314 mid[1] = start[1] + (end[1] - start[1])*frac;
315 mid[2] = start[2] + (end[2] - start[2])*frac;
317 // go down front side
318 if (RecursiveLightPoint (color, node->children[front < 0], start, mid))
319 return true; // hit something
324 // check for impact on this node
325 VectorCopy (mid, lightspot);
326 lightplane = node->plane;
328 surf = cl.worldmodel->surfaces + node->firstsurface;
329 for (i = 0;i < node->numsurfaces;i++, surf++)
331 if (surf->flags & SURF_DRAWTILED)
332 continue; // no lightmaps
334 ds = (int) ((float) DotProduct (mid, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3]);
335 dt = (int) ((float) DotProduct (mid, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3]);
337 if (ds < surf->texturemins[0] || dt < surf->texturemins[1])
340 ds -= surf->texturemins[0];
341 dt -= surf->texturemins[1];
343 if (ds > surf->extents[0] || dt > surf->extents[1])
349 int maps, line3, dsfrac = ds & 15, dtfrac = dt & 15, r00 = 0, g00 = 0, b00 = 0, r01 = 0, g01 = 0, b01 = 0, r10 = 0, g10 = 0, b10 = 0, r11 = 0, g11 = 0, b11 = 0;
351 line3 = ((surf->extents[0]>>4)+1)*3;
353 lightmap = surf->samples + ((dt>>4) * ((surf->extents[0]>>4)+1) + (ds>>4))*3; // LordHavoc: *3 for color
355 for (maps = 0;maps < MAXLIGHTMAPS && surf->styles[maps] != 255;maps++)
357 scale = (float) d_lightstylevalue[surf->styles[maps]] * 1.0 / 256.0;
358 r00 += (float) lightmap[ 0] * scale;g00 += (float) lightmap[ 1] * scale;b00 += (float) lightmap[2] * scale;
359 r01 += (float) lightmap[ 3] * scale;g01 += (float) lightmap[ 4] * scale;b01 += (float) lightmap[5] * scale;
360 r10 += (float) lightmap[line3+0] * scale;g10 += (float) lightmap[line3+1] * scale;b10 += (float) lightmap[line3+2] * scale;
361 r11 += (float) lightmap[line3+3] * scale;g11 += (float) lightmap[line3+4] * scale;b11 += (float) lightmap[line3+5] * scale;
362 lightmap += ((surf->extents[0]>>4)+1) * ((surf->extents[1]>>4)+1)*3; // LordHavoc: *3 for colored lighting
365 color[0] += (float) ((int) ((((((((r11-r10) * dsfrac) >> 4) + r10)-((((r01-r00) * dsfrac) >> 4) + r00)) * dtfrac) >> 4) + ((((r01-r00) * dsfrac) >> 4) + r00)));
366 color[1] += (float) ((int) ((((((((g11-g10) * dsfrac) >> 4) + g10)-((((g01-g00) * dsfrac) >> 4) + g00)) * dtfrac) >> 4) + ((((g01-g00) * dsfrac) >> 4) + g00)));
367 color[2] += (float) ((int) ((((((((b11-b10) * dsfrac) >> 4) + b10)-((((b01-b00) * dsfrac) >> 4) + b00)) * dtfrac) >> 4) + ((((b01-b00) * dsfrac) >> 4) + b00)));
369 return true; // success
373 return RecursiveLightPoint (color, node->children[front >= 0], mid, end);
377 void R_LightPoint (vec3_t color, vec3_t p)
381 if (r_fullbright.value || !cl.worldmodel->lightdata)
383 color[0] = color[1] = color[2] = 255;
389 end[2] = p[2] - 2048;
391 color[0] = color[1] = color[2] = r_ambient.value * 2.0f;
392 RecursiveLightPoint (color, cl.worldmodel->nodes, p, end);
395 void SV_LightPoint (vec3_t color, vec3_t p)
399 if (!sv.worldmodel->lightdata)
401 color[0] = color[1] = color[2] = 255;
407 end[2] = p[2] - 2048;
409 color[0] = color[1] = color[2] = 0;
410 RecursiveLightPoint (color, sv.worldmodel->nodes, p, end);
414 int RecursiveLightPoint (vec3_t color, mnode_t *node, float x, float y, float startz, float endz)
416 int side, distz = endz - startz;
421 if (node->contents < 0)
422 return false; // didn't hit anything
424 switch (node->plane->type)
427 node = node->children[x < node->plane->dist];
430 node = node->children[y < node->plane->dist];
433 side = startz < node->plane->dist;
434 if ((endz < node->plane->dist) == side)
436 node = node->children[side];
439 // found an intersection
440 // mid = startz + (endz - startz) * (startz - node->plane->dist) / (startz - endz);
441 // mid = startz + distz * (startz - node->plane->dist) / (-distz);
442 // mid = startz + (-(startz - node->plane->dist));
443 // mid = startz - (startz - node->plane->dist);
444 // mid = startz + node->plane->dist - startz;
445 mid = node->plane->dist;
448 back = front = x * node->plane->normal[0] + y * node->plane->normal[1];
449 front += startz * node->plane->normal[2];
450 back += endz * node->plane->normal[2];
451 side = front < node->plane->dist;
452 if ((back < node->plane->dist) == side)
454 node = node->children[side];
457 // found an intersection
458 // mid = startz + (endz - startz) * ((front - node->plane->dist) / ((front - node->plane->dist) - (back - node->plane->dist)));
459 // mid = startz + (endz - startz) * ((front - node->plane->dist) / (front - back));
460 mid = startz + distz * (front - node->plane->dist) / (front - back);
464 // go down front side
465 if (node->children[side]->contents >= 0 && RecursiveLightPoint (color, node->children[side], x, y, startz, mid))
466 return true; // hit something
469 // check for impact on this node
470 if (node->numsurfaces)
477 lightplane = node->plane;
479 surf = cl.worldmodel->surfaces + node->firstsurface;
480 for (i = 0;i < node->numsurfaces;i++, surf++)
482 if (surf->flags & SURF_DRAWTILED)
483 continue; // no lightmaps
485 ds = (int) (x * surf->texinfo->vecs[0][0] + y * surf->texinfo->vecs[0][1] + mid * surf->texinfo->vecs[0][2] + surf->texinfo->vecs[0][3]);
486 dt = (int) (x * surf->texinfo->vecs[1][0] + y * surf->texinfo->vecs[1][1] + mid * surf->texinfo->vecs[1][2] + surf->texinfo->vecs[1][3]);
488 if (ds < surf->texturemins[0] || dt < surf->texturemins[1])
491 ds -= surf->texturemins[0];
492 dt -= surf->texturemins[1];
494 if (ds > surf->extents[0] || dt > surf->extents[1])
500 int maps, line3, size3, dsfrac = ds & 15, dtfrac = dt & 15, scale = 0, r00 = 0, g00 = 0, b00 = 0, r01 = 0, g01 = 0, b01 = 0, r10 = 0, g10 = 0, b10 = 0, r11 = 0, g11 = 0, b11 = 0;
501 line3 = ((surf->extents[0]>>4)+1)*3;
502 size3 = ((surf->extents[0]>>4)+1) * ((surf->extents[1]>>4)+1)*3; // LordHavoc: *3 for colored lighting
504 lightmap = surf->samples + ((dt>>4) * ((surf->extents[0]>>4)+1) + (ds>>4))*3; // LordHavoc: *3 for color
506 for (maps = 0;maps < MAXLIGHTMAPS && surf->styles[maps] != 255;maps++)
508 scale = d_lightstylevalue[surf->styles[maps]];
509 r00 += lightmap[ 0] * scale;g00 += lightmap[ 1] * scale;b00 += lightmap[ 2] * scale;
510 r01 += lightmap[ 3] * scale;g01 += lightmap[ 4] * scale;b01 += lightmap[ 5] * scale;
511 r10 += lightmap[line3+0] * scale;g10 += lightmap[line3+1] * scale;b10 += lightmap[line3+2] * scale;
512 r11 += lightmap[line3+3] * scale;g11 += lightmap[line3+4] * scale;b11 += lightmap[line3+5] * scale;
516 color[0] += (float) ((((((((r11-r10) * dsfrac) >> 4) + r10)-((((r01-r00) * dsfrac) >> 4) + r00)) * dtfrac) >> 4) + ((((r01-r00) * dsfrac) >> 4) + r00)) * (1.0f / 256.0f);
517 color[1] += (float) ((((((((g11-g10) * dsfrac) >> 4) + g10)-((((g01-g00) * dsfrac) >> 4) + g00)) * dtfrac) >> 4) + ((((g01-g00) * dsfrac) >> 4) + g00)) * (1.0f / 256.0f);
518 color[2] += (float) ((((((((b11-b10) * dsfrac) >> 4) + b10)-((((b01-b00) * dsfrac) >> 4) + b00)) * dtfrac) >> 4) + ((((b01-b00) * dsfrac) >> 4) + b00)) * (1.0f / 256.0f);
520 return true; // success
525 node = node->children[side ^ 1];
527 distz = endz - startz;
529 // return RecursiveLightPoint (color, node->children[side ^ 1], x, y, mid, endz);
533 void R_LightPoint (vec3_t color, vec3_t p)
535 if (r_fullbright.value || !cl.worldmodel->lightdata)
537 color[0] = color[1] = color[2] = 255;
541 color[0] = color[1] = color[2] = r_ambient.value * 2.0f;
542 RecursiveLightPoint (color, cl.worldmodel->nodes, p[0], p[1], p[2], p[2] - 65536);
545 // LordHavoc: added light checking to the server
546 void SV_LightPoint (vec3_t color, vec3_t p)
548 if (!sv.worldmodel->lightdata)
550 color[0] = color[1] = color[2] = 255;
554 color[0] = color[1] = color[2] = 0;
555 RecursiveLightPoint (color, sv.worldmodel->nodes, p[0], p[1], p[2], p[2] - 65536);
558 // LordHavoc: R_DynamicLightPoint - acumulates the dynamic lighting
559 void R_DynamicLightPoint(vec3_t color, vec3_t org, int *dlightbits)
563 float brightness, r, f;
565 if (!r_dynamic.value || (!dlightbits[0] && !dlightbits[1] && !dlightbits[2] && !dlightbits[3] && !dlightbits[4] && !dlightbits[5] && !dlightbits[6] && !dlightbits[7]))
568 for (j = 0;j < (MAX_DLIGHTS >> 5);j++)
572 for (i=0 ; i<32 ; i++)
574 if ((!((1 << (i&31)) & dlightbits[i>>5])) || cl_dlights[i].die < cl.time || !cl_dlights[i].radius)
577 VectorSubtract (org, cl_dlights[k].origin, dist);
578 f = DotProduct(dist, dist) + LIGHTOFFSET;
579 r = cl_dlights[k].radius*cl_dlights[k].radius*LIGHTSCALE;
582 brightness = r * 16.0f / f;
583 color[0] += brightness * cl_dlights[k].color[0];
584 color[1] += brightness * cl_dlights[k].color[1];
585 color[2] += brightness * cl_dlights[k].color[2];
592 // same as above but no bitmask to check
593 void R_DynamicLightPointNoMask(vec3_t color, vec3_t org)
597 float brightness, r, f;
599 if (!r_dynamic.value)
602 for (i=0 ; i<MAX_DLIGHTS ; i++)
604 if (cl_dlights[i].die < cl.time || !cl_dlights[i].radius)
606 VectorSubtract (org, cl_dlights[i].origin, dist);
607 f = DotProduct(dist, dist) + LIGHTOFFSET;
608 r = cl_dlights[i].radius*cl_dlights[i].radius*LIGHTSCALE;
611 brightness = r * 16.0f / f;
612 if (cl_dlights[i].dark)
613 brightness = -brightness;
614 color[0] += brightness * cl_dlights[i].color[0];
615 color[1] += brightness * cl_dlights[i].color[1];
616 color[2] += brightness * cl_dlights[i].color[2];
621 void R_CompleteLightPoint (vec3_t color, vec3_t p)
623 R_LightPoint(color, p);
624 R_DynamicLightPointNoMask(color, p);
627 extern float *aliasvert;
628 extern float *aliasvertnorm;
629 extern byte *aliasvertcolor;
630 extern float modelalpha;
631 extern int modeldlightbits[8];
632 void R_LightModel(int numverts, vec3_t center, vec3_t basecolor)
634 // LordHavoc: warning: reliance on int being 4 bytes here (of course the d_8to24table relies on that too...)
635 int i, j, nearlights = 0, color;
637 float t, t1, t2, t3, *avn;
643 } nearlight[MAX_DLIGHTS];
644 avc = aliasvertcolor;
646 a = (byte) bound((int) 0, (int) (modelalpha * 255.0f), (int) 255);
647 if (currententity->effects & EF_FULLBRIGHT)
651 ((byte *)&color)[0] = (byte) ((float) (128.0f * currententity->colormod[0]));
652 ((byte *)&color)[1] = (byte) ((float) (128.0f * currententity->colormod[1]));
653 ((byte *)&color)[2] = (byte) ((float) (128.0f * currententity->colormod[2]));
657 ((byte *)&color)[0] = (byte) ((float) (255.0f * currententity->colormod[0]));
658 ((byte *)&color)[1] = (byte) ((float) (255.0f * currententity->colormod[1]));
659 ((byte *)&color)[2] = (byte) ((float) (255.0f * currententity->colormod[2]));
661 ((byte *)&color)[3] = a;
662 for (i = 0;i < numverts;i++)
664 *((int *)avc) = color;
671 mod[0] = currententity->colormod[0] * 0.5f;
672 mod[1] = currententity->colormod[1] * 0.5f;
673 mod[2] = currententity->colormod[2] * 0.5f;
677 mod[0] = currententity->colormod[0];
678 mod[1] = currententity->colormod[1];
679 mod[2] = currententity->colormod[2];
681 basecolor[0] *= mod[0];
682 basecolor[1] *= mod[1];
683 basecolor[2] *= mod[2];
684 if (r_lightmodels.value)
686 for (i = 0;i < MAX_DLIGHTS;i++)
688 if (!modeldlightbits[i >> 5])
693 if (!(modeldlightbits[i >> 5] & (1 << (i & 31))))
695 VectorSubtract (center, cl_dlights[i].origin, dist);
696 t1 = cl_dlights[i].radius*cl_dlights[i].radius*LIGHTSCALE;
697 t2 = DotProduct(dist,dist) + LIGHTOFFSET;
700 VectorCopy(cl_dlights[i].origin, nearlight[nearlights].origin);
701 nearlight[nearlights].color[0] = cl_dlights[i].color[0] * cl_dlights[i].radius * cl_dlights[i].radius * mod[0];
702 nearlight[nearlights].color[1] = cl_dlights[i].color[1] * cl_dlights[i].radius * cl_dlights[i].radius * mod[1];
703 nearlight[nearlights].color[2] = cl_dlights[i].color[2] * cl_dlights[i].radius * cl_dlights[i].radius * mod[2];
704 t1 = (128.0f / LIGHTSCALE) / t2;
705 basecolor[0] += nearlight[nearlights].color[0] * t1;
706 basecolor[1] += nearlight[nearlights].color[1] * t1;
707 basecolor[2] += nearlight[nearlights].color[2] * t1;
714 for (i = 0;i < MAX_DLIGHTS;i++)
716 if (!modeldlightbits[i >> 5])
721 if (!(modeldlightbits[i >> 5] & (1 << (i & 31))))
723 VectorSubtract (center, cl_dlights[i].origin, dist);
724 t1 = cl_dlights[i].radius*cl_dlights[i].radius*LIGHTSCALE;
725 t2 = DotProduct(dist,dist) + LIGHTOFFSET;
728 dist[0] = cl_dlights[i].color[0] * cl_dlights[i].radius * cl_dlights[i].radius * mod[0];
729 dist[1] = cl_dlights[i].color[1] * cl_dlights[i].radius * cl_dlights[i].radius * mod[1];
730 dist[2] = cl_dlights[i].color[2] * cl_dlights[i].radius * cl_dlights[i].radius * mod[2];
731 t1 = (192.0f / LIGHTSCALE) / t2;
732 basecolor[0] += dist[0] * t1;
733 basecolor[1] += dist[1] * t1;
734 basecolor[2] += dist[2] * t1;
738 t1 = bound(0, basecolor[0], 255);r = (byte) t1;
739 t1 = bound(0, basecolor[1], 255);g = (byte) t1;
740 t1 = bound(0, basecolor[2], 255);b = (byte) t1;
741 ((byte *)&color)[0] = r;
742 ((byte *)&color)[1] = g;
743 ((byte *)&color)[2] = b;
744 ((byte *)&color)[3] = a;
753 for (i = 0;i < numverts;i++)
755 VectorSubtract(nearlight[0].origin, av, v);
756 t = DotProduct(avn,v);
759 t /= DotProduct(v,v);
760 temp = (int) ((float) (basecolor[0] + nearlight[0].color[0] * t));if (temp < 0) temp = 0;else if (temp > 255) temp = 255;avc[0] = temp;
761 temp = (int) ((float) (basecolor[1] + nearlight[0].color[1] * t));if (temp < 0) temp = 0;else if (temp > 255) temp = 255;avc[1] = temp;
762 temp = (int) ((float) (basecolor[2] + nearlight[0].color[2] * t));if (temp < 0) temp = 0;else if (temp > 255) temp = 255;avc[2] = temp;
766 *((int *)avc) = color;
775 for (i = 0;i < numverts;i++)
781 for (j = 0;j < nearlights;j++)
783 VectorSubtract(nearlight[j].origin, av, v);
784 t = DotProduct(avn,v);
787 t /= DotProduct(v,v);
788 t1 += nearlight[j].color[0] * t;
789 t2 += nearlight[j].color[1] * t;
790 t3 += nearlight[j].color[2] * t;
794 if (k) // dodge the costly float -> int conversions
796 i1 = t1;if (i1 < 0) i1 = 0;else if (i1 > 255) i1 = 255;avc[0] = i1;
797 i2 = t2;if (i2 < 0) i2 = 0;else if (i2 > 255) i2 = 255;avc[1] = i2;
798 i3 = t3;if (i3 < 0) i3 = 0;else if (i3 > 255) i3 = 255;avc[2] = i3;
802 *((int *)avc) = color;
809 for (i = 0;i < numverts;i++)
811 *((int *)avc) = color;