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.
23 int SV_RecursiveLightPoint (vec3_t color, mnode_t *node, float x, float y, float startz, float endz)
25 int side, distz = endz - startz;
30 if (node->contents < 0)
31 return false; // didn't hit anything
33 switch (node->plane->type)
36 node = node->children[x < node->plane->dist];
39 node = node->children[y < node->plane->dist];
42 side = startz < node->plane->dist;
43 if ((endz < node->plane->dist) == side)
45 node = node->children[side];
48 // found an intersection
49 mid = node->plane->dist;
52 back = front = x * node->plane->normal[0] + y * node->plane->normal[1];
53 front += startz * node->plane->normal[2];
54 back += endz * node->plane->normal[2];
55 side = front < node->plane->dist;
56 if ((back < node->plane->dist) == side)
58 node = node->children[side];
61 // found an intersection
62 mid = startz + distz * (front - node->plane->dist) / (front - back);
67 if (node->children[side]->contents >= 0 && SV_RecursiveLightPoint (color, node->children[side], x, y, startz, mid))
68 return true; // hit something
71 // check for impact on this node
72 if (node->numsurfaces)
77 surf = sv.worldmodel->surfaces + node->firstsurface;
78 for (i = 0;i < node->numsurfaces;i++, surf++)
80 if (!(surf->flags & SURF_LIGHTMAP))
83 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]);
84 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]);
86 if (ds < surf->texturemins[0] || dt < surf->texturemins[1])
89 ds -= surf->texturemins[0];
90 dt -= surf->texturemins[1];
92 if (ds > surf->extents[0] || dt > surf->extents[1])
98 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;
99 line3 = ((surf->extents[0]>>4)+1)*3;
100 size3 = ((surf->extents[0]>>4)+1) * ((surf->extents[1]>>4)+1)*3; // LordHavoc: *3 for colored lighting
102 lightmap = surf->samples + ((dt>>4) * ((surf->extents[0]>>4)+1) + (ds>>4))*3; // LordHavoc: *3 for color
104 for (maps = 0;maps < MAXLIGHTMAPS && surf->styles[maps] != 255;maps++)
106 scale = 256; // FIXME: server doesn't know what light styles are doing
107 r00 += lightmap[ 0] * scale;g00 += lightmap[ 1] * scale;b00 += lightmap[ 2] * scale;
108 r01 += lightmap[ 3] * scale;g01 += lightmap[ 4] * scale;b01 += lightmap[ 5] * scale;
109 r10 += lightmap[line3+0] * scale;g10 += lightmap[line3+1] * scale;b10 += lightmap[line3+2] * scale;
110 r11 += lightmap[line3+3] * scale;g11 += lightmap[line3+4] * scale;b11 += lightmap[line3+5] * scale;
114 color[0] += (float) ((((((((r11-r10) * dsfrac) >> 4) + r10)-((((r01-r00) * dsfrac) >> 4) + r00)) * dtfrac) >> 4) + ((((r01-r00) * dsfrac) >> 4) + r00)) * (1.0f / 256.0f);
115 color[1] += (float) ((((((((g11-g10) * dsfrac) >> 4) + g10)-((((g01-g00) * dsfrac) >> 4) + g00)) * dtfrac) >> 4) + ((((g01-g00) * dsfrac) >> 4) + g00)) * (1.0f / 256.0f);
116 color[2] += (float) ((((((((b11-b10) * dsfrac) >> 4) + b10)-((((b01-b00) * dsfrac) >> 4) + b00)) * dtfrac) >> 4) + ((((b01-b00) * dsfrac) >> 4) + b00)) * (1.0f / 256.0f);
118 return true; // success
123 node = node->children[side ^ 1];
125 distz = endz - startz;
130 // LordHavoc: added light checking to the server
131 void SV_LightPoint (vec3_t color, vec3_t p)
133 Mod_CheckLoaded(sv.worldmodel);
134 if (!sv.worldmodel->lightdata)
136 color[0] = color[1] = color[2] = 255;
140 color[0] = color[1] = color[2] = 0;
141 SV_RecursiveLightPoint (color, sv.worldmodel->nodes, p[0], p[1], p[2], p[2] - 65536);