@@ -99,48 +99,75 @@ void CL_RunLightStyles( lightstyle_t *ls )
99
99
R_MarkLights
100
100
=============
101
101
*/
102
- void R_MarkLights ( dlight_t * light , int bit , mnode_t * node )
102
+ void R_MarkLights ( const dlight_t * light , int bit , const mnode_t * node )
103
103
{
104
- float dist ;
105
- msurface_t * surf ;
106
- int i ;
104
+ const float virtual_radius = light -> radius * Q_max ( 1.0f , r_dlight_virtual_radius .value );
105
+ const float maxdist = light -> radius * light -> radius ;
106
+ float dist ;
107
+ int i ;
107
108
mnode_t * children [2 ];
108
109
int firstsurface , numsurfaces ;
109
110
111
+ start :
112
+
110
113
if ( !node || node -> contents < 0 )
111
114
return ;
112
115
113
116
dist = PlaneDiff ( light -> origin , node -> plane );
114
117
115
118
node_children ( children , node , RI .currentmodel );
116
- firstsurface = node_firstsurface ( node , RI .currentmodel );
117
- numsurfaces = node_numsurfaces ( node , RI .currentmodel );
118
119
119
- if ( dist > light -> radius )
120
+ if ( dist > virtual_radius )
120
121
{
121
- R_MarkLights ( light , bit , children [0 ] ) ;
122
- return ;
122
+ node = children [0 ];
123
+ goto start ;
123
124
}
124
- if ( dist < - light -> radius )
125
+
126
+ if ( dist < - virtual_radius )
125
127
{
126
- R_MarkLights ( light , bit , children [1 ] ) ;
127
- return ;
128
+ node = children [1 ];
129
+ goto start ;
128
130
}
129
131
130
132
// mark the polygons
131
- surf = RI .currentmodel -> surfaces + firstsurface ;
133
+ firstsurface = node_firstsurface ( node , RI .currentmodel );
134
+ numsurfaces = node_numsurfaces ( node , RI .currentmodel );
132
135
133
- for ( i = 0 ; i < numsurfaces ; i ++ , surf ++ )
136
+ for ( i = 0 ; i < numsurfaces ; i ++ )
134
137
{
135
- if ( !BoundsAndSphereIntersect ( surf -> info -> mins , surf -> info -> maxs , light -> origin , light -> radius ))
136
- continue ; // no intersection
138
+ vec3_t impact ;
139
+ float s , t , l ;
140
+ msurface_t * surf = & RI .currentmodel -> surfaces [firstsurface + i ];
141
+ const mextrasurf_t * info = surf -> info ;
142
+
143
+ if ( surf -> plane -> type < 3 )
144
+ {
145
+ VectorCopy ( light -> origin , impact );
146
+ impact [surf -> plane -> type ] -= dist ;
147
+ }
148
+ else VectorMA ( light -> origin , - dist , surf -> plane -> normal , impact );
149
+
150
+ // a1ba: taken from JoeQuake, but it's probably originated in FitzQuake
151
+ // clamp center of light to corner and check brightness
152
+ l = DotProduct ( impact , info -> lmvecs [0 ] ) + info -> lmvecs [0 ][3 ] - info -> lightmapmins [0 ];
153
+ s = l + 0.5 ;
154
+ s = bound ( 0 , s , info -> lightextents [0 ] );
155
+ s = l - s ;
156
+
157
+ l = DotProduct ( impact , info -> lmvecs [1 ] ) + info -> lmvecs [1 ][3 ] - info -> lightmapmins [1 ];
158
+ t = l + 0.5 ;
159
+ t = bound ( 0 , t , info -> lightextents [1 ] );
160
+ t = l - t ;
161
+
162
+ if ( s * s + t * t + dist * dist >= maxdist )
163
+ continue ;
137
164
138
165
if ( surf -> dlightframe != tr .dlightframecount )
139
166
{
140
- surf -> dlightbits = 0 ;
167
+ surf -> dlightbits = bit ;
141
168
surf -> dlightframe = tr .dlightframecount ;
142
169
}
143
- surf -> dlightbits |= bit ;
170
+ else surf -> dlightbits |= bit ;
144
171
}
145
172
146
173
R_MarkLights ( light , bit , children [0 ] );
0 commit comments