Debian Codegraph @

tools/quake3/q3map2/fog.c

raw symbols SCIP
1 /* -------------------------------------------------------------------------------
2
3 Copyright (C) 1999-2007 id Software, Inc. and contributors.
4 For a list of contributors, see the accompanying CONTRIBUTORS file.
5
6 This file is part of GtkRadiant.
7
8 GtkRadiant is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 GtkRadiant is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GtkRadiant; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
22 ----------------------------------------------------------------------------------
23
24 This code has been altered significantly from its original form, to support
25 several games based on the Quake III Arena engine, in the form of "Q3Map2."
26
27 ------------------------------------------------------------------------------- */
28
29
30
31 /* marker */
32 #define FOG_C
33
34
35
36 /* dependencies */
37 #include "q3map2.h"
38
39
40
41 int numFogFragments;
42 int numFogPatchFragments;
43
44
45
46 /*
47 DrawSurfToMesh()
48 converts a patch drawsurface to a mesh_t
49 */
50
51 mesh_t *DrawSurfToMesh( mapDrawSurface_t *ds ){
52 mesh_t *m;
53
54
55 m = safe_malloc( sizeof( *m ) );
56 m->width = ds->patchWidth;
57 m->height = ds->patchHeight;
58 m->verts = safe_malloc( sizeof( m->verts[ 0 ] ) * m->width * m->height );
59 memcpy( m->verts, ds->verts, sizeof( m->verts[ 0 ] ) * m->width * m->height );
60
61 return m;
62 }
63
64
65
66 /*
67 SplitMeshByPlane()
68 chops a mesh by a plane
69 */
70
71 void SplitMeshByPlane( mesh_t *in, vec3_t normal, float dist, mesh_t **front, mesh_t **back ){
72 int w, h, split;
73 float d[MAX_PATCH_SIZE][MAX_PATCH_SIZE];
74 bspDrawVert_t *dv, *v1, *v2;
75 int c_front, c_back;
76 // int c_on;
77 mesh_t *f, *b;
78 int i;
79 float frac;
80 int frontAprox, backAprox;
81
82 for ( i = 0 ; i < 2 ; i++ ) {
83 dv = in->verts;
84 c_front = 0;
85 c_back = 0;
86 // c_on = 0;
87 for ( h = 0 ; h < in->height ; h++ ) {
88 for ( w = 0 ; w < in->width ; w++, dv++ ) {
89 d[h][w] = DotProduct( dv->xyz, normal ) - dist;
90 if ( d[h][w] > ON_EPSILON ) {
91 c_front++;
92 }
93 else if ( d[h][w] < -ON_EPSILON ) {
94 c_back++;
95 }
96 else {
97 // c_on++;
98 }
99 }
100 }
101
102 *front = NULL;
103 *back = NULL;
104
105 if ( !c_front ) {
106 *back = in;
107 return;
108 }
109 if ( !c_back ) {
110 *front = in;
111 return;
112 }
113
114 // find a split point
115 split = -1;
116 for ( w = 0 ; w < in->width - 1 ; w++ ) {
117 if ( ( d[0][w] < 0 ) != ( d[0][w + 1] < 0 ) ) {
118 if ( split == -1 ) {
119 split = w;
120 break;
121 }
122 }
123 }
124
125 if ( split == -1 ) {
126 if ( i == 1 ) {
127 Sys_FPrintf( SYS_VRB, "No crossing points in patch\n" );
128 *front = in;
129 return;
130 }
131
132 in = TransposeMesh( in );
133 InvertMesh( in );
134 continue;
135 }
136
137 // make sure the split point stays the same for all other rows
138 for ( h = 1 ; h < in->height ; h++ ) {
139 for ( w = 0 ; w < in->width - 1 ; w++ ) {
140 if ( ( d[h][w] < 0 ) != ( d[h][w + 1] < 0 ) ) {
141 if ( w != split ) {
142 Sys_Printf( "multiple crossing points for patch -- can't clip\n" );
143 *front = in;
144 return;
145 }
146 }
147 }
148 if ( ( d[h][split] < 0 ) == ( d[h][split + 1] < 0 ) ) {
149 Sys_Printf( "differing crossing points for patch -- can't clip\n" );
150 *front = in;
151 return;
152 }
153 }
154
155 break;
156 }
157
158
159 // create two new meshes
160 f = safe_malloc( sizeof( *f ) );
161 f->width = split + 2;
162 if ( !( f->width & 1 ) ) {
163 f->width++;
164 frontAprox = 1;
165 }
166 else {
167 frontAprox = 0;
168 }
169 if ( f->width > MAX_PATCH_SIZE ) {
170 Error( "MAX_PATCH_SIZE after split" );
171 }
172 f->height = in->height;
173 f->verts = safe_malloc( sizeof( f->verts[0] ) * f->width * f->height );
174
175 b = safe_malloc( sizeof( *b ) );
176 b->width = in->width - split;
177 if ( !( b->width & 1 ) ) {
178 b->width++;
179 backAprox = 1;
180 }
181 else {
182 backAprox = 0;
183 }
184 if ( b->width > MAX_PATCH_SIZE ) {
185 Error( "MAX_PATCH_SIZE after split" );
186 }
187 b->height = in->height;
188 b->verts = safe_malloc( sizeof( b->verts[0] ) * b->width * b->height );
189
190 if ( d[0][0] > 0 ) {
191 *front = f;
192 *back = b;
193 }
194 else {
195 *front = b;
196 *back = f;
197 }
198
199 // distribute the points
200 for ( w = 0 ; w < in->width ; w++ ) {
201 for ( h = 0 ; h < in->height ; h++ ) {
202 if ( w <= split ) {
203 f->verts[ h * f->width + w ] = in->verts[ h * in->width + w ];
204 }
205 else {
206 b->verts[ h * b->width + w - split + backAprox ] = in->verts[ h * in->width + w ];
207 }
208 }
209 }
210
211 // clip the crossing line
212 for ( h = 0; h < in->height; h++ )
213 {
214 dv = &f->verts[ h * f->width + split + 1 ];
215 v1 = &in->verts[ h * in->width + split ];
216 v2 = &in->verts[ h * in->width + split + 1 ];
217
218 frac = d[h][split] / ( d[h][split] - d[h][split + 1] );
219
220 /* interpolate */
221 //% for( i = 0; i < 10; i++ )
222 //% dv->xyz[ i ] = v1->xyz[ i ] + frac * (v2->xyz[ i ] - v1->xyz[ i ]);
223 //% dv->xyz[10] = 0; // set all 4 colors to 0
224 LerpDrawVertAmount( v1, v2, frac, dv );
225
226 if ( frontAprox ) {
227 f->verts[ h * f->width + split + 2 ] = *dv;
228 }
229 b->verts[ h * b->width ] = *dv;
230 if ( backAprox ) {
231 b->verts[ h * b->width + 1 ] = *dv;
232 }
233 }
234
235 /*
236 PrintMesh( in );
237 Sys_Printf("\n");
238 PrintMesh( f );
239 Sys_Printf("\n");
240 PrintMesh( b );
241 Sys_Printf("\n");
242 */
243
244 FreeMesh( in );
245 }
246
247
248 /*
249 ChopPatchSurfaceByBrush()
250 chops a patch up by a fog brush
251 */
252
253 qboolean ChopPatchSurfaceByBrush( entity_t *e, mapDrawSurface_t *ds, brush_t *b ){
254 int i, j;
255 side_t *s;
256 plane_t *plane;
257 mesh_t *outside[MAX_BRUSH_SIDES];
258 int numOutside;
259 mesh_t *m, *front, *back;
260 mapDrawSurface_t *newds;
261
262 m = DrawSurfToMesh( ds );
263 numOutside = 0;
264
265 // only split by the top and bottom planes to avoid
266 // some messy patch clipping issues
267
268 for ( i = 4 ; i <= 5 ; i++ ) {
269 s = &b->sides[ i ];
270 plane = &mapplanes[ s->planenum ];
271
272 SplitMeshByPlane( m, plane->normal, plane->dist, &front, &back );
273
274 if ( !back ) {
275 // nothing actually contained inside
276 for ( j = 0 ; j < numOutside ; j++ ) {
277 FreeMesh( outside[j] );
278 }
279 return qfalse;
280 }
281 m = back;
282
283 if ( front ) {
284 if ( numOutside == MAX_BRUSH_SIDES ) {
285 Error( "MAX_BRUSH_SIDES" );
286 }
287 outside[ numOutside ] = front;
288 numOutside++;
289 }
290 }
291
292 /* all of outside fragments become seperate drawsurfs */
293 numFogPatchFragments += numOutside;
294 for ( i = 0; i < numOutside; i++ )
295 {
296 /* transpose and invert the chopped patch (fixes potential crash. fixme: why?) */
297 outside[ i ] = TransposeMesh( outside[ i ] );
298 InvertMesh( outside[ i ] );
299
300 /* ydnar: do this the hacky right way */
301 newds = AllocDrawSurface( SURFACE_PATCH );
302 memcpy( newds, ds, sizeof( *ds ) );
303 newds->patchWidth = outside[ i ]->width;
304 newds->patchHeight = outside[ i ]->height;
305 newds->numVerts = outside[ i ]->width * outside[ i ]->height;
306 newds->verts = safe_malloc( newds->numVerts * sizeof( *newds->verts ) );
307 memcpy( newds->verts, outside[ i ]->verts, newds->numVerts * sizeof( *newds->verts ) );
308
309 /* free the source mesh */
310 FreeMesh( outside[ i ] );
311 }
312
313 /* only rejigger this patch if it was chopped */
314 //% Sys_Printf( "Inside: %d x %d\n", m->width, m->height );
315 if ( numOutside > 0 ) {
316 /* transpose and invert the chopped patch (fixes potential crash. fixme: why?) */
317 m = TransposeMesh( m );
318 InvertMesh( m );
319
320 /* replace ds with m */
321 ds->patchWidth = m->width;
322 ds->patchHeight = m->height;
323 ds->numVerts = m->width * m->height;
324 free( ds->verts );
325 ds->verts = safe_malloc( ds->numVerts * sizeof( *ds->verts ) );
326 memcpy( ds->verts, m->verts, ds->numVerts * sizeof( *ds->verts ) );
327 }
328
329 /* free the source mesh and return */
330 FreeMesh( m );
331 return qtrue;
332 }
333
334
335
336 /*
337 WindingFromDrawSurf()
338 creates a winding from a surface's verts
339 */
340
341 winding_t *WindingFromDrawSurf( mapDrawSurface_t *ds ){
342 winding_t *w;
343 int i;
344
345 // we use the first point of the surface, maybe something more clever would be useful
346 // (actually send the whole draw surface would be cool?)
347 if ( ds->numVerts >= MAX_POINTS_ON_WINDING ) {
348 int max = ds->numVerts;
349 vec3_t p[256];
350
351 if ( max > 256 ) {
352 max = 256;
353 }
354
355 for ( i = 0 ; i < max ; i++ ) {
356 VectorCopy( ds->verts[i].xyz, p[i] );
357 }
358
359 xml_Winding( "WindingFromDrawSurf failed: MAX_POINTS_ON_WINDING exceeded", p, max, qtrue );
360 }
361
362 w = AllocWinding( ds->numVerts );
363 w->numpoints = ds->numVerts;
364 for ( i = 0 ; i < ds->numVerts ; i++ ) {
365 VectorCopy( ds->verts[i].xyz, w->p[i] );
366 }
367 return w;
368 }
369
370
371
372 /*
373 ChopFaceSurfaceByBrush()
374 chops up a face drawsurface by a fog brush, with a potential fragment left inside
375 */
376
377 qboolean ChopFaceSurfaceByBrush( entity_t *e, mapDrawSurface_t *ds, brush_t *b ){
378 int i, j;
379 side_t *s;
380 plane_t *plane;
381 winding_t *w;
382 winding_t *front, *back;
383 winding_t *outside[ MAX_BRUSH_SIDES ];
384 int numOutside;
385 mapDrawSurface_t *newds;
386
387
388 /* dummy check */
389 if ( ds->sideRef == NULL || ds->sideRef->side == NULL ) {
390 return qfalse;
391 }
392
393 /* initial setup */
394 w = WindingFromDrawSurf( ds );
395 numOutside = 0;
396
397 /* chop by each brush side */
398 for ( i = 0; i < b->numsides; i++ )
399 {
400 /* get brush side and plane */
401 s = &b->sides[ i ];
402 plane = &mapplanes[ s->planenum ];
403
404 /* handle coplanar outfacing (don't fog) */
405 if ( ds->sideRef->side->planenum == s->planenum ) {
406 return qfalse;
407 }
408
409 /* handle coplanar infacing (keep inside) */
410 if ( ( ds->sideRef->side->planenum ^ 1 ) == s->planenum ) {
411 continue;
412 }
413
414 /* general case */
415 ClipWindingEpsilonStrict( w, plane->normal, plane->dist, ON_EPSILON, &front, &back ); /* strict; if plane is "almost identical" to face, both ways to continue can be wrong, so we better not fog it */
416 FreeWinding( w );
417
418 if ( back == NULL ) {
419 /* nothing actually contained inside */
420 for ( j = 0; j < numOutside; j++ )
421 FreeWinding( outside[ j ] );
422 return qfalse;
423 }
424
425 if ( front != NULL ) {
426 if ( numOutside == MAX_BRUSH_SIDES ) {
427 Error( "MAX_BRUSH_SIDES" );
428 }
429 outside[ numOutside ] = front;
430 numOutside++;
431 }
432
433 w = back;
434 }
435
436 /* fixme: celshaded surface fragment errata */
437
438 /* all of outside fragments become seperate drawsurfs */
439 numFogFragments += numOutside;
440 s = ds->sideRef->side;
441 for ( i = 0; i < numOutside; i++ )
442 {
443 newds = DrawSurfaceForSide( e, ds->mapBrush, s, outside[ i ] );
444 newds->fogNum = ds->fogNum;
445 FreeWinding( outside[ i ] );
446 }
447
448 /* ydnar: the old code neglected to snap to 0.125 for the fragment
449 inside the fog brush, leading to sparklies. this new code does
450 the right thing and uses the original surface's brush side */
451
452 /* build a drawsurf for it */
453 newds = DrawSurfaceForSide( e, ds->mapBrush, s, w );
454 if ( newds == NULL ) {
455 return qfalse;
456 }
457
458 /* copy new to original */
459 ClearSurface( ds );
460 memcpy( ds, newds, sizeof( mapDrawSurface_t ) );
461
462 /* didn't really add a new drawsurface... :) */
463 numMapDrawSurfs--;
464
465 /* return ok */
466 return qtrue;
467 }
468
469
470
471 /*
472 FogDrawSurfaces()
473 call after the surface list has been pruned, before tjunction fixing
474 */
475
476 void FogDrawSurfaces( entity_t *e ){
477 int i, j, k, fogNum;
478 fog_t *fog;
479 mapDrawSurface_t *ds;
480 vec3_t mins, maxs;
481 int fogged, numFogged;
482 int numBaseDrawSurfs;
483
484
485 /* note it */
486 Sys_FPrintf( SYS_VRB, "----- FogDrawSurfs -----\n" );
487
488 /* reset counters */
489 numFogged = 0;
490 numFogFragments = 0;
491
492 /* walk fog list */
493 for ( fogNum = 0; fogNum < numMapFogs; fogNum++ )
494 {
495 /* get fog */
496 fog = &mapFogs[ fogNum ];
497
498 /* clip each surface into this, but don't clip any of the resulting fragments to the same brush */
499 numBaseDrawSurfs = numMapDrawSurfs;
500 for ( i = 0; i < numBaseDrawSurfs; i++ )
501 {
502 /* get the drawsurface */
503 ds = &mapDrawSurfs[ i ];
504
505 /* no fog? */
506 if ( ds->shaderInfo->noFog ) {
507 continue;
508 }
509
510 /* global fog doesn't have a brush */
511 if ( fog->brush == NULL ) {
512 /* don't re-fog already fogged surfaces */
513 if ( ds->fogNum >= 0 ) {
514 continue;
515 }
516 fogged = 1;
517 }
518 else
519 {
520 /* find drawsurface bounds */
521 ClearBounds( mins, maxs );
522 for ( j = 0; j < ds->numVerts; j++ )
523 AddPointToBounds( ds->verts[ j ].xyz, mins, maxs );
524
525 /* check against the fog brush */
526 for ( k = 0; k < 3; k++ )
527 {
528 if ( mins[ k ] > fog->brush->maxs[ k ] ) {
529 break;
530 }
531 if ( maxs[ k ] < fog->brush->mins[ k ] ) {
532 break;
533 }
534 }
535
536 /* no intersection? */
537 if ( k < 3 ) {
538 continue;
539 }
540
541 /* ydnar: gs mods: handle the various types of surfaces */
542 switch ( ds->type )
543 {
544 /* handle brush faces */
545 case SURFACE_FACE:
546 fogged = ChopFaceSurfaceByBrush( e, ds, fog->brush );
547 break;
548
549 /* handle patches */
550 case SURFACE_PATCH:
551 fogged = ChopPatchSurfaceByBrush( e, ds, fog->brush );
552 break;
553
554 /* handle triangle surfaces (fixme: split triangle surfaces) */
555 case SURFACE_TRIANGLES:
556 case SURFACE_FORCED_META:
557 case SURFACE_META:
558 fogged = 1;
559 break;
560
561 /* no fogging */
562 default:
563 fogged = 0;
564 break;
565 }
566 }
567
568 /* is this surface fogged? */
569 if ( fogged ) {
570 numFogged += fogged;
571 ds->fogNum = fogNum;
572 }
573 }
574 }
575
576 /* emit some statistics */
577 Sys_FPrintf( SYS_VRB, "%9d fog polygon fragments\n", numFogFragments );
578 Sys_FPrintf( SYS_VRB, "%9d fog patch fragments\n", numFogPatchFragments );
579 Sys_FPrintf( SYS_VRB, "%9d fogged drawsurfs\n", numFogged );
580 }
581
582
583
584 /*
585 FogForPoint() - ydnar
586 gets the fog number for a point in space
587 */
588
589 int FogForPoint( vec3_t point, float epsilon ){
590 int fogNum, i, j;
591 float dot;
592 qboolean inside;
593 brush_t *brush;
594 plane_t *plane;
595
596
597 /* start with bogus fog num */
598 fogNum = defaultFogNum;
599
600 /* walk the list of fog volumes */
601 for ( i = 0; i < numMapFogs; i++ )
602 {
603 /* sof2: global fog doesn't reference a brush */
604 if ( mapFogs[ i ].brush == NULL ) {
605 fogNum = i;
606 continue;
607 }
608
609 /* get fog brush */
610 brush = mapFogs[ i ].brush;
611
612 /* check point against all planes */
613 inside = qtrue;
614 for ( j = 0; j < brush->numsides && inside; j++ )
615 {
616 plane = &mapplanes[ brush->sides[ j ].planenum ]; /* note usage of map planes here */
617 dot = DotProduct( point, plane->normal );
618 dot -= plane->dist;
619 if ( dot > epsilon ) {
620 inside = qfalse;
621 }
622 }
623
624 /* if inside, return the fog num */
625 if ( inside ) {
626 //% Sys_Printf( "FogForPoint: %f, %f, %f in fog %d\n", point[ 0 ], point[ 1 ], point[ 2 ], i );
627 return i;
628 }
629 }
630
631 /* if the point made it this far, it's not inside any fog volumes (or inside global fog) */
632 return fogNum;
633 }
634
635
636
637 /*
638 FogForBounds() - ydnar
639 gets the fog number for a bounding box
640 */
641
642 int FogForBounds( vec3_t mins, vec3_t maxs, float epsilon ){
643 int fogNum, i, j;
644 float highMin, lowMax, volume, bestVolume;
645 vec3_t fogMins, fogMaxs, overlap;
646 brush_t *brush;
647
648
649 /* start with bogus fog num */
650 fogNum = defaultFogNum;
651
652 /* init */
653 bestVolume = 0.0f;
654
655 /* walk the list of fog volumes */
656 for ( i = 0; i < numMapFogs; i++ )
657 {
658 /* sof2: global fog doesn't reference a brush */
659 if ( mapFogs[ i ].brush == NULL ) {
660 fogNum = i;
661 continue;
662 }
663
664 /* get fog brush */
665 brush = mapFogs[ i ].brush;
666
667 /* get bounds */
668 fogMins[ 0 ] = brush->mins[ 0 ] - epsilon;
669 fogMins[ 1 ] = brush->mins[ 1 ] - epsilon;
670 fogMins[ 2 ] = brush->mins[ 2 ] - epsilon;
671 fogMaxs[ 0 ] = brush->maxs[ 0 ] + epsilon;
672 fogMaxs[ 1 ] = brush->maxs[ 1 ] + epsilon;
673 fogMaxs[ 2 ] = brush->maxs[ 2 ] + epsilon;
674
675 /* check against bounds */
676 for ( j = 0; j < 3; j++ )
677 {
678 if ( mins[ j ] > fogMaxs[ j ] || maxs[ j ] < fogMins[ j ] ) {
679 break;
680 }
681 highMin = mins[ j ] > fogMins[ j ] ? mins[ j ] : fogMins[ j ];
682 lowMax = maxs[ j ] < fogMaxs[ j ] ? maxs[ j ] : fogMaxs[ j ];
683 overlap[ j ] = lowMax - highMin;
684 if ( overlap[ j ] < 1.0f ) {
685 overlap[ j ] = 1.0f;
686 }
687 }
688
689 /* no overlap */
690 if ( j < 3 ) {
691 continue;
692 }
693
694 /* get volume */
695 volume = overlap[ 0 ] * overlap[ 1 ] * overlap[ 2 ];
696
697 /* test against best volume */
698 if ( volume > bestVolume ) {
699 bestVolume = volume;
700 fogNum = i;
701 }
702 }
703
704 /* if the point made it this far, it's not inside any fog volumes (or inside global fog) */
705 return fogNum;
706 }
707
708
709
710 /*
711 CreateMapFogs() - ydnar
712 generates a list of map fogs
713 */
714
715 void CreateMapFogs( void ){
716 int i, j;
717 entity_t *entity;
718 brush_t *brush;
719 fog_t *fog;
720 vec3_t invFogDir;
721 const char *globalFog;
722
723
724 /* skip? */
725 if ( nofog ) {
726 return;
727 }
728
729 /* note it */
730 Sys_FPrintf( SYS_VRB, "--- CreateMapFogs ---\n" );
731
732 /* walk entities */
733 for ( i = 0; i < numEntities; i++ )
734 {
735 /* get entity */
736 entity = &entities[ i ];
737
738 /* walk entity brushes */
739 for ( brush = entity->brushes; brush != NULL; brush = brush->next )
740 {
741 /* ignore non-fog brushes */
742 if ( brush->contentShader->fogParms == qfalse ) {
743 continue;
744 }
745
746 /* test limit */
747 if ( numMapFogs >= MAX_MAP_FOGS ) {
748 Error( "Exceeded MAX_MAP_FOGS (%d)", MAX_MAP_FOGS );
749 }
750
751 /* set up fog */
752 fog = &mapFogs[ numMapFogs++ ];
753 fog->si = brush->contentShader;
754 fog->brush = brush;
755 fog->visibleSide = -1;
756
757 /* if shader specifies an explicit direction, then find a matching brush side with an opposed normal */
758 if ( VectorLength( fog->si->fogDir ) ) {
759 /* flip it */
760 VectorScale( fog->si->fogDir, -1.0f, invFogDir );
761
762 /* find the brush side */
763 for ( j = 0; j < brush->numsides; j++ )
764 {
765 if ( VectorCompare( invFogDir, mapplanes[ brush->sides[ j ].planenum ].normal ) ) {
766 fog->visibleSide = j;
767 //% Sys_Printf( "Brush num: %d Side num: %d\n", fog->brushNum, fog->visibleSide );
768 break;
769 }
770 }
771 }
772 }
773 }
774
775 /* ydnar: global fog */
776 globalFog = ValueForKey( &entities[ 0 ], "_fog" );
777 if ( globalFog[ 0 ] == '\0' ) {
778 globalFog = ValueForKey( &entities[ 0 ], "fog" );
779 }
780 if ( globalFog[ 0 ] != '\0' ) {
781 /* test limit */
782 if ( numMapFogs >= MAX_MAP_FOGS ) {
783 Error( "Exceeded MAX_MAP_FOGS (%d) trying to add global fog", MAX_MAP_FOGS );
784 }
785
786 /* note it */
787 Sys_FPrintf( SYS_VRB, "Map has global fog shader %s\n", globalFog );
788
789 /* set up fog */
790 fog = &mapFogs[ numMapFogs++ ];
791 fog->si = ShaderInfoForShaderNull( globalFog );
792 if ( fog->si == NULL ) {
793 Error( "Invalid shader \"%s\" referenced trying to add global fog", globalFog );
794 }
795 fog->brush = NULL;
796 fog->visibleSide = -1;
797
798 /* set as default fog */
799 defaultFogNum = numMapFogs - 1;
800
801 /* mark all worldspawn brushes as fogged */
802 for ( brush = entities[ 0 ].brushes; brush != NULL; brush = brush->next )
803 ApplySurfaceParm( "fog", &brush->contentFlags, NULL, &brush->compileFlags );
804 }
805
806 /* emit some stats */
807 Sys_FPrintf( SYS_VRB, "%9d fogs\n", numMapFogs );
808 }