summaryrefslogtreecommitdiff
path: root/src/sw_light.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sw_light.c')
-rw-r--r--src/sw_light.c168
1 files changed, 81 insertions, 87 deletions
diff --git a/src/sw_light.c b/src/sw_light.c
index 6babb19..80b1231 100644
--- a/src/sw_light.c
+++ b/src/sw_light.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -37,52 +37,48 @@ DYNAMIC LIGHTS
R_MarkLights
=============
*/
-void R_MarkLights (dlight_t *light, int bit, mnode_t *node)
+void R_MarkLights(dlight_t *light, int bit, mnode_t *node)
{
cplane_t *splitplane;
float dist;
mface_t *surf;
int i;
-
+
if (!node->plane)
return;
splitplane = node->plane;
- dist = DotProduct (light->origin, splitplane->normal) - splitplane->dist;
-
+ dist = DotProduct(light->origin, splitplane->normal) - splitplane->dist;
+
//=====
//PGM
- i=light->intensity;
- if(i<0)
- i=-i;
+ i = light->intensity;
+ if (i < 0)
+ i = -i;
//PGM
//=====
- if (dist > i) // PGM (dist > light->intensity)
- {
- R_MarkLights (light, bit, node->children[0]);
+ if (dist > i) { // PGM (dist > light->intensity)
+ R_MarkLights(light, bit, node->children[0]);
return;
}
- if (dist < -i) // PGM (dist < -light->intensity)
- {
- R_MarkLights (light, bit, node->children[1]);
+ if (dist < -i) { // PGM (dist < -light->intensity)
+ R_MarkLights(light, bit, node->children[1]);
return;
}
-
+
// mark the polygons
surf = node->firstface;
- for (i=0 ; i<node->numfaces ; i++, surf++)
- {
- if (surf->dlightframe != r_dlightframecount)
- {
+ for (i = 0; i < node->numfaces; i++, surf++) {
+ if (surf->dlightframe != r_dlightframecount) {
surf->dlightbits = 0;
surf->dlightframe = r_dlightframecount;
}
surf->dlightbits |= bit;
}
- R_MarkLights (light, bit, node->children[0]);
- R_MarkLights (light, bit, node->children[1]);
+ R_MarkLights(light, bit, node->children[0]);
+ R_MarkLights(light, bit, node->children[1]);
}
@@ -91,15 +87,14 @@ void R_MarkLights (dlight_t *light, int bit, mnode_t *node)
R_PushDlights
=============
*/
-void R_PushDlights (mnode_t *headnode)
+void R_PushDlights(mnode_t *headnode)
{
int i;
dlight_t *l;
r_dlightframecount = r_framecount;
- for (i=0, l = r_newrefdef.dlights ; i<r_newrefdef.num_dlights ; i++, l++)
- {
- R_MarkLights ( l, 1 << i, headnode);
+ for (i = 0, l = r_newrefdef.dlights; i < r_newrefdef.num_dlights; i++, l++) {
+ R_MarkLights(l, 1 << i, headnode);
}
}
@@ -112,7 +107,8 @@ LIGHT SAMPLING
=============================================================================
*/
-static qboolean RecursiveLightPoint (vec3_t p, vec3_t color) {
+static qboolean RecursiveLightPoint(vec3_t p, vec3_t color)
+{
mface_t *surf;
int ds, dt;
byte *lightmap;
@@ -125,8 +121,8 @@ static qboolean RecursiveLightPoint (vec3_t p, vec3_t color) {
end[1] = p[1];
end[2] = p[2] - 2048;
- surf = BSP_LightPoint( r_worldmodel->nodes, p, end, &ds, &dt );
- if( !surf ) {
+ surf = BSP_LightPoint(r_worldmodel->nodes, p, end, &ds, &dt);
+ if (!surf) {
return qfalse;
}
@@ -136,11 +132,10 @@ static qboolean RecursiveLightPoint (vec3_t p, vec3_t color) {
lightmap = surf->lightmap;
lightmap += dt * S_MAX(surf) + ds;
- for (maps = 0 ; maps < surf->numstyles ; maps++)
- {
- samp = *lightmap * (1.0/255); // adjust for gl scale
+ for (maps = 0; maps < surf->numstyles; maps++) {
+ samp = *lightmap * (1.0 / 255); // adjust for gl scale
scales = r_newrefdef.lightstyles[surf->styles[maps]].rgb;
- VectorMA (color, samp, scales, color);
+ VectorMA(color, samp, scales, color);
lightmap += S_MAX(surf) * T_MAX(surf);
}
return qtrue;
@@ -151,39 +146,36 @@ static qboolean RecursiveLightPoint (vec3_t p, vec3_t color) {
R_LightPoint
===============
*/
-void R_LightPoint (vec3_t p, vec3_t color)
+void R_LightPoint(vec3_t p, vec3_t color)
{
int lnum;
dlight_t *dl;
float light;
vec3_t dist;
float add;
-
- if (!r_worldmodel || !r_worldmodel->lightmap || !r_newrefdef.lightstyles)
- {
+
+ if (!r_worldmodel || !r_worldmodel->lightmap || !r_newrefdef.lightstyles) {
color[0] = color[1] = color[2] = 1.0;
return;
}
-
- VectorClear( color );
- RecursiveLightPoint (p, color);
+ VectorClear(color);
+
+ RecursiveLightPoint(p, color);
//
// add dynamic lights
//
light = 0;
- for (lnum=0 ; lnum<r_newrefdef.num_dlights ; lnum++)
- {
+ for (lnum = 0; lnum < r_newrefdef.num_dlights; lnum++) {
dl = &r_newrefdef.dlights[lnum];
- VectorSubtract (p,
- dl->origin,
- dist);
+ VectorSubtract(p,
+ dl->origin,
+ dist);
add = dl->intensity - VectorLength(dist);
- add *= (1.0/256);
- if (add > 0)
- {
- VectorMA (color, add, dl->color, color);
+ add *= (1.0 / 256);
+ if (add > 0) {
+ VectorMA(color, add, dl->color, color);
}
}
}
@@ -197,7 +189,8 @@ blocklight_t blocklights[MAX_BLOCKLIGHTS];
R_AddDynamicLights
===============
*/
-static void R_AddDynamicLights( void ) {
+static void R_AddDynamicLights(void)
+{
mface_t *surf;
int lnum;
int sd, td;
@@ -215,57 +208,57 @@ static void R_AddDynamicLights( void ) {
tmax = T_MAX(surf);
tex = surf->texinfo;
- for ( lnum = 0; lnum < r_newrefdef.num_dlights; lnum++ ) {
- if ( !(surf->dlightbits & (1<<lnum) ) )
+ for (lnum = 0; lnum < r_newrefdef.num_dlights; lnum++) {
+ if (!(surf->dlightbits & (1 << lnum)))
continue; // not lit by this light
dl = &r_newrefdef.dlights[lnum];
rad = dl->intensity;
negativeLight = 0;
- if(rad < 0) {
+ if (rad < 0) {
negativeLight = 1;
rad = -rad;
}
- dist = PlaneDiffFast (dl->origin, surf->plane);
+ dist = PlaneDiffFast(dl->origin, surf->plane);
rad -= fabs(dist);
minlight = 32; // dl->minlight;
if (rad < minlight)
continue;
minlight = rad - minlight;
- for (i=0 ; i<3 ; i++) {
- impact[i] = dl->origin[i] - surf->plane->normal[i]*dist;
+ for (i = 0; i < 3; i++) {
+ impact[i] = dl->origin[i] - surf->plane->normal[i] * dist;
}
- local[0] = DotProduct (impact, tex->axis[0]) + tex->offset[0];
- local[1] = DotProduct (impact, tex->axis[1]) + tex->offset[1];
+ local[0] = DotProduct(impact, tex->axis[0]) + tex->offset[0];
+ local[1] = DotProduct(impact, tex->axis[1]) + tex->offset[1];
local[0] -= surf->texturemins[0];
local[1] -= surf->texturemins[1];
-
- for (t = 0 ; t<tmax ; t++) {
- td = local[1] - t*16;
+
+ for (t = 0; t < tmax; t++) {
+ td = local[1] - t * 16;
if (td < 0)
td = -td;
- for (s=0 ; s<smax ; s++) {
- sd = local[0] - s*16;
+ for (s = 0; s < smax; s++) {
+ sd = local[0] - s * 16;
if (sd < 0)
sd = -sd;
/*if (sd > td)
dist = sd + (td>>1);
else
dist = td + (sd>>1);*/
- dist = sqrt( sd * sd + td * td );
- if(!negativeLight) {
+ dist = sqrt(sd * sd + td * td);
+ if (!negativeLight) {
if (dist < minlight)
- blocklights[t*smax + s] += (rad - dist)*256;
+ blocklights[t * smax + s] += (rad - dist) * 256;
} else {
if (dist < minlight)
- blocklights[t*smax + s] -= (rad - dist)*256;
- if(blocklights[t*smax + s] < minlight)
- blocklights[t*smax + s] = minlight;
+ blocklights[t * smax + s] -= (rad - dist) * 256;
+ if (blocklights[t * smax + s] < minlight)
+ blocklights[t * smax + s] = minlight;
}
}
}
@@ -281,7 +274,8 @@ Combine and scale multiple lightmaps into the 8.8 format in blocklights
===============
*/
-void R_BuildLightMap( void ) {
+void R_BuildLightMap(void)
+{
int smax, tmax;
blocklight_t t;
int i, size;
@@ -292,32 +286,32 @@ void R_BuildLightMap( void ) {
surf = r_drawsurf.surf;
- smax = S_MAX( surf );
- tmax = T_MAX( surf );
+ smax = S_MAX(surf);
+ tmax = T_MAX(surf);
size = smax * tmax;
- if( size > MAX_BLOCKLIGHTS ) {
- Com_Error( ERR_DROP, "R_BuildLightMap: surface blocklights size %i > %i", size, MAX_BLOCKLIGHTS );
+ if (size > MAX_BLOCKLIGHTS) {
+ Com_Error(ERR_DROP, "R_BuildLightMap: surface blocklights size %i > %i", size, MAX_BLOCKLIGHTS);
}
// clear to no light
dst = blocklights;
- for( i = 0; i < size; i++ ) {
+ for (i = 0; i < size; i++) {
*dst++ = 0;
}
-
- if( r_fullbright->integer || !r_worldmodel->lightmap ) {
+
+ if (r_fullbright->integer || !r_worldmodel->lightmap) {
return;
}
// add all the lightmaps
lightmap = surf->lightmap;
- if( lightmap ) {
- for( maps = 0; maps < surf->numstyles; maps++ ) {
+ if (lightmap) {
+ for (maps = 0; maps < surf->numstyles; maps++) {
fixed8_t scale;
-
+
dst = blocklights;
- scale = r_drawsurf.lightadj[maps]; // 8.8 fraction
- for( i = 0; i < size; i++ ) {
+ scale = r_drawsurf.lightadj[maps]; // 8.8 fraction
+ for (i = 0; i < size; i++) {
blocklights[i] += lightmap[0] * scale;
lightmap++; dst++;
@@ -326,18 +320,18 @@ void R_BuildLightMap( void ) {
}
// add all the dynamic lights
- if( surf->dlightframe == r_framecount )
+ if (surf->dlightframe == r_framecount)
R_AddDynamicLights();
// bound, invert, and shift
- for( i = 0; i < size; i++ ) {
+ for (i = 0; i < size; i++) {
t = blocklights[i];
- if( t < 0 )
+ if (t < 0)
t = 0;
- t = ( 255 * 256 - t ) >> ( 8 - VID_CBITS );
+ t = (255 * 256 - t) >> (8 - VID_CBITS);
- if( t < ( 1 << 6 ) )
- t = ( 1 << 6 );
+ if (t < (1 << 6))
+ t = (1 << 6);
blocklights[i] = t;
}