From: Rudolf Polzer Date: Tue, 6 Apr 2010 15:03:50 +0000 (+0200) Subject: new option -extradist to improve lighting a bit, also a light entity field _extradist... X-Git-Tag: xonotic-v0.5.0~273 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=commitdiff_plain;h=99342abdf7de0407f481e288aceae87033c378f7 new option -extradist to improve lighting a bit, also a light entity field _extradist of the same purpose --- diff --git a/tools/quake3/q3map2/light.c b/tools/quake3/q3map2/light.c index deff9677..6c8eb96a 100644 --- a/tools/quake3/q3map2/light.c +++ b/tools/quake3/q3map2/light.c @@ -401,6 +401,10 @@ void CreateEntityLights( void ) else light->color[ 0 ] = light->color[ 1 ] = light->color[ 2 ] = 1.0f; + light->extraDist = FloatForKey( e, "_extradist" ); + if(light->extraDist == 0.0f) + light->extraDist = extraDist; + intensity = intensity * pointScale; light->photons = intensity; @@ -821,6 +825,12 @@ int LightContributionToSample( trace_t *trace ) else if( angle < 0.0f && (trace->twoSided || (light->flags & LIGHT_TWOSIDED)) ) angle = -angle; + + /* clamp the distance to prevent super hot spots */ + dist = sqrt(dist * dist + light->extraDist * light->extraDist); + if( dist < 16.0f ) + dist = 16.0f; + add = light->photons / (dist * dist) * angle; } else @@ -859,11 +869,12 @@ int LightContributionToSample( trace_t *trace ) dist = SetupTrace( trace ); if( dist >= light->envelope ) return 0; - + /* clamp the distance to prevent super hot spots */ + dist = sqrt(dist * dist + light->extraDist * light->extraDist); if( dist < 16.0f ) dist = 16.0f; - + /* angle attenuation */ if( light->flags & LIGHT_ATTEN_ANGLE ) { @@ -907,7 +918,7 @@ int LightContributionToSample( trace_t *trace ) add = 0.0f; } else - add = light->photons / (dist * dist) * angle; + add = (light->photons / (dist * dist)) * angle; /* handle spotlights */ if( light->type == EMIT_SPOT ) @@ -1156,9 +1167,10 @@ int LightContributionToPoint( trace_t *trace ) if( light->type == EMIT_AREA && faster ) { /* clamp the distance to prevent super hot spots */ + dist = sqrt(dist * dist + light->extraDist * light->extraDist); if( dist < 16.0f ) dist = 16.0f; - + /* attenuate */ add = light->photons / (dist * dist); } @@ -1202,6 +1214,7 @@ int LightContributionToPoint( trace_t *trace ) else if( light->type == EMIT_POINT || light->type == EMIT_SPOT ) { /* clamp the distance to prevent super hot spots */ + dist = sqrt(dist * dist + light->extraDist * light->extraDist); if( dist < 16.0f ) dist = 16.0f; @@ -2227,6 +2240,15 @@ int LightMain( int argc, char **argv ) wolfLight = qfalse; Sys_Printf( "Enabling Quake 3 lighting model (nonlinear default)\n" ); } + + else if( !strcmp( argv[ i ], "-extradist" ) ) + { + extraDist = atof( argv[ i + 1 ] ); + if( extraDist < 0 ) + extraDist = 0; + i++; + Sys_Printf( "Default extra radius set to %f units\n", extraDist ); + } else if( !strcmp( argv[ i ], "-sunonly" ) ) { diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 498f656b..5db3b8cd 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -1304,6 +1304,7 @@ typedef struct light_s float radiusByDist; /* for spotlights */ float fade; /* ydnar: from wolf, for linear lights */ float angleScale; /* ydnar: stolen from vlight for K */ + float extraDist; /* "extra dimension" distance of the light, to kill hot spots */ float add; /* ydnar: used for area lights */ float envelope; /* ydnar: units until falloff < tolerance */ @@ -2141,6 +2142,7 @@ light global variables /* commandline arguments */ Q_EXTERN qboolean wolfLight Q_ASSIGN( qfalse ); +Q_EXTERN float extraDist Q_ASSIGN( 0.0f ); Q_EXTERN qboolean loMem Q_ASSIGN( qfalse ); Q_EXTERN qboolean noStyles Q_ASSIGN( qfalse ); Q_EXTERN qboolean keepLights Q_ASSIGN( qfalse );