From 858ec974f7ec9ca14fdf6266ce4b80d9c0515168 Mon Sep 17 00:00:00 2001 From: Garux Date: Mon, 8 Mar 2021 13:34:58 +0300 Subject: [PATCH] * -saturation light switch, default = 1, affects lightmaps and vertex color; > 1 = saturate, 0 = grayscale, < 0 = complementary colors --- Makefile | 2 -- tools/quake3/q3map2/light.cpp | 7 +++++++ tools/quake3/q3map2/light_ydnar.cpp | 18 ++++++++++++++++++ tools/quake3/q3map2/q3map2.h | 1 + 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 6f1f7236..5b873069 100644 --- a/Makefile +++ b/Makefile @@ -583,7 +583,6 @@ $(INSTALLDIR)/q3map2.$(EXE): \ libddslib.$(A) \ libfilematch.$(A) \ libl_net.$(A) \ - libmathlib.$(A) \ libpicomodel.$(A) \ $(if $(findstring $(OS),Win32),icons/q3map2.o,) \ @@ -749,7 +748,6 @@ $(INSTALLDIR)/radiant.$(EXE): \ libcmdlib.$(A) \ libgtkutil.$(A) \ libl_net.$(A) \ - libmathlib.$(A) \ libprofile.$(A) \ libquickhull.$(A) \ libxmllib.$(A) \ diff --git a/tools/quake3/q3map2/light.cpp b/tools/quake3/q3map2/light.cpp index b9838264..296fc755 100644 --- a/tools/quake3/q3map2/light.cpp +++ b/tools/quake3/q3map2/light.cpp @@ -2248,6 +2248,13 @@ int LightMain( int argc, char **argv ){ lightmapContrast = ( 259 * ( lightmapContrast + 255 ) ) / ( 255 * ( 259 - lightmapContrast ) ); } + /* Lighting saturation */ + else if( striEqual( argv[ i ], "-saturation" ) ){ + g_lightmapSaturation = atof( argv[ i + 1 ] ); + Sys_Printf( "Lighting saturation set to %f\n", g_lightmapSaturation ); + i++; + } + /* ydnar switches */ else if ( striEqual( argv[ i ], "-bounce" ) ) { bounce = std::max( 0, atoi( argv[ i + 1 ] ) ); diff --git a/tools/quake3/q3map2/light_ydnar.cpp b/tools/quake3/q3map2/light_ydnar.cpp index 9ace44b1..0e60fc60 100644 --- a/tools/quake3/q3map2/light_ydnar.cpp +++ b/tools/quake3/q3map2/light_ydnar.cpp @@ -32,6 +32,21 @@ #include "q3map2.h" +// http://www.graficaobscura.com/matrix/index.html +static void color_saturate( Vector3& color, float saturation ){ + /* This is the luminance vector. Notice here that we do not use the standard NTSC weights of 0.299, 0.587, and 0.114. + The NTSC weights are only applicable to RGB colors in a gamma 2.2 color space. For linear RGB colors these values are better. */ + const Vector3 rgb2gray( 0.3086, 0.6094, 0.0820 ); + Matrix4 tra( g_matrix4_identity ); + tra.x().vec3().set( rgb2gray.x() * ( 1 - saturation ) ); + tra.y().vec3().set( rgb2gray.y() * ( 1 - saturation ) ); + tra.z().vec3().set( rgb2gray.z() * ( 1 - saturation ) ); + tra.xx() += saturation; + tra.yy() += saturation; + tra.zz() += saturation; + matrix4_transform_direction( tra, color ); +} + /* @@ -53,6 +68,9 @@ Vector3b ColorToBytes( const Vector3& color, float scale ){ /* make a local copy */ Vector3 sample = color * scale; + if( g_lightmapSaturation != 1 ) + color_saturate( sample, g_lightmapSaturation ); + /* muck with it */ gamma = 1.0f / lightmapGamma; for ( i = 0; i < 3; i++ ) diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 20300db1..51133f9c 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -2345,6 +2345,7 @@ Q_EXTERN float lightmapExposure Q_ASSIGN( 0.0f ); Q_EXTERN float lightmapCompensate Q_ASSIGN( 1.0f ); Q_EXTERN float lightmapBrightness Q_ASSIGN( 1.0f ); Q_EXTERN float lightmapContrast Q_ASSIGN( 1.0f ); +inline float g_lightmapSaturation = 1; /* ydnar: for runtime tweaking of falloff tolerance */ Q_EXTERN float falloffTolerance Q_ASSIGN( 1.0f );