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->dlightframe != r_dlightframecount) // not dynamic until now
126 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;
127 surf->dlightframe = r_dlightframecount;
129 surf->dlightbits[bitindex] |= bit;
132 if (node->children[0]->contents >= 0)
134 if (node->children[1]->contents >= 0)
136 R_OldMarkLights (lightorigin, light, bit, bitindex, node->children[0]);
137 node = node->children[1];
142 node = node->children[0];
146 else if (node->children[1]->contents >= 0)
148 node = node->children[1];
153 void R_NoVisMarkLights (vec3_t lightorigin, dlight_t *light, int bit, int bitindex, model_t *model)
155 R_OldMarkLights(lightorigin, light, bit, bitindex, model->nodes + model->hulls[0].firstclipnode);
159 void R_VisMarkLights (vec3_t lightorigin, dlight_t *light, int bit, int bitindex, model_t *model)
161 mleaf_t *pvsleaf = Mod_PointInLeaf (lightorigin, model);
163 if (!pvsleaf->compressed_vis)
164 { // no vis info, so make all visible
165 R_OldMarkLights(lightorigin, light, bit, bitindex, model->nodes + model->hulls[0].firstclipnode);
171 msurface_t *surf, **mark;
173 byte *in = pvsleaf->compressed_vis;
174 int row = (model->numleafs+7)>>3;
175 float low[3], high[3], radius;
177 radius = light->radius * 4.0f;
178 low[0] = lightorigin[0] - radius;low[1] = lightorigin[1] - radius;low[2] = lightorigin[2] - radius;
179 high[0] = lightorigin[0] + radius;high[1] = lightorigin[1] + radius;high[2] = lightorigin[2] + radius;
188 l = model->numleafs - (k << 3);
191 for (i=0 ; i<l ; i++)
195 leaf = &model->leafs[(k << 3)+i+1];
196 leaf->lightframe = lightframe;
197 if (leaf->visframe != r_visframecount)
199 if (leaf->contents == CONTENTS_SOLID)
201 // if out of the light radius, skip
203 if (leaf->minmaxs[0] > high[0] || leaf->minmaxs[3] < low[0]
204 || leaf->minmaxs[1] > high[1] || leaf->minmaxs[4] < low[1]
205 || leaf->minmaxs[2] > high[2] || leaf->minmaxs[5] < low[2])
208 if (leaf->dlightframe != r_dlightframecount) // not dynamic until now
210 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;
211 leaf->dlightframe = r_dlightframecount;
213 leaf->dlightbits[bitindex] |= bit;
214 if ((m = leaf->nummarksurfaces))
216 mark = leaf->firstmarksurface;
220 if (surf->visframe != r_framecount || surf->lightframe == lightframe)
222 surf->lightframe = lightframe;
223 //if (((surf->flags & SURF_PLANEBACK) == 0) == ((PlaneDiff(lightorigin, surf->plane)) >= 0))
225 if (surf->dlightframe != r_dlightframecount) // not dynamic until now
227 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;
228 surf->dlightframe = r_dlightframecount;
230 surf->dlightbits[bitindex] |= bit;
252 void R_PushDlights (void)
257 r_dlightframecount = r_framecount + 1; // because the count hasn't advanced yet for this frame
259 if (!r_dynamic.value)
264 for (i=0 ; i<MAX_DLIGHTS ; i++, l++)
266 if (l->die < cl.time || !l->radius)
268 // R_MarkLights (l->origin, l, 1<<(i&31), i >> 5, cl.worldmodel->nodes );
269 R_VisMarkLights (l->origin, l, 1<<(i&31), i >> 5, cl.worldmodel);
275 =============================================================================
279 =============================================================================
282 mplane_t *lightplane;
285 extern cvar_t r_ambient;
288 int RecursiveLightPoint (vec3_t color, mnode_t *node, vec3_t start, vec3_t end)
290 float front, back, frac;
294 if (node->contents < 0)
295 return false; // didn't hit anything
297 // calculate mid point
298 front = PlaneDiff (start, node->plane);
299 back = PlaneDiff (end, node->plane);
301 // LordHavoc: optimized recursion
302 if ((back < 0) == (front < 0))
303 // return RecursiveLightPoint (color, node->children[front < 0], start, end);
305 node = node->children[front < 0];
309 frac = front / (front-back);
310 mid[0] = start[0] + (end[0] - start[0])*frac;
311 mid[1] = start[1] + (end[1] - start[1])*frac;
312 mid[2] = start[2] + (end[2] - start[2])*frac;
314 // go down front side
315 if (RecursiveLightPoint (color, node->children[front < 0], start, mid))
316 return true; // hit something
321 // check for impact on this node
322 VectorCopy (mid, lightspot);
323 lightplane = node->plane;
325 surf = cl.worldmodel->surfaces + node->firstsurface;
326 for (i = 0;i < node->numsurfaces;i++, surf++)
328 if (surf->flags & SURF_DRAWTILED)
329 continue; // no lightmaps
331 ds = (int) ((float) DotProduct (mid, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3]);
332 dt = (int) ((float) DotProduct (mid, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3]);
334 if (ds < surf->texturemins[0] || dt < surf->texturemins[1])
337 ds -= surf->texturemins[0];
338 dt -= surf->texturemins[1];
340 if (ds > surf->extents[0] || dt > surf->extents[1])
346 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;
348 line3 = ((surf->extents[0]>>4)+1)*3;
350 lightmap = surf->samples + ((dt>>4) * ((surf->extents[0]>>4)+1) + (ds>>4))*3; // LordHavoc: *3 for color
352 for (maps = 0;maps < MAXLIGHTMAPS && surf->styles[maps] != 255;maps++)
354 scale = (float) d_lightstylevalue[surf->styles[maps]] * 1.0 / 256.0;
355 r00 += (float) lightmap[ 0] * scale;g00 += (float) lightmap[ 1] * scale;b00 += (float) lightmap[2] * scale;
356 r01 += (float) lightmap[ 3] * scale;g01 += (float) lightmap[ 4] * scale;b01 += (float) lightmap[5] * scale;
357 r10 += (float) lightmap[line3+0] * scale;g10 += (float) lightmap[line3+1] * scale;b10 += (float) lightmap[line3+2] * scale;
358 r11 += (float) lightmap[line3+3] * scale;g11 += (float) lightmap[line3+4] * scale;b11 += (float) lightmap[line3+5] * scale;
359 lightmap += ((surf->extents[0]>>4)+1) * ((surf->extents[1]>>4)+1)*3; // LordHavoc: *3 for colored lighting
362 color[0] += (float) ((int) ((((((((r11-r10) * dsfrac) >> 4) + r10)-((((r01-r00) * dsfrac) >> 4) + r00)) * dtfrac) >> 4) + ((((r01-r00) * dsfrac) >> 4) + r00)));
363 color[1] += (float) ((int) ((((((((g11-g10) * dsfrac) >> 4) + g10)-((((g01-g00) * dsfrac) >> 4) + g00)) * dtfrac) >> 4) + ((((g01-g00) * dsfrac) >> 4) + g00)));
364 color[2] += (float) ((int) ((((((((b11-b10) * dsfrac) >> 4) + b10)-((((b01-b00) * dsfrac) >> 4) + b00)) * dtfrac) >> 4) + ((((b01-b00) * dsfrac) >> 4) + b00)));
366 return true; // success
370 return RecursiveLightPoint (color, node->children[front >= 0], mid, end);
374 void R_LightPoint (vec3_t color, vec3_t p)
378 if (r_fullbright.value || !cl.worldmodel->lightdata)
380 color[0] = color[1] = color[2] = 255;
386 end[2] = p[2] - 2048;
388 color[0] = color[1] = color[2] = r_ambient.value * 2.0f;
389 RecursiveLightPoint (color, cl.worldmodel->nodes, p, end);
392 void SV_LightPoint (vec3_t color, vec3_t p)
396 if (!sv.worldmodel->lightdata)
398 color[0] = color[1] = color[2] = 255;
404 end[2] = p[2] - 2048;
406 color[0] = color[1] = color[2] = 0;
407 RecursiveLightPoint (color, sv.worldmodel->nodes, p, end);
411 int RecursiveLightPoint (vec3_t color, mnode_t *node, float x, float y, float startz, float endz)
413 int side, distz = endz - startz;
418 if (node->contents < 0)
419 return false; // didn't hit anything
421 switch (node->plane->type)
424 node = node->children[x < node->plane->dist];
427 node = node->children[y < node->plane->dist];
430 side = startz < node->plane->dist;
431 if ((endz < node->plane->dist) == side)
433 node = node->children[side];
436 // found an intersection
437 // mid = startz + (endz - startz) * (startz - node->plane->dist) / (startz - endz);
438 // mid = startz + distz * (startz - node->plane->dist) / (-distz);
439 // mid = startz + (-(startz - node->plane->dist));
440 // mid = startz - (startz - node->plane->dist);
441 // mid = startz + node->plane->dist - startz;
442 mid = node->plane->dist;
445 back = front = x * node->plane->normal[0] + y * node->plane->normal[1];
446 front += startz * node->plane->normal[2];
447 back += endz * node->plane->normal[2];
448 side = front < node->plane->dist;
449 if ((back < node->plane->dist) == side)
451 node = node->children[side];
454 // found an intersection
455 // mid = startz + (endz - startz) * ((front - node->plane->dist) / ((front - node->plane->dist) - (back - node->plane->dist)));
456 // mid = startz + (endz - startz) * ((front - node->plane->dist) / (front - back));
457 mid = startz + distz * (front - node->plane->dist) / (front - back);
461 // go down front side
462 if (node->children[side]->contents >= 0 && RecursiveLightPoint (color, node->children[side], x, y, startz, mid))
463 return true; // hit something
466 // check for impact on this node
467 if (node->numsurfaces)
474 lightplane = node->plane;
476 surf = cl.worldmodel->surfaces + node->firstsurface;
477 for (i = 0;i < node->numsurfaces;i++, surf++)
479 if (surf->flags & SURF_DRAWTILED)
480 continue; // no lightmaps
482 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]);
483 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]);
485 if (ds < surf->texturemins[0] || dt < surf->texturemins[1])
488 ds -= surf->texturemins[0];
489 dt -= surf->texturemins[1];
491 if (ds > surf->extents[0] || dt > surf->extents[1])
497 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;
498 line3 = ((surf->extents[0]>>4)+1)*3;
499 size3 = ((surf->extents[0]>>4)+1) * ((surf->extents[1]>>4)+1)*3; // LordHavoc: *3 for colored lighting
501 lightmap = surf->samples + ((dt>>4) * ((surf->extents[0]>>4)+1) + (ds>>4))*3; // LordHavoc: *3 for color
503 for (maps = 0;maps < MAXLIGHTMAPS && surf->styles[maps] != 255;maps++)
505 scale = d_lightstylevalue[surf->styles[maps]];
506 r00 += lightmap[ 0] * scale;g00 += lightmap[ 1] * scale;b00 += lightmap[ 2] * scale;
507 r01 += lightmap[ 3] * scale;g01 += lightmap[ 4] * scale;b01 += lightmap[ 5] * scale;
508 r10 += lightmap[line3+0] * scale;g10 += lightmap[line3+1] * scale;b10 += lightmap[line3+2] * scale;
509 r11 += lightmap[line3+3] * scale;g11 += lightmap[line3+4] * scale;b11 += lightmap[line3+5] * scale;
513 color[0] += (float) ((((((((r11-r10) * dsfrac) >> 4) + r10)-((((r01-r00) * dsfrac) >> 4) + r00)) * dtfrac) >> 4) + ((((r01-r00) * dsfrac) >> 4) + r00)) * (1.0f / 256.0f);
514 color[1] += (float) ((((((((g11-g10) * dsfrac) >> 4) + g10)-((((g01-g00) * dsfrac) >> 4) + g00)) * dtfrac) >> 4) + ((((g01-g00) * dsfrac) >> 4) + g00)) * (1.0f / 256.0f);
515 color[2] += (float) ((((((((b11-b10) * dsfrac) >> 4) + b10)-((((b01-b00) * dsfrac) >> 4) + b00)) * dtfrac) >> 4) + ((((b01-b00) * dsfrac) >> 4) + b00)) * (1.0f / 256.0f);
517 return true; // success
522 node = node->children[side ^ 1];
524 distz = endz - startz;
526 // return RecursiveLightPoint (color, node->children[side ^ 1], x, y, mid, endz);
530 void R_LightPoint (vec3_t color, vec3_t p)
532 if (r_fullbright.value || !cl.worldmodel->lightdata)
534 color[0] = color[1] = color[2] = 255;
538 color[0] = color[1] = color[2] = r_ambient.value * 2.0f;
539 RecursiveLightPoint (color, cl.worldmodel->nodes, p[0], p[1], p[2], p[2] - 65536);
542 // LordHavoc: added light checking to the server
543 void SV_LightPoint (vec3_t color, vec3_t p)
545 if (!sv.worldmodel->lightdata)
547 color[0] = color[1] = color[2] = 255;
551 color[0] = color[1] = color[2] = 0;
552 RecursiveLightPoint (color, sv.worldmodel->nodes, p[0], p[1], p[2], p[2] - 65536);
555 // LordHavoc: R_DynamicLightPoint - acumulates the dynamic lighting
556 void R_DynamicLightPoint(vec3_t color, vec3_t org, int *dlightbits)
560 float brightness, r, f;
562 if (!r_dynamic.value || (!dlightbits[0] && !dlightbits[1] && !dlightbits[2] && !dlightbits[3] && !dlightbits[4] && !dlightbits[5] && !dlightbits[6] && !dlightbits[7]))
565 for (j = 0;j < (MAX_DLIGHTS >> 5);j++)
569 for (i=0 ; i<32 ; i++)
571 if ((!((1 << (i&31)) & dlightbits[i>>5])) || cl_dlights[i].die < cl.time || !cl_dlights[i].radius)
574 VectorSubtract (org, cl_dlights[k].origin, dist);
575 f = DotProduct(dist, dist) + LIGHTOFFSET;
576 r = cl_dlights[k].radius*cl_dlights[k].radius*LIGHTSCALE;
579 brightness = r * 16.0f / f;
580 color[0] += brightness * cl_dlights[k].color[0];
581 color[1] += brightness * cl_dlights[k].color[1];
582 color[2] += brightness * cl_dlights[k].color[2];
589 // same as above but no bitmask to check
590 void R_DynamicLightPointNoMask(vec3_t color, vec3_t org)
594 float brightness, r, f;
596 if (!r_dynamic.value)
599 for (i=0 ; i<MAX_DLIGHTS ; i++)
601 if (cl_dlights[i].die < cl.time || !cl_dlights[i].radius)
603 VectorSubtract (org, cl_dlights[i].origin, dist);
604 f = DotProduct(dist, dist) + LIGHTOFFSET;
605 r = cl_dlights[i].radius*cl_dlights[i].radius*LIGHTSCALE;
608 brightness = r * 16.0f / f;
609 if (cl_dlights[i].dark)
610 brightness = -brightness;
611 color[0] += brightness * cl_dlights[i].color[0];
612 color[1] += brightness * cl_dlights[i].color[1];
613 color[2] += brightness * cl_dlights[i].color[2];
618 void R_CompleteLightPoint (vec3_t color, vec3_t p)
620 R_LightPoint(color, p);
621 R_DynamicLightPointNoMask(color, p);
624 extern float *aliasvert;
625 extern float *aliasvertnorm;
626 extern byte *aliasvertcolor;
627 extern float modelalpha;
628 extern qboolean lighthalf;
629 extern int modeldlightbits[8];
630 void R_LightModel(int numverts, vec3_t center, vec3_t basecolor)
632 // LordHavoc: warning: reliance on int being 4 bytes here (of course the d_8to24table relies on that too...)
633 int i, j, nearlights = 0, color;
635 float t, t1, t2, t3, *avn;
641 } nearlight[MAX_DLIGHTS];
642 avc = aliasvertcolor;
644 a = (byte) bound((int) 0, (int) (modelalpha * 255.0f), (int) 255);
645 if (currententity->effects & EF_FULLBRIGHT)
649 ((byte *)&color)[0] = (byte) ((float) (128.0f * currententity->colormod[0]));
650 ((byte *)&color)[1] = (byte) ((float) (128.0f * currententity->colormod[1]));
651 ((byte *)&color)[2] = (byte) ((float) (128.0f * currententity->colormod[2]));
655 ((byte *)&color)[0] = (byte) ((float) (255.0f * currententity->colormod[0]));
656 ((byte *)&color)[1] = (byte) ((float) (255.0f * currententity->colormod[1]));
657 ((byte *)&color)[2] = (byte) ((float) (255.0f * currententity->colormod[2]));
659 ((byte *)&color)[3] = a;
660 for (i = 0;i < numverts;i++)
662 *((int *)avc) = color;
669 mod[0] = currententity->colormod[0] * 0.5f;
670 mod[1] = currententity->colormod[1] * 0.5f;
671 mod[2] = currententity->colormod[2] * 0.5f;
675 mod[0] = currententity->colormod[0];
676 mod[1] = currententity->colormod[1];
677 mod[2] = currententity->colormod[2];
679 basecolor[0] *= mod[0];
680 basecolor[1] *= mod[1];
681 basecolor[2] *= mod[2];
682 if (r_lightmodels.value)
684 for (i = 0;i < MAX_DLIGHTS;i++)
686 if (!modeldlightbits[i >> 5])
691 if (!(modeldlightbits[i >> 5] & (1 << (i & 31))))
693 VectorSubtract (center, cl_dlights[i].origin, dist);
694 t1 = cl_dlights[i].radius*cl_dlights[i].radius*LIGHTSCALE;
695 t2 = DotProduct(dist,dist) + LIGHTOFFSET;
698 VectorCopy(cl_dlights[i].origin, nearlight[nearlights].origin);
699 nearlight[nearlights].color[0] = cl_dlights[i].color[0] * cl_dlights[i].radius * cl_dlights[i].radius * mod[0];
700 nearlight[nearlights].color[1] = cl_dlights[i].color[1] * cl_dlights[i].radius * cl_dlights[i].radius * mod[1];
701 nearlight[nearlights].color[2] = cl_dlights[i].color[2] * cl_dlights[i].radius * cl_dlights[i].radius * mod[2];
702 t1 = (128.0f / LIGHTSCALE) / t2;
703 basecolor[0] += nearlight[nearlights].color[0] * t1;
704 basecolor[1] += nearlight[nearlights].color[1] * t1;
705 basecolor[2] += nearlight[nearlights].color[2] * t1;
712 for (i = 0;i < MAX_DLIGHTS;i++)
714 if (!modeldlightbits[i >> 5])
719 if (!(modeldlightbits[i >> 5] & (1 << (i & 31))))
721 VectorSubtract (center, cl_dlights[i].origin, dist);
722 t1 = cl_dlights[i].radius*cl_dlights[i].radius*LIGHTSCALE;
723 t2 = DotProduct(dist,dist) + LIGHTOFFSET;
726 dist[0] = cl_dlights[i].color[0] * cl_dlights[i].radius * cl_dlights[i].radius * mod[0];
727 dist[1] = cl_dlights[i].color[1] * cl_dlights[i].radius * cl_dlights[i].radius * mod[1];
728 dist[2] = cl_dlights[i].color[2] * cl_dlights[i].radius * cl_dlights[i].radius * mod[2];
729 t1 = (192.0f / LIGHTSCALE) / t2;
730 basecolor[0] += dist[0] * t1;
731 basecolor[1] += dist[1] * t1;
732 basecolor[2] += dist[2] * t1;
736 t1 = bound(0, basecolor[0], 255);r = (byte) t1;
737 t1 = bound(0, basecolor[1], 255);g = (byte) t1;
738 t1 = bound(0, basecolor[2], 255);b = (byte) t1;
739 ((byte *)&color)[0] = r;
740 ((byte *)&color)[1] = g;
741 ((byte *)&color)[2] = b;
742 ((byte *)&color)[3] = a;
751 for (i = 0;i < numverts;i++)
753 VectorSubtract(nearlight[0].origin, av, v);
754 t = DotProduct(avn,v);
757 t /= DotProduct(v,v);
758 temp = (int) ((float) (basecolor[0] + nearlight[0].color[0] * t));if (temp < 0) temp = 0;else if (temp > 255) temp = 255;avc[0] = temp;
759 temp = (int) ((float) (basecolor[1] + nearlight[0].color[1] * t));if (temp < 0) temp = 0;else if (temp > 255) temp = 255;avc[1] = temp;
760 temp = (int) ((float) (basecolor[2] + nearlight[0].color[2] * t));if (temp < 0) temp = 0;else if (temp > 255) temp = 255;avc[2] = temp;
764 *((int *)avc) = color;
773 for (i = 0;i < numverts;i++)
779 for (j = 0;j < nearlights;j++)
781 VectorSubtract(nearlight[j].origin, av, v);
782 t = DotProduct(avn,v);
785 t /= DotProduct(v,v);
786 t1 += nearlight[j].color[0] * t;
787 t2 += nearlight[j].color[1] * t;
788 t3 += nearlight[j].color[2] * t;
792 if (k) // dodge the costly float -> int conversions
794 i1 = t1;if (i1 < 0) i1 = 0;else if (i1 > 255) i1 = 255;avc[0] = i1;
795 i2 = t2;if (i2 < 0) i2 = 0;else if (i2 > 255) i2 = 255;avc[1] = i2;
796 i3 = t3;if (i3 < 0) i3 = 0;else if (i3 > 255) i3 = 255;avc[2] = i3;
800 *((int *)avc) = color;
807 for (i = 0;i < numverts;i++)
809 *((int *)avc) = color;