26 byte *b1, *b2, *b3, *b4;
37 w1 = (16 - fracu) * (16 - fracv);
38 w2 = fracu * (16 - fracv);
40 w4 = (16 - fracu) * fracv;
49 size = smax * tmax * 3;
54 lightmap = surf->lightmap;
55 for (i = 0; i < surf->numstyles; i++) {
56 b1 = &lightmap[3 * ((t + 0) * smax + (s + 0))];
57 b2 = &lightmap[3 * ((t + 0) * smax + (s + 1))];
58 b3 = &lightmap[3 * ((t + 1) * smax + (s + 1))];
59 b4 = &lightmap[3 * ((t + 1) * smax + (s + 0))];
61 temp[0] = (w1 * b1[0] + w2 * b2[0] + w3 * b3[0] + w4 * b4[0]) >> 8;
62 temp[1] = (w1 * b1[1] + w2 * b2[1] + w3 * b3[1] + w4 * b4[1]) >> 8;
63 temp[2] = (w1 * b1[2] + w2 * b2[2] + w3 * b3[2] + w4 * b4[2]) >> 8;
67 color[0] += temp[0] * style->rgb[0];
68 color[1] += temp[1] * style->rgb[1];
69 color[2] += temp[2] * style->rgb[2];
80 vec3_t end, mins, maxs;
86 if (!bsp || !bsp->lightmap)
91 end[2] = start[2] - 8192;
97 for (i = 0; i <
glr.
fd.num_entities; i++) {
98 ent = &
glr.
fd.entities[i];
100 if (!(index & 0x80000000))
104 if (index < 1 || index >= bsp->nummodels)
107 model = &bsp->models[index];
108 if (!model->numfaces)
112 if (ent->angles[0] || ent->angles[1] || ent->angles[2]) {
113 if (fabs(start[0] - ent->origin[0]) > model->radius)
115 if (fabs(start[1] - ent->origin[1]) > model->radius)
117 angles = ent->angles;
119 VectorAdd(model->mins, ent->origin, mins);
120 VectorAdd(model->maxs, ent->origin, maxs);
121 if (start[0] < mins[0] || start[0] > maxs[0])
123 if (start[1] < mins[1] || start[1] > maxs[1])
128 BSP_TransformedLightPoint(&pt, start, end, model->headnode,
129 ent->origin, angles);
146 static void GL_MarkLights_r(mnode_t *node, dlight_t *light,
int lightbit)
152 while (node->plane) {
153 dot = PlaneDiffFast(light->transformed, node->plane);
154 if (dot > light->intensity - DLIGHT_CUTOFF) {
155 node = node->children[0];
158 if (dot < -light->
intensity + DLIGHT_CUTOFF) {
159 node = node->children[1];
163 face = node->firstface;
164 count = node->numfaces;
166 if (!(face->drawflags & SURF_NOLM_MASK)) {
167 if (face->dlightframe !=
glr.dlightframe) {
168 face->dlightframe =
glr.dlightframe;
169 face->dlightbits = 0;
172 face->dlightbits |= lightbit;
178 GL_MarkLights_r(node->children[0], light, lightbit);
179 node = node->children[1];
190 for (i = 0, light =
glr.
fd.dlights; i <
glr.
fd.num_dlights; i++, light++) {
191 VectorCopy(light->origin, light->transformed);
204 for (i = 0, light =
glr.
fd.dlights; i <
glr.
fd.num_dlights; i++, light++) {
205 VectorSubtract(light->origin,
glr.
ent->origin, temp);
206 light->transformed[0] = DotProduct(temp,
glr.
entaxis[0]);
207 light->transformed[1] = DotProduct(temp,
glr.
entaxis[1]);
208 light->transformed[2] = DotProduct(temp,
glr.
entaxis[2]);
209 GL_MarkLights_r(model->headnode, light, 1 << i);
219 for (i = 0, light =
glr.
fd.dlights; i <
glr.
fd.num_dlights; i++, light++) {
220 f = light->intensity - DLIGHT_CUTOFF - Distance(light->origin,
origin);
228 #define GL_MarkLights() (void)0
229 #define GL_TransformLights() (void)0
230 #define GL_AddLights(origin, color) (void)0
236 VectorSet(
color, 1, 1, 1);
242 VectorSet(
color, 1, 1, 1);
260 for (i = 0; i < 3; i++) {
261 clamp(
color[i], 0, 1);
267 static int lastNodesVisible;
268 byte vis1[VIS_MAX_BYTES];
269 byte vis2[VIS_MAX_BYTES];
272 uint_fast32_t *src1, *src2;
273 int cluster1, cluster2, longs;
279 cluster1 = cluster2 = leaf->cluster;
280 VectorCopy(
glr.
fd.vieworg, tmp);
281 if (!leaf->contents) {
287 if (!(leaf->contents & CONTENTS_SOLID)) {
288 cluster2 = leaf->cluster;
303 if (!bsp->vis ||
gl_novis->integer || cluster1 == -1) {
305 for (i = 0; i < bsp->numnodes; i++) {
308 for (i = 0; i < bsp->numleafs; i++) {
311 lastNodesVisible = bsp->numnodes;
316 if (cluster1 != cluster2) {
318 longs = VIS_FAST_LONGS(bsp);
319 src1 = (uint_fast32_t *)vis1;
320 src2 = (uint_fast32_t *)vis2;
326 lastNodesVisible = 0;
327 for (i = 0, leaf = bsp->leafs; i < bsp->numleafs; i++, leaf++) {
328 cluster1 = leaf->cluster;
329 if (cluster1 == -1) {
332 if (Q_IsBitSet(vis1, cluster1)) {
333 node = (mnode_t *)leaf;
352 #define BACKFACE_EPSILON 0.01f
354 #define BSP_CullFace(face, dot) \
355 (((dot) < -BACKFACE_EPSILON && !((face)->drawflags & DSURF_PLANEBACK)) || \
356 ((dot) > BACKFACE_EPSILON && ((face)->drawflags & DSURF_PLANEBACK)))
360 mface_t *face, *last;
363 vec3_t transformed, temp;
367 if (!model->numfaces)
377 VectorCopy(model->mins, bounds[0]);
378 VectorCopy(model->maxs, bounds[1]);
385 VectorSubtract(
glr.
fd.vieworg, ent->origin, temp);
386 transformed[0] = DotProduct(temp,
glr.
entaxis[0]);
387 transformed[1] = DotProduct(temp,
glr.
entaxis[1]);
388 transformed[2] = DotProduct(temp,
glr.
entaxis[2]);
390 VectorAdd(model->mins, ent->origin, bounds[0]);
391 VectorAdd(model->maxs, ent->origin, bounds[1]);
397 VectorSubtract(
glr.
fd.vieworg, ent->origin, transformed);
407 last = model->firstface + model->numfaces;
408 for (face = model->firstface; face < last; face++) {
409 dot = PlaneDiffFast(transformed, face->plane);
416 if (face->drawflags & SURF_SKY) {
423 if (face->drawflags & SURF_TRANS_MASK) {
443 #define NODE_CLIPPED 0
444 #define NODE_UNCLIPPED 15
448 int flags = *clipflags;
454 for (i = 0, mask = 1; i < 4; i++, mask <<= 1) {
460 if (bits == BOX_BEHIND) {
463 if (bits == BOX_INFRONT) {
475 mface_t **face, **last;
477 if (leaf->contents == CONTENTS_SOLID) {
480 if (
glr.
fd.areabits && !Q_IsBitSet(
glr.
fd.areabits, leaf->area)) {
484 last = leaf->firstleafface + leaf->numleaffaces;
485 for (face = leaf->firstleafface; face < last; face++) {
494 mface_t *face, *last = node->firstface + node->numfaces;
496 for (face = node->firstface; face < last; face++) {
501 if (face->drawflags & SURF_SKY) {
506 if (face->drawflags & SURF_TRANS_MASK) {
541 dot = PlaneDiffFast(
glr.
fd.vieworg, node->plane);
548 node = node->children[side ^ 1];