Merge pull request #1 from Joshua-Ashton/light_surface_fixes
Support for Half-Life styled lights and light_surfaces
This commit is contained in:
commit
011de3563f
1 changed files with 65 additions and 11 deletions
|
@ -208,6 +208,30 @@ static void CreateSkyLights( vec3_t color, float value, int iterations, float fi
|
|||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
stristr()
|
||||
helper to find a substring (case-insensitive)
|
||||
*/
|
||||
|
||||
static const char *stristr(const char *haystack, const char *needle) {
|
||||
char c = tolower(*needle);
|
||||
if (!c) {
|
||||
return haystack;
|
||||
}
|
||||
for (; *haystack; haystack++) {
|
||||
if (tolower(*haystack) == c) {
|
||||
for (size_t i = 1;;i++) {
|
||||
if (!needle[i]) {
|
||||
return haystack;
|
||||
}
|
||||
if (tolower(haystack[i]) != tolower(needle[i])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
@ -222,7 +246,7 @@ void CreateEntityLights( void ){
|
|||
const char *name;
|
||||
const char *target;
|
||||
vec3_t dest;
|
||||
const char *_color;
|
||||
const char *_color, *_light_brightness;
|
||||
float intensity, scale, deviance, filterRadius;
|
||||
int spawnflags, flags, numSamples;
|
||||
qboolean junior;
|
||||
|
@ -340,6 +364,9 @@ void CreateEntityLights( void ){
|
|||
const char *surfacename;
|
||||
|
||||
surfacename = ValueForKey( e, "surfacename" );
|
||||
if ( !surfacename || !surfacename[ 0 ] ) {
|
||||
surfacename = ValueForKey( e, "_tex" );
|
||||
}
|
||||
|
||||
/* loop through all surfaces -eukara */
|
||||
for (int i = 0; i < numBSPDrawSurfaces; i++)
|
||||
|
@ -354,10 +381,19 @@ void CreateEntityLights( void ){
|
|||
int style;
|
||||
float bscale, bsfrac, bsdist;
|
||||
|
||||
if (Q_stricmp(si->shader, surfacename))
|
||||
if (!stristr(si->shader, surfacename))
|
||||
continue;
|
||||
|
||||
_light_brightness = ValueForKey( e, "_light" );
|
||||
if ( _light_brightness && _light_brightness[ 0 ] ) {
|
||||
/* Only the last value, alpha, matters for the brightness
|
||||
* the rest is always dummy values which are meaningless.
|
||||
*/
|
||||
sscanf( _light_brightness, "%*f %*f %*f %f", &lb );
|
||||
}
|
||||
else {
|
||||
lb = FloatForKey( e, "light" );
|
||||
}
|
||||
subd = IntForKey( e, "subdivisions" );
|
||||
style = IntForKey( e, "style" );
|
||||
bscale = FloatForKey( e, "bouncescale" );
|
||||
|
@ -393,6 +429,9 @@ void CreateEntityLights( void ){
|
|||
} else {
|
||||
/* alternative: read color in RGB8 values -eukara */
|
||||
_color = ValueForKey( e, "color255" );
|
||||
if ( !_color || !_color[ 0 ] ) {
|
||||
_color = ValueForKey( e, "_texcolor" );
|
||||
}
|
||||
if ( _color && _color[ 0 ] ) {
|
||||
sscanf( _color, "%f %f %f", &si->color[ 0 ], &si->color[ 1 ], &si->color[ 2 ] );
|
||||
si->color[0] /= 255;
|
||||
|
@ -503,11 +542,31 @@ void CreateEntityLights( void ){
|
|||
Sys_FPrintf( SYS_WRN, "WARNING: Styled light found targeting %s\n **", target );
|
||||
}
|
||||
|
||||
/* default to white color values */
|
||||
light->color[ 0 ] =
|
||||
light->color[ 1 ] =
|
||||
light->color[ 2 ] = 1.0f;
|
||||
|
||||
/* set light intensity */
|
||||
_color = ValueForKey( e, "_light" );
|
||||
if ( _color && _color[0] ) {
|
||||
/* Handle Half-Life styled _light values which
|
||||
* contain color. Otherwise, fallback to _light
|
||||
* being a single float for intensity
|
||||
*/
|
||||
if ( sscanf( _color, "%f %f %f %f", &light->color[ 0 ], &light->color[ 1 ], &light->color[ 2 ], &intensity ) == 4 ) {
|
||||
light->color[ 0 ] /= 255;
|
||||
light->color[ 1 ] /= 255;
|
||||
light->color[ 2 ] /= 255;
|
||||
intensity /= 4;
|
||||
}
|
||||
else {
|
||||
intensity = FloatForKey( e, "_light" );
|
||||
if ( intensity == 0.0f ) {
|
||||
intensity = FloatForKey( e, "light" );
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( intensity == 0.0f ) {
|
||||
intensity = 300.0f;
|
||||
}
|
||||
|
@ -590,11 +649,6 @@ void CreateEntityLights( void ){
|
|||
/*if ( !( light->flags & LIGHT_UNNORMALIZED ) ) {
|
||||
ColorNormalize( light->color, light->color );
|
||||
}*/
|
||||
} else {
|
||||
/* default to white color values */
|
||||
light->color[ 0 ] =
|
||||
light->color[ 1 ] =
|
||||
light->color[ 2 ] = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue