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"};
26 extern cvar_t gl_transform;
32 void r_light_shutdown()
42 Cvar_RegisterVariable(&r_lightmodels);
43 R_RegisterModule("R_Light", r_light_start, r_light_shutdown, r_light_newmap);
46 int r_dlightframecount;
53 void R_AnimateLight (void)
59 // 'm' is normal light, 'a' is no light, 'z' is double bright
60 i = (int)(cl.time*10);
61 for (j=0 ; j<MAX_LIGHTSTYLES ; j++)
63 if (!cl_lightstyle[j].length)
65 d_lightstylevalue[j] = 256;
68 k = i % cl_lightstyle[j].length;
69 k = cl_lightstyle[j].map[k] - 'a';
71 d_lightstylevalue[j] = k;
76 =============================================================================
80 =============================================================================
88 void R_OldMarkLights (vec3_t lightorigin, dlight_t *light, int bit, int bitindex, mnode_t *node)
97 // for comparisons to minimum acceptable light
98 maxdist = light->radius * light->radius;
100 // clamp radius to avoid exceeding 32768 entry division table
101 if (maxdist > 4194304)
105 if (node->contents < 0)
108 ndist = PlaneDiff(lightorigin, node->plane);
110 if (ndist > light->radius)
112 if (node->children[0]->contents >= 0) // LordHavoc: save some time by not pushing another stack frame
114 node = node->children[0];
119 if (ndist < -light->radius)
121 if (node->children[1]->contents >= 0) // LordHavoc: save some time by not pushing another stack frame
123 node = node->children[1];
129 if (node->dlightframe != r_dlightframecount) // not dynamic until now
131 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;
132 node->dlightframe = r_dlightframecount;
134 node->dlightbits[bitindex] |= bit;
137 surf = cl.worldmodel->surfaces + node->firstsurface;
138 for (i=0 ; i<node->numsurfaces ; i++, surf++)
141 float dist, dist2, impact[3];
143 if (surf->flags & SURF_PLANEBACK)
146 if (dist < -0.25f && !(surf->flags & SURF_LIGHTBOTHSIDES))
150 if (dist2 >= maxdist)
153 impact[0] = light->origin[0] - surf->plane->normal[0] * dist;
154 impact[1] = light->origin[1] - surf->plane->normal[1] * dist;
155 impact[2] = light->origin[2] - surf->plane->normal[2] * dist;
157 d = DotProduct (impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0];
162 if (dist2 >= maxdist)
167 d -= surf->extents[0] + 16;
171 if (dist2 >= maxdist)
176 d = DotProduct (impact, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] - surf->texturemins[1];
181 if (dist2 >= maxdist)
186 d -= surf->extents[1] + 16;
190 if (dist2 >= maxdist)
195 if (surf->dlightframe != r_dlightframecount) // not dynamic until now
197 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;
198 surf->dlightframe = r_dlightframecount;
200 surf->dlightbits[bitindex] |= bit;
203 if (((surf->flags & SURF_PLANEBACK) == 0) == ((PlaneDist(lightorigin, surf->plane)) >= surf->plane->dist))
205 if (surf->dlightframe != r_dlightframecount) // not dynamic until now
207 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;
208 surf->dlightframe = r_dlightframecount;
210 surf->dlightbits[bitindex] |= bit;
215 if (node->children[0]->contents >= 0)
217 if (node->children[1]->contents >= 0)
219 R_OldMarkLights (lightorigin, light, bit, bitindex, node->children[0]);
220 node = node->children[1];
225 node = node->children[0];
229 else if (node->children[1]->contents >= 0)
231 node = node->children[1];
236 void R_NoVisMarkLights (vec3_t lightorigin, dlight_t *light, int bit, int bitindex, model_t *model)
238 R_OldMarkLights(lightorigin, light, bit, bitindex, model->nodes + model->hulls[0].firstclipnode);
242 void R_VisMarkLights (vec3_t lightorigin, dlight_t *light, int bit, int bitindex, model_t *model)
244 mleaf_t *pvsleaf = Mod_PointInLeaf (lightorigin, model);
246 if (!r_dynamic.value)
249 if (!pvsleaf->compressed_vis)
250 { // no vis info, so make all visible
251 R_OldMarkLights(lightorigin, light, bit, bitindex, model->nodes + model->hulls[0].firstclipnode);
257 msurface_t *surf, **mark;
259 byte *in = pvsleaf->compressed_vis;
260 int row = (model->numleafs+7)>>3;
261 float low[3], high[3], radius, dist, maxdist;
265 radius = light->radius * 2;
267 // clamp radius to avoid exceeding 32768 entry division table
271 low[0] = lightorigin[0] - radius;low[1] = lightorigin[1] - radius;low[2] = lightorigin[2] - radius;
272 high[0] = lightorigin[0] + radius;high[1] = lightorigin[1] + radius;high[2] = lightorigin[2] + radius;
274 // for comparisons to minimum acceptable light
275 maxdist = radius*radius;
283 l = model->numleafs - (k << 3);
286 for (i=0 ; i<l ; i++)
290 leaf = &model->leafs[(k << 3)+i+1];
291 leaf->lightframe = lightframe;
292 if (leaf->visframe != r_visframecount)
294 if (leaf->contents == CONTENTS_SOLID)
296 // if out of the light radius, skip
297 if (leaf->minmaxs[0] > high[0] || leaf->minmaxs[3] < low[0]
298 || leaf->minmaxs[1] > high[1] || leaf->minmaxs[4] < low[1]
299 || leaf->minmaxs[2] > high[2] || leaf->minmaxs[5] < low[2])
301 if (leaf->dlightframe != r_dlightframecount) // not dynamic until now
303 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;
304 leaf->dlightframe = r_dlightframecount;
306 leaf->dlightbits[bitindex] |= bit;
307 if ((m = leaf->nummarksurfaces))
309 mark = leaf->firstmarksurface;
313 if (surf->visframe != r_framecount || surf->lightframe == lightframe)
315 surf->lightframe = lightframe;
316 dist = PlaneDiff(lightorigin, surf->plane);
317 if (surf->flags & SURF_PLANEBACK)
319 // LordHavoc: make sure it is infront of the surface and not too far away
320 if ((dist >= -0.25f || (surf->flags & SURF_LIGHTBOTHSIDES)) && dist < radius)
323 float dist2, impact[3];
327 impact[0] = light->origin[0] - surf->plane->normal[0] * dist;
328 impact[1] = light->origin[1] - surf->plane->normal[1] * dist;
329 impact[2] = light->origin[2] - surf->plane->normal[2] * dist;
331 d = DotProduct (impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0];
336 if (dist2 >= maxdist)
341 d -= surf->extents[0] + 16;
345 if (dist2 >= maxdist)
350 d = DotProduct (impact, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] - surf->texturemins[1];
355 if (dist2 >= maxdist)
360 d -= surf->extents[1] + 16;
364 if (dist2 >= maxdist)
369 if (surf->dlightframe != r_dlightframecount) // not dynamic until now
371 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;
372 surf->dlightframe = r_dlightframecount;
374 surf->dlightbits[bitindex] |= bit;
396 void R_PushDlights (void)
401 r_dlightframecount = r_framecount + 1; // because the count hasn't advanced yet for this frame
403 if (!r_dynamic.value)
408 for (i=0 ; i<MAX_DLIGHTS ; i++, l++)
412 // R_MarkLights (l->origin, l, 1<<(i&31), i >> 5, cl.worldmodel->nodes );
413 R_VisMarkLights (l->origin, l, 1<<(i&31), i >> 5, cl.worldmodel);
419 =============================================================================
423 =============================================================================
426 mplane_t *lightplane;
429 extern cvar_t r_ambient;
432 int RecursiveLightPoint (vec3_t color, mnode_t *node, vec3_t start, vec3_t end)
434 float front, back, frac;
438 if (node->contents < 0)
439 return false; // didn't hit anything
441 // calculate mid point
442 front = PlaneDiff (start, node->plane);
443 back = PlaneDiff (end, node->plane);
445 // LordHavoc: optimized recursion
446 if ((back < 0) == (front < 0))
447 // return RecursiveLightPoint (color, node->children[front < 0], start, end);
449 node = node->children[front < 0];
453 frac = front / (front-back);
454 mid[0] = start[0] + (end[0] - start[0])*frac;
455 mid[1] = start[1] + (end[1] - start[1])*frac;
456 mid[2] = start[2] + (end[2] - start[2])*frac;
458 // go down front side
459 if (RecursiveLightPoint (color, node->children[front < 0], start, mid))
460 return true; // hit something
465 // check for impact on this node
466 VectorCopy (mid, lightspot);
467 lightplane = node->plane;
469 surf = cl.worldmodel->surfaces + node->firstsurface;
470 for (i = 0;i < node->numsurfaces;i++, surf++)
472 if (surf->flags & SURF_DRAWTILED)
473 continue; // no lightmaps
475 ds = (int) ((float) DotProduct (mid, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3]);
476 dt = (int) ((float) DotProduct (mid, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3]);
478 if (ds < surf->texturemins[0] || dt < surf->texturemins[1])
481 ds -= surf->texturemins[0];
482 dt -= surf->texturemins[1];
484 if (ds > surf->extents[0] || dt > surf->extents[1])
490 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;
492 line3 = ((surf->extents[0]>>4)+1)*3;
494 lightmap = surf->samples + ((dt>>4) * ((surf->extents[0]>>4)+1) + (ds>>4))*3; // LordHavoc: *3 for color
496 for (maps = 0;maps < MAXLIGHTMAPS && surf->styles[maps] != 255;maps++)
498 scale = (float) d_lightstylevalue[surf->styles[maps]] * 1.0 / 256.0;
499 r00 += (float) lightmap[ 0] * scale;g00 += (float) lightmap[ 1] * scale;b00 += (float) lightmap[2] * scale;
500 r01 += (float) lightmap[ 3] * scale;g01 += (float) lightmap[ 4] * scale;b01 += (float) lightmap[5] * scale;
501 r10 += (float) lightmap[line3+0] * scale;g10 += (float) lightmap[line3+1] * scale;b10 += (float) lightmap[line3+2] * scale;
502 r11 += (float) lightmap[line3+3] * scale;g11 += (float) lightmap[line3+4] * scale;b11 += (float) lightmap[line3+5] * scale;
503 lightmap += ((surf->extents[0]>>4)+1) * ((surf->extents[1]>>4)+1)*3; // LordHavoc: *3 for colored lighting
506 color[0] += (float) ((int) ((((((((r11-r10) * dsfrac) >> 4) + r10)-((((r01-r00) * dsfrac) >> 4) + r00)) * dtfrac) >> 4) + ((((r01-r00) * dsfrac) >> 4) + r00)));
507 color[1] += (float) ((int) ((((((((g11-g10) * dsfrac) >> 4) + g10)-((((g01-g00) * dsfrac) >> 4) + g00)) * dtfrac) >> 4) + ((((g01-g00) * dsfrac) >> 4) + g00)));
508 color[2] += (float) ((int) ((((((((b11-b10) * dsfrac) >> 4) + b10)-((((b01-b00) * dsfrac) >> 4) + b00)) * dtfrac) >> 4) + ((((b01-b00) * dsfrac) >> 4) + b00)));
510 return true; // success
514 return RecursiveLightPoint (color, node->children[front >= 0], mid, end);
518 void R_LightPoint (vec3_t color, vec3_t p)
522 if (r_fullbright.value || !cl.worldmodel->lightdata)
524 color[0] = color[1] = color[2] = 255;
530 end[2] = p[2] - 2048;
532 color[0] = color[1] = color[2] = r_ambient.value * 2.0f;
533 RecursiveLightPoint (color, cl.worldmodel->nodes, p, end);
536 void SV_LightPoint (vec3_t color, vec3_t p)
540 if (!sv.worldmodel->lightdata)
542 color[0] = color[1] = color[2] = 255;
548 end[2] = p[2] - 2048;
550 color[0] = color[1] = color[2] = 0;
551 RecursiveLightPoint (color, sv.worldmodel->nodes, p, end);
555 int RecursiveLightPoint (vec3_t color, mnode_t *node, float x, float y, float startz, float endz)
557 int side, distz = endz - startz;
562 if (node->contents < 0)
563 return false; // didn't hit anything
565 switch (node->plane->type)
568 node = node->children[x < node->plane->dist];
571 node = node->children[y < node->plane->dist];
574 side = startz < node->plane->dist;
575 if ((endz < node->plane->dist) == side)
577 node = node->children[side];
580 // found an intersection
581 // mid = startz + (endz - startz) * (startz - node->plane->dist) / (startz - endz);
582 // mid = startz + distz * (startz - node->plane->dist) / (-distz);
583 // mid = startz + (-(startz - node->plane->dist));
584 // mid = startz - (startz - node->plane->dist);
585 // mid = startz + node->plane->dist - startz;
586 mid = node->plane->dist;
589 back = front = x * node->plane->normal[0] + y * node->plane->normal[1];
590 front += startz * node->plane->normal[2];
591 back += endz * node->plane->normal[2];
592 side = front < node->plane->dist;
593 if ((back < node->plane->dist) == side)
595 node = node->children[side];
598 // found an intersection
599 // mid = startz + (endz - startz) * ((front - node->plane->dist) / ((front - node->plane->dist) - (back - node->plane->dist)));
600 // mid = startz + (endz - startz) * ((front - node->plane->dist) / (front - back));
601 mid = startz + distz * (front - node->plane->dist) / (front - back);
605 // go down front side
606 if (node->children[side]->contents >= 0 && RecursiveLightPoint (color, node->children[side], x, y, startz, mid))
607 return true; // hit something
610 // check for impact on this node
611 if (node->numsurfaces)
618 lightplane = node->plane;
620 surf = cl.worldmodel->surfaces + node->firstsurface;
621 for (i = 0;i < node->numsurfaces;i++, surf++)
623 if (surf->flags & SURF_DRAWTILED)
624 continue; // no lightmaps
626 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]);
627 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]);
629 if (ds < surf->texturemins[0] || dt < surf->texturemins[1])
632 ds -= surf->texturemins[0];
633 dt -= surf->texturemins[1];
635 if (ds > surf->extents[0] || dt > surf->extents[1])
641 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;
642 line3 = ((surf->extents[0]>>4)+1)*3;
643 size3 = ((surf->extents[0]>>4)+1) * ((surf->extents[1]>>4)+1)*3; // LordHavoc: *3 for colored lighting
645 lightmap = surf->samples + ((dt>>4) * ((surf->extents[0]>>4)+1) + (ds>>4))*3; // LordHavoc: *3 for color
647 for (maps = 0;maps < MAXLIGHTMAPS && surf->styles[maps] != 255;maps++)
649 scale = d_lightstylevalue[surf->styles[maps]];
650 r00 += lightmap[ 0] * scale;g00 += lightmap[ 1] * scale;b00 += lightmap[ 2] * scale;
651 r01 += lightmap[ 3] * scale;g01 += lightmap[ 4] * scale;b01 += lightmap[ 5] * scale;
652 r10 += lightmap[line3+0] * scale;g10 += lightmap[line3+1] * scale;b10 += lightmap[line3+2] * scale;
653 r11 += lightmap[line3+3] * scale;g11 += lightmap[line3+4] * scale;b11 += lightmap[line3+5] * scale;
657 color[0] += (float) ((((((((r11-r10) * dsfrac) >> 4) + r10)-((((r01-r00) * dsfrac) >> 4) + r00)) * dtfrac) >> 4) + ((((r01-r00) * dsfrac) >> 4) + r00)) * (1.0f / 256.0f);
658 color[1] += (float) ((((((((g11-g10) * dsfrac) >> 4) + g10)-((((g01-g00) * dsfrac) >> 4) + g00)) * dtfrac) >> 4) + ((((g01-g00) * dsfrac) >> 4) + g00)) * (1.0f / 256.0f);
659 color[2] += (float) ((((((((b11-b10) * dsfrac) >> 4) + b10)-((((b01-b00) * dsfrac) >> 4) + b00)) * dtfrac) >> 4) + ((((b01-b00) * dsfrac) >> 4) + b00)) * (1.0f / 256.0f);
661 return true; // success
666 node = node->children[side ^ 1];
668 distz = endz - startz;
670 // return RecursiveLightPoint (color, node->children[side ^ 1], x, y, mid, endz);
674 void R_DynamicLightPoint(vec3_t color, vec3_t org, int *dlightbits)
678 float brightness, r, f;
680 if (!r_dynamic.value || (!dlightbits[0] && !dlightbits[1] && !dlightbits[2] && !dlightbits[3] && !dlightbits[4] && !dlightbits[5] && !dlightbits[6] && !dlightbits[7]))
683 for (j = 0;j < (MAX_DLIGHTS >> 5);j++)
687 for (i=0 ; i<32 ; i++)
689 if (!((1 << i) & dlightbits[j]))
692 if (!cl_dlights[k].radius)
694 VectorSubtract (org, cl_dlights[k].origin, dist);
695 f = DotProduct(dist, dist) + LIGHTOFFSET;
696 r = cl_dlights[k].radius*cl_dlights[k].radius;
699 brightness = r * 128.0f / f;
700 color[0] += brightness * cl_dlights[k].color[0];
701 color[1] += brightness * cl_dlights[k].color[1];
702 color[2] += brightness * cl_dlights[k].color[2];
709 void R_CompleteLightPoint (vec3_t color, vec3_t p, int dynamic)
712 leaf = Mod_PointInLeaf(p, cl.worldmodel);
713 if (leaf->contents == CONTENTS_SOLID)
715 color[0] = color[1] = color[2] = 0;
719 if (r_fullbright.value || !cl.worldmodel->lightdata)
721 color[0] = color[1] = color[2] = 255;
725 color[0] = color[1] = color[2] = r_ambient.value * 2.0f;
726 RecursiveLightPoint (color, cl.worldmodel->nodes, p[0], p[1], p[2], p[2] - 65536);
729 R_DynamicLightPoint(color, p, leaf->dlightbits);
732 void R_ModelLightPoint (vec3_t color, vec3_t p, int *dlightbits)
735 leaf = Mod_PointInLeaf(p, cl.worldmodel);
736 if (leaf->contents == CONTENTS_SOLID)
738 color[0] = color[1] = color[2] = 0;
739 dlightbits[0] = dlightbits[1] = dlightbits[2] = dlightbits[3] = dlightbits[4] = dlightbits[5] = dlightbits[6] = dlightbits[7] = 0;
743 if (r_fullbright.value || !cl.worldmodel->lightdata)
745 color[0] = color[1] = color[2] = 255;
746 dlightbits[0] = dlightbits[1] = dlightbits[2] = dlightbits[3] = dlightbits[4] = dlightbits[5] = dlightbits[6] = dlightbits[7] = 0;
750 color[0] = color[1] = color[2] = r_ambient.value * 2.0f;
751 RecursiveLightPoint (color, cl.worldmodel->nodes, p[0], p[1], p[2], p[2] - 65536);
753 if (leaf->dlightframe == r_dlightframecount)
755 dlightbits[0] = leaf->dlightbits[0];
756 dlightbits[1] = leaf->dlightbits[1];
757 dlightbits[2] = leaf->dlightbits[2];
758 dlightbits[3] = leaf->dlightbits[3];
759 dlightbits[4] = leaf->dlightbits[4];
760 dlightbits[5] = leaf->dlightbits[5];
761 dlightbits[6] = leaf->dlightbits[6];
762 dlightbits[7] = leaf->dlightbits[7];
765 dlightbits[0] = dlightbits[1] = dlightbits[2] = dlightbits[3] = dlightbits[4] = dlightbits[5] = dlightbits[6] = dlightbits[7] = 0;
768 /* // not currently used
769 void R_DynamicLightPointNoMask(vec3_t color, vec3_t org)
773 float brightness, r, f;
775 if (!r_dynamic.value)
778 for (i=0 ; i<MAX_DLIGHTS ; i++)
780 if (!cl_dlights[i].radius)
782 VectorSubtract (org, cl_dlights[i].origin, dist);
783 f = DotProduct(dist, dist) + LIGHTOFFSET;
784 r = cl_dlights[i].radius*cl_dlights[i].radius;
787 brightness = r * 256.0f / f;
788 if (cl_dlights[i].dark)
789 brightness = -brightness;
790 color[0] += brightness * cl_dlights[i].color[0];
791 color[1] += brightness * cl_dlights[i].color[1];
792 color[2] += brightness * cl_dlights[i].color[2];
798 extern float *aliasvert;
799 extern float *aliasvertnorm;
800 extern byte *aliasvertcolor;
801 extern float modelalpha;
802 void R_LightModel(entity_t *ent, int numverts, vec3_t center, vec3_t basecolor)
804 // LordHavoc: warning: reliance on int being 4 bytes here (of course the d_8to24table relies on that too...)
805 int i, j, nearlights = 0, color;
807 float t, t1, t2, t3, *avn;
813 } nearlight[MAX_DLIGHTS];
814 int modeldlightbits[8];
815 avc = aliasvertcolor;
817 a = (byte) bound((int) 0, (int) (modelalpha * 255.0f), (int) 255);
820 mod[0] = ent->render.colormod[0] * 0.5f;
821 mod[1] = ent->render.colormod[1] * 0.5f;
822 mod[2] = ent->render.colormod[2] * 0.5f;
826 mod[0] = ent->render.colormod[0];
827 mod[1] = ent->render.colormod[1];
828 mod[2] = ent->render.colormod[2];
830 if (ent->render.effects & EF_FULLBRIGHT)
832 ((byte *)&color)[0] = (byte) (255.0f * mod[0]);
833 ((byte *)&color)[1] = (byte) (255.0f * mod[1]);
834 ((byte *)&color)[2] = (byte) (255.0f * mod[2]);
835 ((byte *)&color)[3] = a;
836 for (i = 0;i < numverts;i++)
838 *((int *)avc) = color;
843 R_ModelLightPoint(basecolor, center, modeldlightbits);
845 basecolor[0] *= mod[0];
846 basecolor[1] *= mod[1];
847 basecolor[2] *= mod[2];
848 for (i = 0;i < MAX_DLIGHTS;i++)
850 if (!modeldlightbits[i >> 5])
855 if (!(modeldlightbits[i >> 5] & (1 << (i & 31))))
857 VectorSubtract (center, cl_dlights[i].origin, dist);
858 t2 = DotProduct(dist,dist) + LIGHTOFFSET;
859 t1 = cl_dlights[i].radius*cl_dlights[i].radius;
862 // transform the light into the model's coordinate system
863 if (gl_transform.value)
864 softwareuntransform(cl_dlights[i].origin, nearlight[nearlights].origin);
867 VectorCopy(cl_dlights[i].origin, nearlight[nearlights].origin);
869 nearlight[nearlights].color[0] = cl_dlights[i].color[0] * t1 * mod[0];
870 nearlight[nearlights].color[1] = cl_dlights[i].color[1] * t1 * mod[1];
871 nearlight[nearlights].color[2] = cl_dlights[i].color[2] * t1 * mod[2];
872 if (r_lightmodels.value && (ent == NULL || ent != cl_dlights[i].ent))
877 basecolor[0] += nearlight[nearlights].color[0] * t1;
878 basecolor[1] += nearlight[nearlights].color[1] * t1;
879 basecolor[2] += nearlight[nearlights].color[2] * t1;
883 t1 = bound(0, basecolor[0], 255);r = (byte) t1;
884 t1 = bound(0, basecolor[1], 255);g = (byte) t1;
885 t1 = bound(0, basecolor[2], 255);b = (byte) t1;
886 ((byte *)&color)[0] = r;
887 ((byte *)&color)[1] = g;
888 ((byte *)&color)[2] = b;
889 ((byte *)&color)[3] = a;
898 for (i = 0;i < numverts;i++)
900 VectorSubtract(nearlight[0].origin, av, v);
901 t = DotProduct(avn,v);
904 t /= (DotProduct(v,v) + LIGHTOFFSET);
905 temp = (int) ((float) (basecolor[0] + nearlight[0].color[0] * t));
906 avc[0] = bound(0, temp, 255);
907 temp = (int) ((float) (basecolor[1] + nearlight[0].color[1] * t));
908 avc[1] = bound(0, temp, 255);
909 temp = (int) ((float) (basecolor[2] + nearlight[0].color[2] * t));
910 avc[2] = bound(0, temp, 255);
914 *((int *)avc) = color;
922 for (i = 0;i < numverts;i++)
929 for (j = 0;j < nearlights;j++)
931 VectorSubtract(nearlight[j].origin, av, v);
932 t = DotProduct(avn,v);
935 t /= (DotProduct(v,v) + LIGHTOFFSET);
936 t1 += nearlight[j].color[0] * t;
937 t2 += nearlight[j].color[1] * t;
938 t3 += nearlight[j].color[2] * t;
946 avc[0] = bound(0, i1, 255);
948 avc[1] = bound(0, i2, 255);
950 avc[2] = bound(0, i3, 255);
953 else // dodge the costly float -> int conversions
954 *((int *)avc) = color;
963 for (i = 0;i < numverts;i++)
965 *((int *)avc) = color;