diff --git a/tools/quake3/q3map2/bsp.cpp b/tools/quake3/q3map2/bsp.cpp index e09007de..4352ac16 100644 --- a/tools/quake3/q3map2/bsp.cpp +++ b/tools/quake3/q3map2/bsp.cpp @@ -411,6 +411,7 @@ static void ProcessWorldModel( entity_t& e ){ /* get specifics */ const Vector3 origin( light.vectorForKey( "origin" ) ); Vector3 color( light.vectorForKey( "_color" ) ); + ColorFromSRGB( color ); const int lightStyle = light.intForKey( "_style", "style" ); Vector3 normal; @@ -427,12 +428,6 @@ static void ProcessWorldModel( entity_t& e ){ normal = -g_vector3_axis_z; } - if ( colorsRGB ) { - color[0] = Image_LinearFloatFromsRGBFloat( color[0] ); - color[1] = Image_LinearFloatFromsRGBFloat( color[1] ); - color[2] = Image_LinearFloatFromsRGBFloat( color[2] ); - } - /* create the flare surface (note shader defaults automatically) */ DrawSurfaceForFlare( e.mapEntityNum, origin, normal, color, flareShader, lightStyle ); } diff --git a/tools/quake3/q3map2/light.cpp b/tools/quake3/q3map2/light.cpp index 9ec46bc9..983278b9 100644 --- a/tools/quake3/q3map2/light.cpp +++ b/tools/quake3/q3map2/light.cpp @@ -460,11 +460,7 @@ static void CreateEntityLights(){ /* set light color */ if ( e.read_keyvalue( light.color, "_color" ) ) { - if ( colorsRGB ) { - light.color[0] = Image_LinearFloatFromsRGBFloat( light.color[0] ); - light.color[1] = Image_LinearFloatFromsRGBFloat( light.color[1] ); - light.color[2] = Image_LinearFloatFromsRGBFloat( light.color[2] ); - } + ColorFromSRGB( light.color ); if ( !( light.flags & LightFlags::Unnormalized ) ) { ColorNormalize( light.color ); } @@ -1956,18 +1952,13 @@ static void LightWorld( bool fastAllocate, bool bounceStore ){ /* find the optional minimum lighting values */ color = entities[ 0 ].vectorForKey( "_color" ); - if ( colorsRGB ) { - color[0] = Image_LinearFloatFromsRGBFloat( color[0] ); - color[1] = Image_LinearFloatFromsRGBFloat( color[1] ); - color[2] = Image_LinearFloatFromsRGBFloat( color[2] ); - } - if ( vector3_length( color ) == 0.0f ) { + if ( color == g_vector3_identity ) color.set( 1 ); - } + else + ColorFromSRGB( color ); /* ambient */ - f = entities[ 0 ].floatForKey( "_ambient", "ambient" ); - ambientColor = color * f; + ambientColor = color * entities[ 0 ].floatForKey( "_ambient", "ambient" ); /* minvertexlight */ if ( ( minVertex = entities[ 0 ].read_keyvalue( f, "_minvertexlight" ) ) ) { diff --git a/tools/quake3/q3map2/light_ydnar.cpp b/tools/quake3/q3map2/light_ydnar.cpp index 0a2c823a..15b242ba 100644 --- a/tools/quake3/q3map2/light_ydnar.cpp +++ b/tools/quake3/q3map2/light_ydnar.cpp @@ -3664,22 +3664,20 @@ static Vector3 floodVectors[ FLOODLIGHT_NUM_VECTORS ]; static int numFloodVectors = 0; void SetupFloodLight(){ - int i, j; - float angle, elevation, angleStep, elevationStep; - /* note it */ Sys_FPrintf( SYS_VRB, "--- SetupFloodLight ---\n" ); /* calculate angular steps */ - angleStep = degrees_to_radians( 360.0f / FLOODLIGHT_NUM_ANGLE_STEPS ); - elevationStep = degrees_to_radians( FLOODLIGHT_CONE_ANGLE / FLOODLIGHT_NUM_ELEVATION_STEPS ); + const float angleStep = degrees_to_radians( 360.0f / FLOODLIGHT_NUM_ANGLE_STEPS ); + const float elevationStep = degrees_to_radians( FLOODLIGHT_CONE_ANGLE / FLOODLIGHT_NUM_ELEVATION_STEPS ); /* iterate angle */ - angle = 0.0f; - for ( i = 0, angle = 0.0f; i < FLOODLIGHT_NUM_ANGLE_STEPS; ++i, angle += angleStep ) + float angle = 0.0f; + for ( int i = 0; i < FLOODLIGHT_NUM_ANGLE_STEPS; ++i, angle += angleStep ) { /* iterate elevation */ - for ( j = 0, elevation = elevationStep * 0.5f; j < FLOODLIGHT_NUM_ELEVATION_STEPS; ++j, elevation += elevationStep ) + float elevation = elevationStep * 0.5f; + for ( int j = 0; j < FLOODLIGHT_NUM_ELEVATION_STEPS; ++j, elevation += elevationStep ) { floodVectors[ numFloodVectors ][ 0 ] = sin( elevation ) * cos( angle ); floodVectors[ numFloodVectors ][ 1 ] = sin( elevation ) * sin( angle ); @@ -3692,8 +3690,7 @@ void SetupFloodLight(){ Sys_FPrintf( SYS_VRB, "%9d numFloodVectors\n", numFloodVectors ); /* floodlight */ - const char *value; - if ( entities[ 0 ].read_keyvalue( value, "_floodlight" ) ) { + if ( const char *value; entities[ 0 ].read_keyvalue( value, "_floodlight" ) ) { double v1, v2, v3, v4, v5, v6; v1 = v2 = v3 = 0; v4 = floodlightDistance; @@ -3704,23 +3701,13 @@ void SetupFloodLight(){ floodlightRGB = Vector3( v1, v2, v3 ); - if ( vector3_length( floodlightRGB ) == 0 ) { + if ( floodlightRGB == g_vector3_identity ) { floodlightRGB = { 0.94, 0.94, 1.0 }; } - if ( v4 < 1 ) { - v4 = 1024; - } - if ( v5 < 1 ) { - v5 = 128; - } - if ( v6 < 0 ) { - v6 = 1; - } - - floodlightDistance = v4; - floodlightIntensity = v5; - floodlightDirectionScale = v6; + floodlightDistance = v4 < 1? 1024 : v4; + floodlightIntensity = v5 < 1? 128 : v5; + floodlightDirectionScale = v6 < 0? 1 : v6; floodlighty = true; Sys_Printf( "FloodLighting enabled via worldspawn _floodlight key.\n" ); @@ -3729,11 +3716,7 @@ void SetupFloodLight(){ { floodlightRGB = { 0.94, 0.94, 1.0 }; } - if ( colorsRGB ) { - floodlightRGB[0] = Image_LinearFloatFromsRGBFloat( floodlightRGB[0] ); - floodlightRGB[1] = Image_LinearFloatFromsRGBFloat( floodlightRGB[1] ); - floodlightRGB[2] = Image_LinearFloatFromsRGBFloat( floodlightRGB[2] ); - } + ColorFromSRGB( floodlightRGB ); ColorNormalize( floodlightRGB ); } diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index f3e5bbc1..73fe1765 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -2189,3 +2189,11 @@ inline std::vector bspAds; #define Image_LinearFloatFromsRGBFloat( c ) ( ( ( c ) <= 0.04045f ) ? ( c ) * ( 1.0f / 12.92f ) : (float)pow( ( ( c ) + 0.055f ) * ( 1.0f / 1.055f ), 2.4f ) ) #define Image_sRGBFloatFromLinearFloat( c ) ( ( ( c ) < 0.0031308f ) ? ( c ) * 12.92f : 1.055f * (float)pow( ( c ), 1.0f / 2.4f ) - 0.055f ) + +inline void ColorFromSRGB( Vector3& color ){ + if ( colorsRGB ) { + color[0] = Image_LinearFloatFromsRGBFloat( color[0] ); + color[1] = Image_LinearFloatFromsRGBFloat( color[1] ); + color[2] = Image_LinearFloatFromsRGBFloat( color[2] ); + } +} diff --git a/tools/quake3/q3map2/shaders.cpp b/tools/quake3/q3map2/shaders.cpp index ab033164..b6d21f2d 100644 --- a/tools/quake3/q3map2/shaders.cpp +++ b/tools/quake3/q3map2/shaders.cpp @@ -1064,11 +1064,7 @@ static void ParseShaderFile( const char *filename ){ text.GetToken( false ); sun.color[ 2 ] = atof( token ); - if ( colorsRGB ) { - sun.color[0] = Image_LinearFloatFromsRGBFloat( sun.color[0] ); - sun.color[1] = Image_LinearFloatFromsRGBFloat( sun.color[1] ); - sun.color[2] = Image_LinearFloatFromsRGBFloat( sun.color[2] ); - } + ColorFromSRGB( sun.color ); /* normalize it */ ColorNormalize( sun.color ); @@ -1236,11 +1232,7 @@ static void ParseShaderFile( const char *filename ){ si.color[ 1 ] = atof( token ); text.GetToken( false ); si.color[ 2 ] = atof( token ); - if ( colorsRGB ) { - si.color[0] = Image_LinearFloatFromsRGBFloat( si.color[0] ); - si.color[1] = Image_LinearFloatFromsRGBFloat( si.color[1] ); - si.color[2] = Image_LinearFloatFromsRGBFloat( si.color[2] ); - } + ColorFromSRGB( si.color ); ColorNormalize( si.color ); } @@ -1273,11 +1265,7 @@ static void ParseShaderFile( const char *filename ){ si.floodlightIntensity = atof( token ); text.GetToken( false ); si.floodlightDirectionScale = atof( token ); - if ( colorsRGB ) { - si.floodlightRGB[0] = Image_LinearFloatFromsRGBFloat( si.floodlightRGB[0] ); - si.floodlightRGB[1] = Image_LinearFloatFromsRGBFloat( si.floodlightRGB[1] ); - si.floodlightRGB[2] = Image_LinearFloatFromsRGBFloat( si.floodlightRGB[2] ); - } + ColorFromSRGB( si.floodlightRGB ); ColorNormalize( si.floodlightRGB ); }