From f68d4836e176af360f6e72011eebd5bd49f7aa19 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Sun, 22 Aug 2021 01:40:40 +0100 Subject: [PATCH 1/2] Support for other formats of light_surface entities In the light_surfaces we want to use, the light brighness is stored in the alpha of _light and the color as color255 in _texcolor. Signed-off-by: Joshua Ashton --- tools/vmap/light.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/tools/vmap/light.c b/tools/vmap/light.c index 987a313..43ac1a8 100644 --- a/tools/vmap/light.c +++ b/tools/vmap/light.c @@ -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; - lb = FloatForKey( e, "light" ); + _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; From fc0e5c3cccbcbd15154808f5c7842bb31a79023c Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Sun, 22 Aug 2021 03:10:27 +0100 Subject: [PATCH 2/2] Handle Half-Life 1 styled point light info This adds support for the vector version of _light, where the first 3 values are the color and the alpha is the intensity. Signed-off-by: Joshua Ashton --- tools/vmap/light.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/tools/vmap/light.c b/tools/vmap/light.c index 43ac1a8..8cf86a8 100644 --- a/tools/vmap/light.c +++ b/tools/vmap/light.c @@ -542,10 +542,30 @@ 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 */ - intensity = FloatForKey( e, "_light" ); - if ( intensity == 0.0f ) { - intensity = FloatForKey( e, "light" ); + _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; @@ -629,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; } }