diff --git a/changelog.txt b/changelog.txt index 671587b..377fc42 100644 --- a/changelog.txt +++ b/changelog.txt @@ -79,7 +79,11 @@ add: r_rtColorFormat <0|1|2> (default: 0) selects the color format for render ta r_rtColorFormat 0 = R8G8B8A8 r_rtColorFormat 1 = R10G10B10A2 r_rtColorFormat 2 = R16G16B16A16 - + +add: r_lightmapGreyscale <0.0 to 1.0> (default: 0) to control how monochromatic the lightmaps look + r_lightmapGreyscale 0 = full color (nothing done) + r_lightmapGreyscale 1 = completely monochrome + add: r_mapBrightness now works on q3map2's external lightmap atlas images add: the renderer can now batch surfaces with different (but sufficiently similar) shaders diff --git a/code/renderer/tr_bsp.cpp b/code/renderer/tr_bsp.cpp index beac135..e26d3df 100644 --- a/code/renderer/tr_bsp.cpp +++ b/code/renderer/tr_bsp.cpp @@ -41,13 +41,20 @@ static int lightmapsPerAtlas; static void R_ColorShiftLightingBytesRGB( const byte* in, byte* out ) { - const int scale16 = (int)( r_mapBrightness->value * 65536.0f ); - // scale based on brightness + const int scale16 = (int)( r_mapBrightness->value * 65536.0f ); int r = ( (int)in[0] * scale16 ) >> 16; int g = ( (int)in[1] * scale16 ) >> 16; int b = ( (int)in[2] * scale16 ) >> 16; + // desaturate by moving the channels towards the grey "midpoint" + // credit for the following snippet goes to Jakub 'kubaxvx' Matraszek + const int grey = (r + g + b) / 3; // could use the Rec. 601 or 709 coefficients instead + const int greyscale16 = (int)( r_lightmapGreyscale->value * 65536.0f ); + r = ( ( r << 16 ) + greyscale16 * ( grey - r ) ) >> 16; + g = ( ( g << 16 ) + greyscale16 * ( grey - g ) ) >> 16; + b = ( ( b << 16 ) + greyscale16 * ( grey - b ) ) >> 16; + // normalize by color instead of saturating to white if ( ( r | g | b ) > 255 ) { int max; diff --git a/code/renderer/tr_init.cpp b/code/renderer/tr_init.cpp index e88e5d2..9f9f056 100644 --- a/code/renderer/tr_init.cpp +++ b/code/renderer/tr_init.cpp @@ -60,6 +60,7 @@ cvar_t *r_drawworld; cvar_t *r_speeds; cvar_t *r_fullbright; cvar_t *r_lightmap; +cvar_t *r_lightmapGreyscale; cvar_t *r_novis; cvar_t *r_nocull; cvar_t *r_nocurves; @@ -389,6 +390,7 @@ static const cvarTableItem_t r_cvars[] = { &r_subdivisions, "r_subdivisions", "1", CVAR_ARCHIVE | CVAR_LATCH, CVART_FLOAT, "1", "64", help_r_subdivisions }, { &r_fullbright, "r_fullbright", "0", CVAR_ARCHIVE | CVAR_LATCH, CVART_BOOL, NULL, NULL, help_r_fullbright }, { &r_lightmap, "r_lightmap", "0", CVAR_ARCHIVE | CVAR_LATCH, CVART_BOOL, NULL, NULL, help_r_lightmap }, + { &r_lightmapGreyscale, "r_lightmapGreyscale", "0", CVAR_ARCHIVE | CVAR_LATCH, CVART_FLOAT, "0", "1", "how monochrome the lightmap looks" }, { &r_softSprites, "r_softSprites", "1", CVAR_ARCHIVE | CVAR_LATCH, CVART_BOOL, NULL, NULL, help_r_softSprites }, { &r_gpuMipGen, "r_gpuMipGen", "1", CVAR_ARCHIVE | CVAR_LATCH, CVART_BOOL, NULL, NULL, help_r_gpuMipGen }, { &r_alphaToCoverage, "r_alphaToCoverage", "1", CVAR_ARCHIVE | CVAR_LATCH, CVART_BOOL, NULL, NULL, help_r_alphaToCoverage }, diff --git a/code/renderer/tr_local.h b/code/renderer/tr_local.h index e6d0a8e..bcc4526 100644 --- a/code/renderer/tr_local.h +++ b/code/renderer/tr_local.h @@ -982,6 +982,7 @@ extern cvar_t *r_gamma; extern cvar_t *r_greyscale; extern cvar_t *r_noiseScale; // the strength of the dithering noise extern cvar_t *r_lightmap; // render lightmaps only +extern cvar_t *r_lightmapGreyscale; // how monochrome the lightmap looks extern cvar_t *r_fullbright; // avoid lightmap pass extern cvar_t *r_softSprites; // draws certain surfaces as depth particles extern cvar_t *r_gpuMipGen; // uses GPU-side mip-map generation