Debian Codegraph @

code/renderergl2/tr_world.c

raw symbols SCIP
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22 #include "tr_local.h"
23
24
25
26 /*
27 ================
28 R_CullSurface
29
30 Tries to cull surfaces before they are lighted or
31 added to the sorting list.
32 ================
33 */
34 static qboolean R_CullSurface( msurface_t *surf ) {
35 if ( r_nocull->integer || surf->cullinfo.type == CULLINFO_NONE) {
36 return qfalse;
37 }
38
39 if ( r_nocurves->integer && *surf->data == SF_GRID ) {
40 return qtrue;
41 }
42
43 if (surf->cullinfo.type & CULLINFO_PLANE)
44 {
45 // Only true for SF_FACE, so treat like its own function
46 float d;
47 cullType_t ct;
48
49 if ( !r_facePlaneCull->integer ) {
50 return qfalse;
51 }
52
53 ct = surf->shader->cullType;
54
55 if (ct == CT_TWO_SIDED)
56 {
57 return qfalse;
58 }
59
60 // don't cull for depth shadow
61 /*
62 if ( tr.viewParms.flags & VPF_DEPTHSHADOW )
63 {
64 return qfalse;
65 }
66 */
67
68 // shadowmaps draw back surfaces
69 if ( tr.viewParms.flags & (VPF_SHADOWMAP | VPF_DEPTHSHADOW) )
70 {
71 if (ct == CT_FRONT_SIDED)
72 {
73 ct = CT_BACK_SIDED;
74 }
75 else
76 {
77 ct = CT_FRONT_SIDED;
78 }
79 }
80
81 // do proper cull for orthographic projection
82 if (tr.viewParms.flags & VPF_ORTHOGRAPHIC) {
83 d = DotProduct(tr.viewParms.or.axis[0], surf->cullinfo.plane.normal);
84 if ( ct == CT_FRONT_SIDED ) {
85 if (d > 0)
86 return qtrue;
87 } else {
88 if (d < 0)
89 return qtrue;
90 }
91 return qfalse;
92 }
93
94 d = DotProduct (tr.or.viewOrigin, surf->cullinfo.plane.normal);
95
96 // don't cull exactly on the plane, because there are levels of rounding
97 // through the BSP, ICD, and hardware that may cause pixel gaps if an
98 // epsilon isn't allowed here
99 if ( ct == CT_FRONT_SIDED ) {
100 if ( d < surf->cullinfo.plane.dist - 8 ) {
101 return qtrue;
102 }
103 } else {
104 if ( d > surf->cullinfo.plane.dist + 8 ) {
105 return qtrue;
106 }
107 }
108
109 return qfalse;
110 }
111
112 if (surf->cullinfo.type & CULLINFO_SPHERE)
113 {
114 int sphereCull;
115
116 if ( tr.currentEntityNum != REFENTITYNUM_WORLD ) {
117 sphereCull = R_CullLocalPointAndRadius( surf->cullinfo.localOrigin, surf->cullinfo.radius );
118 } else {
119 sphereCull = R_CullPointAndRadius( surf->cullinfo.localOrigin, surf->cullinfo.radius );
120 }
121
122 if ( sphereCull == CULL_OUT )
123 {
124 return qtrue;
125 }
126 }
127
128 if (surf->cullinfo.type & CULLINFO_BOX)
129 {
130 int boxCull;
131
132 if ( tr.currentEntityNum != REFENTITYNUM_WORLD ) {
133 boxCull = R_CullLocalBox( surf->cullinfo.bounds );
134 } else {
135 boxCull = R_CullBox( surf->cullinfo.bounds );
136 }
137
138 if ( boxCull == CULL_OUT )
139 {
140 return qtrue;
141 }
142 }
143
144 return qfalse;
145 }
146
147
148 /*
149 ====================
150 R_DlightSurface
151
152 The given surface is going to be drawn, and it touches a leaf
153 that is touched by one or more dlights, so try to throw out
154 more dlights if possible.
155 ====================
156 */
157 static int R_DlightSurface( msurface_t *surf, int dlightBits ) {
158 float d;
159 int i;
160 dlight_t *dl;
161
162 if ( surf->cullinfo.type & CULLINFO_PLANE )
163 {
164 for ( i = 0 ; i < tr.refdef.num_dlights ; i++ ) {
165 if ( ! ( dlightBits & ( 1 << i ) ) ) {
166 continue;
167 }
168 dl = &tr.refdef.dlights[i];
169 d = DotProduct( dl->origin, surf->cullinfo.plane.normal ) - surf->cullinfo.plane.dist;
170 if ( d < -dl->radius || d > dl->radius ) {
171 // dlight doesn't reach the plane
172 dlightBits &= ~( 1 << i );
173 }
174 }
175 }
176
177 if ( surf->cullinfo.type & CULLINFO_BOX )
178 {
179 for ( i = 0 ; i < tr.refdef.num_dlights ; i++ ) {
180 if ( ! ( dlightBits & ( 1 << i ) ) ) {
181 continue;
182 }
183 dl = &tr.refdef.dlights[i];
184 if ( dl->origin[0] - dl->radius > surf->cullinfo.bounds[1][0]
185 || dl->origin[0] + dl->radius < surf->cullinfo.bounds[0][0]
186 || dl->origin[1] - dl->radius > surf->cullinfo.bounds[1][1]
187 || dl->origin[1] + dl->radius < surf->cullinfo.bounds[0][1]
188 || dl->origin[2] - dl->radius > surf->cullinfo.bounds[1][2]
189 || dl->origin[2] + dl->radius < surf->cullinfo.bounds[0][2] ) {
190 // dlight doesn't reach the bounds
191 dlightBits &= ~( 1 << i );
192 }
193 }
194 }
195
196 if ( surf->cullinfo.type & CULLINFO_SPHERE )
197 {
198 for ( i = 0 ; i < tr.refdef.num_dlights ; i++ ) {
199 if ( ! ( dlightBits & ( 1 << i ) ) ) {
200 continue;
201 }
202 dl = &tr.refdef.dlights[i];
203 if (!SpheresIntersect(dl->origin, dl->radius, surf->cullinfo.localOrigin, surf->cullinfo.radius))
204 {
205 // dlight doesn't reach the bounds
206 dlightBits &= ~( 1 << i );
207 }
208 }
209 }
210
211 switch(*surf->data)
212 {
213 case SF_FACE:
214 case SF_GRID:
215 case SF_TRIANGLES:
216 ((srfBspSurface_t *)surf->data)->dlightBits = dlightBits;
217 break;
218
219 default:
220 dlightBits = 0;
221 break;
222 }
223
224 if ( dlightBits ) {
225 tr.pc.c_dlightSurfaces++;
226 } else {
227 tr.pc.c_dlightSurfacesCulled++;
228 }
229
230 return dlightBits;
231 }
232
233 /*
234 ====================
235 R_PshadowSurface
236
237 Just like R_DlightSurface, cull any we can
238 ====================
239 */
240 static int R_PshadowSurface( msurface_t *surf, int pshadowBits ) {
241 float d;
242 int i;
243 pshadow_t *ps;
244
245 if ( surf->cullinfo.type & CULLINFO_PLANE )
246 {
247 for ( i = 0 ; i < tr.refdef.num_pshadows ; i++ ) {
248 if ( ! ( pshadowBits & ( 1 << i ) ) ) {
249 continue;
250 }
251 ps = &tr.refdef.pshadows[i];
252 d = DotProduct( ps->lightOrigin, surf->cullinfo.plane.normal ) - surf->cullinfo.plane.dist;
253 if ( d < -ps->lightRadius || d > ps->lightRadius ) {
254 // pshadow doesn't reach the plane
255 pshadowBits &= ~( 1 << i );
256 }
257 }
258 }
259
260 if ( surf->cullinfo.type & CULLINFO_BOX )
261 {
262 for ( i = 0 ; i < tr.refdef.num_pshadows ; i++ ) {
263 if ( ! ( pshadowBits & ( 1 << i ) ) ) {
264 continue;
265 }
266 ps = &tr.refdef.pshadows[i];
267 if ( ps->lightOrigin[0] - ps->lightRadius > surf->cullinfo.bounds[1][0]
268 || ps->lightOrigin[0] + ps->lightRadius < surf->cullinfo.bounds[0][0]
269 || ps->lightOrigin[1] - ps->lightRadius > surf->cullinfo.bounds[1][1]
270 || ps->lightOrigin[1] + ps->lightRadius < surf->cullinfo.bounds[0][1]
271 || ps->lightOrigin[2] - ps->lightRadius > surf->cullinfo.bounds[1][2]
272 || ps->lightOrigin[2] + ps->lightRadius < surf->cullinfo.bounds[0][2]
273 || BoxOnPlaneSide(surf->cullinfo.bounds[0], surf->cullinfo.bounds[1], &ps->cullPlane) == 2 ) {
274 // pshadow doesn't reach the bounds
275 pshadowBits &= ~( 1 << i );
276 }
277 }
278 }
279
280 if ( surf->cullinfo.type & CULLINFO_SPHERE )
281 {
282 for ( i = 0 ; i < tr.refdef.num_pshadows ; i++ ) {
283 if ( ! ( pshadowBits & ( 1 << i ) ) ) {
284 continue;
285 }
286 ps = &tr.refdef.pshadows[i];
287 if (!SpheresIntersect(ps->viewOrigin, ps->viewRadius, surf->cullinfo.localOrigin, surf->cullinfo.radius)
288 || DotProduct( surf->cullinfo.localOrigin, ps->cullPlane.normal ) - ps->cullPlane.dist < -surf->cullinfo.radius)
289 {
290 // pshadow doesn't reach the bounds
291 pshadowBits &= ~( 1 << i );
292 }
293 }
294 }
295
296 switch(*surf->data)
297 {
298 case SF_FACE:
299 case SF_GRID:
300 case SF_TRIANGLES:
301 ((srfBspSurface_t *)surf->data)->pshadowBits = pshadowBits;
302 break;
303
304 default:
305 pshadowBits = 0;
306 break;
307 }
308
309 if ( pshadowBits ) {
310 //tr.pc.c_dlightSurfaces++;
311 }
312
313 return pshadowBits;
314 }
315
316
317 /*
318 ======================
319 R_AddWorldSurface
320 ======================
321 */
322 static void R_AddWorldSurface( msurface_t *surf, int dlightBits, int pshadowBits ) {
323 // FIXME: bmodel fog?
324
325 // try to cull before dlighting or adding
326 if ( R_CullSurface( surf ) ) {
327 return;
328 }
329
330 // check for dlighting
331 /*if ( dlightBits ) */{
332 dlightBits = R_DlightSurface( surf, dlightBits );
333 dlightBits = ( dlightBits != 0 );
334 }
335
336 // check for pshadows
337 /*if ( pshadowBits ) */{
338 pshadowBits = R_PshadowSurface( surf, pshadowBits);
339 pshadowBits = ( pshadowBits != 0 );
340 }
341
342 R_AddDrawSurf( surf->data, surf->shader, surf->fogIndex, dlightBits, pshadowBits, surf->cubemapIndex );
343 }
344
345 /*
346 =============================================================
347
348 BRUSH MODELS
349
350 =============================================================
351 */
352
353 /*
354 =================
355 R_AddBrushModelSurfaces
356 =================
357 */
358 void R_AddBrushModelSurfaces ( trRefEntity_t *ent ) {
359 bmodel_t *bmodel;
360 int clip;
361 model_t *pModel;
362 int i;
363
364 pModel = R_GetModelByHandle( ent->e.hModel );
365
366 bmodel = pModel->bmodel;
367
368 clip = R_CullLocalBox( bmodel->bounds );
369 if ( clip == CULL_OUT ) {
370 return;
371 }
372
373 R_SetupEntityLighting( &tr.refdef, ent );
374 R_DlightBmodel( bmodel );
375
376 for ( i = 0 ; i < bmodel->numSurfaces ; i++ ) {
377 int surf = bmodel->firstSurface + i;
378
379 if (tr.world->surfacesViewCount[surf] != tr.viewCount)
380 {
381 tr.world->surfacesViewCount[surf] = tr.viewCount;
382 R_AddWorldSurface( tr.world->surfaces + surf, tr.currentEntity->needDlights, 0 );
383 }
384 }
385 }
386
387
388 /*
389 =============================================================
390
391 WORLD MODEL
392
393 =============================================================
394 */
395
396
397 /*
398 ================
399 R_RecursiveWorldNode
400 ================
401 */
402 static void R_RecursiveWorldNode( mnode_t *node, uint32_t planeBits, uint32_t dlightBits, uint32_t pshadowBits ) {
403
404 do {
405 uint32_t newDlights[2];
406 uint32_t newPShadows[2];
407
408 // if the node wasn't marked as potentially visible, exit
409 // pvs is skipped for depth shadows
410 if (!(tr.viewParms.flags & VPF_DEPTHSHADOW) && node->visCounts[tr.visIndex] != tr.visCounts[tr.visIndex]) {
411 return;
412 }
413
414 // if the bounding volume is outside the frustum, nothing
415 // inside can be visible OPTIMIZE: don't do this all the way to leafs?
416
417 if ( !r_nocull->integer ) {
418 int r;
419
420 if ( planeBits & 1 ) {
421 r = BoxOnPlaneSide(node->mins, node->maxs, &tr.viewParms.frustum[0]);
422 if (r == 2) {
423 return; // culled
424 }
425 if ( r == 1 ) {
426 planeBits &= ~1; // all descendants will also be in front
427 }
428 }
429
430 if ( planeBits & 2 ) {
431 r = BoxOnPlaneSide(node->mins, node->maxs, &tr.viewParms.frustum[1]);
432 if (r == 2) {
433 return; // culled
434 }
435 if ( r == 1 ) {
436 planeBits &= ~2; // all descendants will also be in front
437 }
438 }
439
440 if ( planeBits & 4 ) {
441 r = BoxOnPlaneSide(node->mins, node->maxs, &tr.viewParms.frustum[2]);
442 if (r == 2) {
443 return; // culled
444 }
445 if ( r == 1 ) {
446 planeBits &= ~4; // all descendants will also be in front
447 }
448 }
449
450 if ( planeBits & 8 ) {
451 r = BoxOnPlaneSide(node->mins, node->maxs, &tr.viewParms.frustum[3]);
452 if (r == 2) {
453 return; // culled
454 }
455 if ( r == 1 ) {
456 planeBits &= ~8; // all descendants will also be in front
457 }
458 }
459
460 if ( planeBits & 16 ) {
461 r = BoxOnPlaneSide(node->mins, node->maxs, &tr.viewParms.frustum[4]);
462 if (r == 2) {
463 return; // culled
464 }
465 if ( r == 1 ) {
466 planeBits &= ~16; // all descendants will also be in front
467 }
468 }
469 }
470
471 if ( node->contents != -1 ) {
472 break;
473 }
474
475 // node is just a decision point, so go down both sides
476 // since we don't care about sort orders, just go positive to negative
477
478 // determine which dlights are needed
479 newDlights[0] = 0;
480 newDlights[1] = 0;
481 if ( dlightBits ) {
482 int i;
483
484 for ( i = 0 ; i < tr.refdef.num_dlights ; i++ ) {
485 dlight_t *dl;
486 float dist;
487
488 if ( dlightBits & ( 1 << i ) ) {
489 dl = &tr.refdef.dlights[i];
490 dist = DotProduct( dl->origin, node->plane->normal ) - node->plane->dist;
491
492 if ( dist > -dl->radius ) {
493 newDlights[0] |= ( 1 << i );
494 }
495 if ( dist < dl->radius ) {
496 newDlights[1] |= ( 1 << i );
497 }
498 }
499 }
500 }
501
502 newPShadows[0] = 0;
503 newPShadows[1] = 0;
504 if ( pshadowBits ) {
505 int i;
506
507 for ( i = 0 ; i < tr.refdef.num_pshadows ; i++ ) {
508 pshadow_t *shadow;
509 float dist;
510
511 if ( pshadowBits & ( 1 << i ) ) {
512 shadow = &tr.refdef.pshadows[i];
513 dist = DotProduct( shadow->lightOrigin, node->plane->normal ) - node->plane->dist;
514
515 if ( dist > -shadow->lightRadius ) {
516 newPShadows[0] |= ( 1 << i );
517 }
518 if ( dist < shadow->lightRadius ) {
519 newPShadows[1] |= ( 1 << i );
520 }
521 }
522 }
523 }
524
525 // recurse down the children, front side first
526 R_RecursiveWorldNode (node->children[0], planeBits, newDlights[0], newPShadows[0] );
527
528 // tail recurse
529 node = node->children[1];
530 dlightBits = newDlights[1];
531 pshadowBits = newPShadows[1];
532 } while ( 1 );
533
534 {
535 // leaf node, so add mark surfaces
536 int c;
537 int surf, *view;
538
539 tr.pc.c_leafs++;
540
541 // add to z buffer bounds
542 if ( node->mins[0] < tr.viewParms.visBounds[0][0] ) {
543 tr.viewParms.visBounds[0][0] = node->mins[0];
544 }
545 if ( node->mins[1] < tr.viewParms.visBounds[0][1] ) {
546 tr.viewParms.visBounds[0][1] = node->mins[1];
547 }
548 if ( node->mins[2] < tr.viewParms.visBounds[0][2] ) {
549 tr.viewParms.visBounds[0][2] = node->mins[2];
550 }
551
552 if ( node->maxs[0] > tr.viewParms.visBounds[1][0] ) {
553 tr.viewParms.visBounds[1][0] = node->maxs[0];
554 }
555 if ( node->maxs[1] > tr.viewParms.visBounds[1][1] ) {
556 tr.viewParms.visBounds[1][1] = node->maxs[1];
557 }
558 if ( node->maxs[2] > tr.viewParms.visBounds[1][2] ) {
559 tr.viewParms.visBounds[1][2] = node->maxs[2];
560 }
561
562 // add surfaces
563 view = tr.world->marksurfaces + node->firstmarksurface;
564
565 c = node->nummarksurfaces;
566 while (c--) {
567 // just mark it as visible, so we don't jump out of the cache derefencing the surface
568 surf = *view;
569 if (tr.world->surfacesViewCount[surf] != tr.viewCount)
570 {
571 tr.world->surfacesViewCount[surf] = tr.viewCount;
572 tr.world->surfacesDlightBits[surf] = dlightBits;
573 tr.world->surfacesPshadowBits[surf] = pshadowBits;
574 }
575 else
576 {
577 tr.world->surfacesDlightBits[surf] |= dlightBits;
578 tr.world->surfacesPshadowBits[surf] |= pshadowBits;
579 }
580 view++;
581 }
582 }
583
584 }
585
586
587 /*
588 ===============
589 R_PointInLeaf
590 ===============
591 */
592 static mnode_t *R_PointInLeaf( const vec3_t p ) {
593 mnode_t *node;
594 float d;
595 cplane_t *plane;
596
597 if ( !tr.world ) {
598 ri.Error (ERR_DROP, "R_PointInLeaf: bad model");
599 }
600
601 node = tr.world->nodes;
602 while( 1 ) {
603 if (node->contents != -1) {
604 break;
605 }
606 plane = node->plane;
607 d = DotProduct (p,plane->normal) - plane->dist;
608 if (d > 0) {
609 node = node->children[0];
610 } else {
611 node = node->children[1];
612 }
613 }
614
615 return node;
616 }
617
618 /*
619 ==============
620 R_ClusterPVS
621 ==============
622 */
623 static const byte *R_ClusterPVS (int cluster) {
624 if (!tr.world->vis || cluster < 0 || cluster >= tr.world->numClusters ) {
625 return NULL;
626 }
627
628 return tr.world->vis + cluster * tr.world->clusterBytes;
629 }
630
631 /*
632 =================
633 R_inPVS
634 =================
635 */
636 qboolean R_inPVS( const vec3_t p1, const vec3_t p2 ) {
637 mnode_t *leaf;
638 byte *vis;
639
640 leaf = R_PointInLeaf( p1 );
641 vis = ri.CM_ClusterPVS( leaf->cluster ); // why not R_ClusterPVS ??
642 leaf = R_PointInLeaf( p2 );
643
644 if ( !(vis[leaf->cluster>>3] & (1<<(leaf->cluster&7))) ) {
645 return qfalse;
646 }
647 return qtrue;
648 }
649
650 /*
651 ===============
652 R_MarkLeaves
653
654 Mark the leaves and nodes that are in the PVS for the current
655 cluster
656 ===============
657 */
658 static void R_MarkLeaves (void) {
659 const byte *vis;
660 mnode_t *leaf, *parent;
661 int i;
662 int cluster;
663
664 // lockpvs lets designers walk around to determine the
665 // extent of the current pvs
666 if ( r_lockpvs->integer ) {
667 return;
668 }
669
670 // current viewcluster
671 leaf = R_PointInLeaf( tr.viewParms.pvsOrigin );
672 cluster = leaf->cluster;
673
674 // if the cluster is the same and the area visibility matrix
675 // hasn't changed, we don't need to mark everything again
676
677 for(i = 0; i < MAX_VISCOUNTS; i++)
678 {
679 // if the areamask or r_showcluster was modified, invalidate all visclusters
680 // this caused doors to open into undrawn areas
681 if (tr.refdef.areamaskModified || r_showcluster->modified)
682 {
683 tr.visClusters[i] = -2;
684 }
685 else if(tr.visClusters[i] == cluster)
686 {
687 if(tr.visClusters[i] != tr.visClusters[tr.visIndex] && r_showcluster->integer)
688 {
689 ri.Printf(PRINT_ALL, "found cluster:%i area:%i index:%i\n", cluster, leaf->area, i);
690 }
691 tr.visIndex = i;
692 return;
693 }
694 }
695
696 tr.visIndex = (tr.visIndex + 1) % MAX_VISCOUNTS;
697 tr.visCounts[tr.visIndex]++;
698 tr.visClusters[tr.visIndex] = cluster;
699
700 if ( r_showcluster->modified || r_showcluster->integer ) {
701 r_showcluster->modified = qfalse;
702 if ( r_showcluster->integer ) {
703 ri.Printf( PRINT_ALL, "cluster:%i area:%i\n", cluster, leaf->area );
704 }
705 }
706
707 vis = R_ClusterPVS(tr.visClusters[tr.visIndex]);
708
709 for (i=0,leaf=tr.world->nodes ; i<tr.world->numnodes ; i++, leaf++) {
710 cluster = leaf->cluster;
711 if ( cluster < 0 || cluster >= tr.world->numClusters ) {
712 continue;
713 }
714
715 // check general pvs
716 if ( vis && !(vis[cluster>>3] & (1<<(cluster&7))) ) {
717 continue;
718 }
719
720 // check for door connection
721 if ( (tr.refdef.areamask[leaf->area>>3] & (1<<(leaf->area&7)) ) ) {
722 continue; // not visible
723 }
724
725 parent = leaf;
726 do {
727 if(parent->visCounts[tr.visIndex] == tr.visCounts[tr.visIndex])
728 break;
729 parent->visCounts[tr.visIndex] = tr.visCounts[tr.visIndex];
730 parent = parent->parent;
731 } while (parent);
732 }
733 }
734
735
736 /*
737 =============
738 R_AddWorldSurfaces
739 =============
740 */
741 void R_AddWorldSurfaces (void) {
742 uint32_t planeBits, dlightBits, pshadowBits;
743
744 if ( !r_drawworld->integer ) {
745 return;
746 }
747
748 if ( tr.refdef.rdflags & RDF_NOWORLDMODEL ) {
749 return;
750 }
751
752 tr.currentEntityNum = REFENTITYNUM_WORLD;
753 tr.shiftedEntityNum = tr.currentEntityNum << QSORT_REFENTITYNUM_SHIFT;
754
755 // determine which leaves are in the PVS / areamask
756 if (!(tr.viewParms.flags & VPF_DEPTHSHADOW))
757 R_MarkLeaves ();
758
759 // clear out the visible min/max
760 ClearBounds( tr.viewParms.visBounds[0], tr.viewParms.visBounds[1] );
761
762 // perform frustum culling and flag all the potentially visible surfaces
763 if ( tr.refdef.num_dlights > MAX_DLIGHTS ) {
764 tr.refdef.num_dlights = MAX_DLIGHTS ;
765 }
766
767 if ( tr.refdef.num_pshadows > MAX_DRAWN_PSHADOWS ) {
768 tr.refdef.num_pshadows = MAX_DRAWN_PSHADOWS;
769 }
770
771 planeBits = (tr.viewParms.flags & VPF_FARPLANEFRUSTUM) ? 31 : 15;
772
773 if ( tr.viewParms.flags & VPF_DEPTHSHADOW )
774 {
775 dlightBits = 0;
776 pshadowBits = 0;
777 }
778 else if ( !(tr.viewParms.flags & VPF_SHADOWMAP) )
779 {
780 dlightBits = ( 1ULL << tr.refdef.num_dlights ) - 1;
781 pshadowBits = ( 1ULL << tr.refdef.num_pshadows ) - 1;
782 }
783 else
784 {
785 dlightBits = ( 1ULL << tr.refdef.num_dlights ) - 1;
786 pshadowBits = 0;
787 }
788
789 R_RecursiveWorldNode( tr.world->nodes, planeBits, dlightBits, pshadowBits);
790
791 // now add all the potentially visible surfaces
792 // also mask invisible dlights for next frame
793 {
794 int i;
795
796 tr.refdef.dlightMask = 0;
797
798 for (i = 0; i < tr.world->numWorldSurfaces; i++)
799 {
800 if (tr.world->surfacesViewCount[i] != tr.viewCount)
801 continue;
802
803 R_AddWorldSurface( tr.world->surfaces + i, tr.world->surfacesDlightBits[i], tr.world->surfacesPshadowBits[i] );
804 tr.refdef.dlightMask |= tr.world->surfacesDlightBits[i];
805 }
806
807 tr.refdef.dlightMask = ~tr.refdef.dlightMask;
808 }
809 }