]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - tools/quake3/q3map2/light_shadows.c
transfer from internal tree r5311 branches/1.4-gpl
[xonotic/netradiant.git] / tools / quake3 / q3map2 / light_shadows.c
1 /*\r
2 Copyright (C) 1999-2007 id Software, Inc. and contributors.\r
3 For a list of contributors, see the accompanying CONTRIBUTORS file.\r
4 \r
5 This file is part of GtkRadiant.\r
6 \r
7 GtkRadiant is free software; you can redistribute it and/or modify\r
8 it under the terms of the GNU General Public License as published by\r
9 the Free Software Foundation; either version 2 of the License, or\r
10 (at your option) any later version.\r
11 \r
12 GtkRadiant is distributed in the hope that it will be useful,\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15 GNU General Public License for more details.\r
16 \r
17 You should have received a copy of the GNU General Public License\r
18 along with GtkRadiant; if not, write to the Free Software\r
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
20 */\r
21 \r
22 #define LIGHT_SHADOWS_C\r
23 \r
24 #include "light.h"\r
25 #include "inout.h"\r
26 \r
27 \r
28 \r
29 /* -------------------------------------------------------------------------------\r
30 \r
31 ydnar: this code deals with shadow volume bsps\r
32 \r
33 ------------------------------------------------------------------------------- */\r
34 \r
35 typedef struct shadowNode_s\r
36 {\r
37         vec4_t  plane;\r
38         int             children[ 2 ];\r
39 }\r
40 shadowNode_t;\r
41 \r
42 int                             numShadowNodes;\r
43 shadowNode_t    *shadowNodes;\r
44 \r
45 \r
46 \r
47 /*\r
48 AddShadow()\r
49 adds a shadow, returning the index into the shadow list\r
50 */\r
51 \r
52 \r
53 \r
54 /*\r
55 MakeShadowFromPoints()\r
56 creates a shadow volume from 4 points (the first being the light origin)\r
57 */\r
58 \r
59 \r
60 \r
61 /*\r
62 SetupShadows()\r
63 sets up the shadow volumes for all lights in the world\r
64 */\r
65 \r
66 void SetupShadows( void )\r
67 {\r
68         int                             i, j, s;\r
69         light_t                 *light;\r
70         dleaf_t                 *leaf;\r
71         dsurface_t              *ds;\r
72         surfaceInfo_t   *info;\r
73         shaderInfo_t    *si;\r
74         byte                    *tested;\r
75 \r
76         \r
77         /* early out for weird cases where there are no lights */\r
78         if( lights == NULL )\r
79                 return;\r
80         \r
81         /* note it */\r
82         Sys_FPrintf( SYS_VRB, "--- SetupShadows ---\n" );\r
83         \r
84         /* allocate a surface test list */\r
85         tested = safe_malloc( numDrawSurfaces / 8 + 1 );\r
86         \r
87         /* walk the list of lights */\r
88         for( light = lights; light != NULL; light = light->next )\r
89         {\r
90                 /* do some early out testing */\r
91                 if( light->cluster < 0 )\r
92                         continue;\r
93                 \r
94                 /* clear surfacetest list */\r
95                 memset( tested, 0, numDrawSurfaces / 8 + 1 );\r
96                 \r
97                 /* walk the bsp leaves */\r
98                 for( i = 0, leaf = dleafs; i < numleafs; i++, leaf++ )\r
99                 {\r
100                         /* in pvs? */\r
101                         if( ClusterVisible( light->cluster, leaf->cluster ) == qfalse )\r
102                                 continue;\r
103                         \r
104                         /* walk the surface list for this leaf */\r
105                         for( j = 0; j < leaf->numLeafSurfaces; j++ )\r
106                         {\r
107                                 /* don't filter a surface more than once */\r
108                                 s = dleafsurfaces[ leaf->firstLeafSurface + j ];\r
109                                 if( tested[ s >> 3 ] & (1 << (s & 7)) )\r
110                                         continue;\r
111                                 tested[ s >> 3 ] |= (1 << (s & 7));\r
112                                 \r
113                                 /* get surface and info */\r
114                                 ds = &drawSurfaces[ s ];\r
115                                 info = &surfaceInfos[ s ];\r
116                                 si = info->si;\r
117                                 \r
118                                 /* don't create shadow volumes from translucent surfaces */\r
119                                 if( si->contents & CONTENTS_TRANSLUCENT )\r
120                                         continue;\r
121                         }\r
122                 }\r
123         }\r
124 }