From e8f27310d6e17f99f55b4fc9184f5115c90e3ec7 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Sat, 29 Oct 2011 16:33:46 +0200 Subject: [PATCH] also new option: -sRGBtex, and renamed -sRGB to -sRGBlight --- tools/quake3/q3map2/branch-manager | 1 - tools/quake3/q3map2/bsp.c | 11 +++++++++++ tools/quake3/q3map2/game__null.h | 1 + tools/quake3/q3map2/game_darkplaces.h | 1 + tools/quake3/q3map2/game_dq.h | 1 + tools/quake3/q3map2/game_ef.h | 1 + tools/quake3/q3map2/game_etut.h | 1 + tools/quake3/q3map2/game_ja.h | 1 + tools/quake3/q3map2/game_jk2.h | 1 + tools/quake3/q3map2/game_nexuiz.h | 1 + tools/quake3/q3map2/game_prophecy.h | 1 + tools/quake3/q3map2/game_qfusion.h | 1 + tools/quake3/q3map2/game_quake3.h | 1 + tools/quake3/q3map2/game_quakelive.h | 1 + tools/quake3/q3map2/game_reaction.h | 1 + tools/quake3/q3map2/game_sof2.h | 1 + tools/quake3/q3map2/game_tenebrae.h | 1 + tools/quake3/q3map2/game_tremulous.h | 1 + tools/quake3/q3map2/game_wolf.h | 1 + tools/quake3/q3map2/game_wolfet.h | 1 + tools/quake3/q3map2/game_xonotic.h | 1 + tools/quake3/q3map2/light.c | 22 ++++++++++++++++++++-- tools/quake3/q3map2/light_bounce.c | 8 ++++++++ tools/quake3/q3map2/light_ydnar.c | 7 +++---- tools/quake3/q3map2/q3map2.h | 5 +++++ 25 files changed, 66 insertions(+), 7 deletions(-) delete mode 120000 tools/quake3/q3map2/branch-manager diff --git a/tools/quake3/q3map2/branch-manager b/tools/quake3/q3map2/branch-manager deleted file mode 120000 index c446238..0000000 --- a/tools/quake3/q3map2/branch-manager +++ /dev/null @@ -1 +0,0 @@ -../../../branch-manager \ No newline at end of file diff --git a/tools/quake3/q3map2/bsp.c b/tools/quake3/q3map2/bsp.c index 54e14bf..f9fe902 100644 --- a/tools/quake3/q3map2/bsp.c +++ b/tools/quake3/q3map2/bsp.c @@ -683,6 +683,7 @@ int BSPMain( int argc, char **argv ) maxSurfaceVerts = game->maxSurfaceVerts; maxSurfaceIndexes = game->maxSurfaceIndexes; emitFlares = game->emitFlares; + texturesRGB = game->texturesRGB; /* process arguments */ for( i = 1; i < (argc - 1); i++ ) @@ -918,6 +919,16 @@ int BSPMain( int argc, char **argv ) Sys_Printf( "Debug portal surfaces enabled\n" ); debugPortals = qtrue; } + else if( !strcmp( argv[ i ], "-sRGBtex" ) ) + { + texturesRGB = qtrue; + Sys_Printf( "Textures are in sRGB\n" ); + } + else if( !strcmp( argv[ i ], "-nosRGBtex" ) ) + { + texturesRGB = qfalse; + Sys_Printf( "Textures are linear\n" ); + } else if( !strcmp( argv[ i ], "-altsplit" ) ) { Sys_Printf( "Alternate BSP splitting (by 27) enabled\n" ); diff --git a/tools/quake3/q3map2/game__null.h b/tools/quake3/q3map2/game__null.h index 0bc61e3..5ff6aba 100644 --- a/tools/quake3/q3map2/game__null.h +++ b/tools/quake3/q3map2/game__null.h @@ -64,6 +64,7 @@ game_t struct 0, /* lightmap width/height */ 0, /* lightmap gamma */ qfalse, /* lightmap sRGB */ + qfalse, /* texture sRGB */ 0, /* lightmap exposure */ 0, /* lightmap compensate */ 0, /* lightgrid scale */ diff --git a/tools/quake3/q3map2/game_darkplaces.h b/tools/quake3/q3map2/game_darkplaces.h index 653beb1..ab73baa 100644 --- a/tools/quake3/q3map2/game_darkplaces.h +++ b/tools/quake3/q3map2/game_darkplaces.h @@ -55,6 +55,7 @@ game_t struct 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ qfalse, /* lightmap sRGB */ + qfalse, /* texture sRGB */ 200.0f, /* lightmap exposure */ 1.0f, /* lightmap compensate */ 0.3f, /* lightgrid scale */ diff --git a/tools/quake3/q3map2/game_dq.h b/tools/quake3/q3map2/game_dq.h index 3d6cfe4..6507aec 100644 --- a/tools/quake3/q3map2/game_dq.h +++ b/tools/quake3/q3map2/game_dq.h @@ -55,6 +55,7 @@ game_t struct 128, /* lightmap width/height */ 1.2f, /* lightmap gamma */ qfalse, /* lightmap sRGB */ + qfalse, /* texture sRGB */ 200.0f, /* lightmap exposure */ 1.0f, /* lightmap compensate */ 0.3f, /* lightgrid scale */ diff --git a/tools/quake3/q3map2/game_ef.h b/tools/quake3/q3map2/game_ef.h index 4c08ab0..1113664 100644 --- a/tools/quake3/q3map2/game_ef.h +++ b/tools/quake3/q3map2/game_ef.h @@ -114,6 +114,7 @@ game_t struct 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ qfalse, /* lightmap sRGB */ + qfalse, /* texture sRGB */ 1.0f, /* lightmap exposure */ 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ diff --git a/tools/quake3/q3map2/game_etut.h b/tools/quake3/q3map2/game_etut.h index ff79162..38bc083 100644 --- a/tools/quake3/q3map2/game_etut.h +++ b/tools/quake3/q3map2/game_etut.h @@ -149,6 +149,7 @@ game_t struct 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ qtrue, /* lightmap sRGB */ + qfalse, /* texture sRGB (yes, this is incorrect, but we better match ET:UT) */ 1.0f, /* lightmap exposure */ 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ diff --git a/tools/quake3/q3map2/game_ja.h b/tools/quake3/q3map2/game_ja.h index 7f4a5fc..3a1a4d4 100644 --- a/tools/quake3/q3map2/game_ja.h +++ b/tools/quake3/q3map2/game_ja.h @@ -68,6 +68,7 @@ game_t struct 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ qfalse, /* lightmap sRGB */ + qfalse, /* texture sRGB */ 1.0f, /* lightmap exposure */ 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ diff --git a/tools/quake3/q3map2/game_jk2.h b/tools/quake3/q3map2/game_jk2.h index 30bb3d3..4dd4d84 100644 --- a/tools/quake3/q3map2/game_jk2.h +++ b/tools/quake3/q3map2/game_jk2.h @@ -65,6 +65,7 @@ game_t struct 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ qfalse, /* lightmap sRGB */ + qfalse, /* texture sRGB */ 1.0f, /* lightmap exposure */ 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ diff --git a/tools/quake3/q3map2/game_nexuiz.h b/tools/quake3/q3map2/game_nexuiz.h index 8e0785d..386cfd0 100644 --- a/tools/quake3/q3map2/game_nexuiz.h +++ b/tools/quake3/q3map2/game_nexuiz.h @@ -64,6 +64,7 @@ game_t struct 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ qfalse, /* lightmap sRGB */ + qfalse, /* texture sRGB */ 1.0f, /* lightmap exposure */ 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ diff --git a/tools/quake3/q3map2/game_prophecy.h b/tools/quake3/q3map2/game_prophecy.h index a1a4c4b..6d8b0a2 100644 --- a/tools/quake3/q3map2/game_prophecy.h +++ b/tools/quake3/q3map2/game_prophecy.h @@ -55,6 +55,7 @@ game_t struct 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ qfalse, /* lightmap sRGB */ + qfalse, /* texture sRGB */ 200.0f, /* lightmap exposure */ 1.0f, /* lightmap compensate */ 0.4f, /* lightgrid scale */ diff --git a/tools/quake3/q3map2/game_qfusion.h b/tools/quake3/q3map2/game_qfusion.h index 0fd336c..681f75d 100644 --- a/tools/quake3/q3map2/game_qfusion.h +++ b/tools/quake3/q3map2/game_qfusion.h @@ -116,6 +116,7 @@ game_t struct 512, /* lightmap width/height */ 1.0f, /* lightmap gamma */ qfalse, /* lightmap sRGB */ + qfalse, /* texture sRGB */ 1.0f, /* lightmap exposure */ 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ diff --git a/tools/quake3/q3map2/game_quake3.h b/tools/quake3/q3map2/game_quake3.h index be09468..76b3ff3 100644 --- a/tools/quake3/q3map2/game_quake3.h +++ b/tools/quake3/q3map2/game_quake3.h @@ -113,6 +113,7 @@ game_t struct 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ qfalse, /* lightmap sRGB */ + qfalse, /* texture sRGB */ 1.0f, /* lightmap exposure */ 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ diff --git a/tools/quake3/q3map2/game_quakelive.h b/tools/quake3/q3map2/game_quakelive.h index a9425a8..ba781cd 100644 --- a/tools/quake3/q3map2/game_quakelive.h +++ b/tools/quake3/q3map2/game_quakelive.h @@ -65,6 +65,7 @@ game_t struct 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ qfalse, /* lightmap sRGB */ + qfalse, /* texture sRGB */ 1.0f, /* lightmap exposure */ 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ diff --git a/tools/quake3/q3map2/game_reaction.h b/tools/quake3/q3map2/game_reaction.h index 97b01c4..ea59e35 100644 --- a/tools/quake3/q3map2/game_reaction.h +++ b/tools/quake3/q3map2/game_reaction.h @@ -85,6 +85,7 @@ game_t struct 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ qfalse, /* lightmap sRGB */ + qfalse, /* texture sRGB */ 1.0f, /* lightmap exposure */ 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ diff --git a/tools/quake3/q3map2/game_sof2.h b/tools/quake3/q3map2/game_sof2.h index e7453f8..98081da 100644 --- a/tools/quake3/q3map2/game_sof2.h +++ b/tools/quake3/q3map2/game_sof2.h @@ -140,6 +140,7 @@ game_t struct 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ qfalse, /* lightmap sRGB */ + qfalse, /* texture sRGB */ 1.0f, /* lightmap exposure */ 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ diff --git a/tools/quake3/q3map2/game_tenebrae.h b/tools/quake3/q3map2/game_tenebrae.h index 2117aa4..9e0658f 100644 --- a/tools/quake3/q3map2/game_tenebrae.h +++ b/tools/quake3/q3map2/game_tenebrae.h @@ -113,6 +113,7 @@ game_t struct 512, /* lightmap width/height */ 2.0f, /* lightmap gamma */ qfalse, /* lightmap sRGB */ + qfalse, /* texture sRGB */ 1.0f, /* lightmap exposure */ 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ diff --git a/tools/quake3/q3map2/game_tremulous.h b/tools/quake3/q3map2/game_tremulous.h index 9a1cb79..08027fe 100644 --- a/tools/quake3/q3map2/game_tremulous.h +++ b/tools/quake3/q3map2/game_tremulous.h @@ -71,6 +71,7 @@ game_t struct 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ qfalse, /* lightmap sRGB */ + qfalse, /* texture sRGB */ 1.0f, /* lightmap exposure */ 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ diff --git a/tools/quake3/q3map2/game_wolf.h b/tools/quake3/q3map2/game_wolf.h index fc55c88..94339e6 100644 --- a/tools/quake3/q3map2/game_wolf.h +++ b/tools/quake3/q3map2/game_wolf.h @@ -130,6 +130,7 @@ game_t struct 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ qfalse, /* lightmap sRGB */ + qfalse, /* texture sRGB */ 1.0f, /* lightmap exposure */ 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ diff --git a/tools/quake3/q3map2/game_wolfet.h b/tools/quake3/q3map2/game_wolfet.h index fdda4d9..bcb3098 100644 --- a/tools/quake3/q3map2/game_wolfet.h +++ b/tools/quake3/q3map2/game_wolfet.h @@ -67,6 +67,7 @@ game_t struct 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ qfalse, /* lightmap sRGB */ + qfalse, /* texture sRGB */ 1.0f, /* lightmap exposure */ 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ diff --git a/tools/quake3/q3map2/game_xonotic.h b/tools/quake3/q3map2/game_xonotic.h index 83d7715..2512193 100644 --- a/tools/quake3/q3map2/game_xonotic.h +++ b/tools/quake3/q3map2/game_xonotic.h @@ -64,6 +64,7 @@ game_t struct 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ qfalse, /* lightmap sRGB */ + qfalse, /* texture sRGB */ 1.0f, /* lightmap exposure */ 1.0f, /* lightmap compensate */ 1.0f, /* lightgrid scale */ diff --git a/tools/quake3/q3map2/light.c b/tools/quake3/q3map2/light.c index ffdd500..c7f1e72 100644 --- a/tools/quake3/q3map2/light.c +++ b/tools/quake3/q3map2/light.c @@ -2077,6 +2077,12 @@ int LightMain( int argc, char **argv ) else Sys_Printf( " lightmap colorspace: linear\n" ); + texturesRGB = game->texturesRGB; + if(texturesRGB) + Sys_Printf( " texture colorspace: sRGB\n" ); + else + Sys_Printf( " texture colorspace: linear\n" ); + lightmapCompensate = game->lightmapCompensate; Sys_Printf( " lightning compensation: %f\n", lightmapCompensate ); @@ -2235,18 +2241,30 @@ int LightMain( int argc, char **argv ) i++; } - else if( !strcmp( argv[ i ], "-sRGB" ) ) + else if( !strcmp( argv[ i ], "-sRGBlight" ) ) { lightmapsRGB = qtrue; Sys_Printf( "Lighting is in sRGB\n" ); } - else if( !strcmp( argv[ i ], "-nosRGB" ) ) + else if( !strcmp( argv[ i ], "-nosRGBlight" ) ) { lightmapsRGB = qfalse; Sys_Printf( "Lighting is linear\n" ); } + else if( !strcmp( argv[ i ], "-sRGBtex" ) ) + { + texturesRGB = qtrue; + Sys_Printf( "Textures are in sRGB\n" ); + } + + else if( !strcmp( argv[ i ], "-nosRGBtex" ) ) + { + texturesRGB = qfalse; + Sys_Printf( "Textures are linear\n" ); + } + else if( !strcmp( argv[ i ], "-exposure" ) ) { f = atof( argv[ i + 1 ] ); diff --git a/tools/quake3/q3map2/light_bounce.c b/tools/quake3/q3map2/light_bounce.c index 0e59dde..d78c6de 100644 --- a/tools/quake3/q3map2/light_bounce.c +++ b/tools/quake3/q3map2/light_bounce.c @@ -233,6 +233,14 @@ qboolean RadSampleImage( byte *pixels, int width, int height, float st[ 2 ], flo pixels += (y * width * 4) + (x * 4); VectorCopy( pixels, color ); color[ 3 ] = pixels[ 3 ]; + + if(texturesRGB) + { + color[0] = Image_LinearFloatFromsRGBFloat(color[0] * (1.0 / 255.0)) * 255.0; + color[1] = Image_LinearFloatFromsRGBFloat(color[1] * (1.0 / 255.0)) * 255.0; + color[2] = Image_LinearFloatFromsRGBFloat(color[2] * (1.0 / 255.0)) * 255.0; + } + return qtrue; } diff --git a/tools/quake3/q3map2/light_ydnar.c b/tools/quake3/q3map2/light_ydnar.c index 09a8e48..b01084d 100644 --- a/tools/quake3/q3map2/light_ydnar.c +++ b/tools/quake3/q3map2/light_ydnar.c @@ -44,7 +44,6 @@ ColorToBytes() ydnar: moved to here 2001-02-04 */ -#define Image_sRGBFloatFromLinear(c) (((c) < 0.8014848f) ? (c) * 0.05046875f : 1.055f * (float)pow((c)*(1.0f/256.0f), 1.0f/2.4f) - 0.055f) void ColorToBytes( const float *color, byte *colorBytes, float scale ) { int i; @@ -125,9 +124,9 @@ void ColorToBytes( const float *color, byte *colorBytes, float scale ) /* sRGB lightmaps */ if(lightmapsRGB) { - sample[0] = floor(Image_sRGBFloatFromLinear(sample[0]) * 255.0 + 0.5); - sample[1] = floor(Image_sRGBFloatFromLinear(sample[1]) * 255.0 + 0.5); - sample[2] = floor(Image_sRGBFloatFromLinear(sample[2]) * 255.0 + 0.5); + sample[0] = floor(Image_sRGBFloatFromLinearFloat(sample[0] * (1.0 / 255.0)) * 255.0 + 0.5); + sample[1] = floor(Image_sRGBFloatFromLinearFloat(sample[1] * (1.0 / 255.0)) * 255.0 + 0.5); + sample[2] = floor(Image_sRGBFloatFromLinearFloat(sample[2] * (1.0 / 255.0)) * 255.0 + 0.5); } /* store it off */ diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 9172415..8c240ea 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -566,6 +566,7 @@ typedef struct game_s int lightmapSize; /* bsp lightmap width/height */ float lightmapGamma; /* default lightmap gamma */ qboolean lightmapsRGB; /* default lightmap sRGB mode */ + qboolean texturesRGB; /* default texture sRGB mode */ float lightmapExposure; /* default lightmap exposure */ float lightmapCompensate; /* default lightmap compensate value */ float gridScale; /* vortex: default lightgrid scale (affects both directional and ambient spectres) */ @@ -2298,6 +2299,7 @@ Q_EXTERN qboolean inGrid Q_ASSIGN(0); /* ydnar: lightmap gamma/compensation */ Q_EXTERN float lightmapGamma Q_ASSIGN( 1.0f ); Q_EXTERN float lightmapsRGB Q_ASSIGN( qfalse ); +Q_EXTERN float texturesRGB Q_ASSIGN( qfalse ); Q_EXTERN float lightmapExposure Q_ASSIGN( 1.0f ); Q_EXTERN float lightmapCompensate Q_ASSIGN( 1.0f ); @@ -2540,5 +2542,8 @@ Q_EXTERN bspAdvertisement_t bspAds[ MAX_MAP_ADVERTISEMENTS ]; #define AUTOEXPAND_BY_REALLOC_BSP(suffix, def) AUTOEXPAND_BY_REALLOC(bsp##suffix, numBSP##suffix, allocatedBSP##suffix, def) +#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) + /* end marker */ #endif -- 2.39.2