From 5c97bccbf609eaa1928c9058d3d6b099397656a0 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Fri, 21 Oct 2011 17:19:52 +0200 Subject: [PATCH] experimental q3map2 command line option: -sRGB (store lightmaps in sRGB) --- 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 | 3 ++- 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 | 13 +++++++++++++ tools/quake3/q3map2/light_ydnar.c | 9 +++++++++ tools/quake3/q3map2/q3map2.h | 2 ++ 22 files changed, 44 insertions(+), 1 deletion(-) diff --git a/tools/quake3/q3map2/game__null.h b/tools/quake3/q3map2/game__null.h index c2f2484..0bc61e3 100644 --- a/tools/quake3/q3map2/game__null.h +++ b/tools/quake3/q3map2/game__null.h @@ -63,6 +63,7 @@ game_t struct qfalse, /* wolf lighting model? */ 0, /* lightmap width/height */ 0, /* lightmap gamma */ + qfalse, /* lightmap 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 e91fdb7..653beb1 100644 --- a/tools/quake3/q3map2/game_darkplaces.h +++ b/tools/quake3/q3map2/game_darkplaces.h @@ -54,6 +54,7 @@ game_t struct qfalse, /* wolf lighting model? */ 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ + qfalse, /* lightmap 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 97d2d6d..3d6cfe4 100644 --- a/tools/quake3/q3map2/game_dq.h +++ b/tools/quake3/q3map2/game_dq.h @@ -54,6 +54,7 @@ game_t struct qfalse, /* wolf lighting model? */ 128, /* lightmap width/height */ 1.2f, /* lightmap gamma */ + qfalse, /* lightmap 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 84ea664..4c08ab0 100644 --- a/tools/quake3/q3map2/game_ef.h +++ b/tools/quake3/q3map2/game_ef.h @@ -113,6 +113,7 @@ game_t struct qfalse, /* wolf lighting model? */ 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ + qfalse, /* lightmap 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 8add5bb..ff79162 100644 --- a/tools/quake3/q3map2/game_etut.h +++ b/tools/quake3/q3map2/game_etut.h @@ -147,7 +147,8 @@ game_t struct "flareshader", /* default flare shader */ qfalse, /* wolf lighting model? */ 128, /* lightmap width/height */ - 2.2f, /* lightmap gamma */ + 1.0f, /* lightmap gamma */ + qtrue, /* lightmap sRGB */ 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 3d25129..7f4a5fc 100644 --- a/tools/quake3/q3map2/game_ja.h +++ b/tools/quake3/q3map2/game_ja.h @@ -67,6 +67,7 @@ game_t struct qfalse, /* wolf lighting model? */ 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ + qfalse, /* lightmap 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 056baf0..30bb3d3 100644 --- a/tools/quake3/q3map2/game_jk2.h +++ b/tools/quake3/q3map2/game_jk2.h @@ -64,6 +64,7 @@ game_t struct qfalse, /* wolf lighting model? */ 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ + qfalse, /* lightmap 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 4d496c3..8e0785d 100644 --- a/tools/quake3/q3map2/game_nexuiz.h +++ b/tools/quake3/q3map2/game_nexuiz.h @@ -63,6 +63,7 @@ game_t struct qfalse, /* wolf lighting model? */ 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ + qfalse, /* lightmap 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 60e299d..a1a4c4b 100644 --- a/tools/quake3/q3map2/game_prophecy.h +++ b/tools/quake3/q3map2/game_prophecy.h @@ -54,6 +54,7 @@ game_t struct qfalse, /* wolf lighting model? */ 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ + qfalse, /* lightmap 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 7645ad0..0fd336c 100644 --- a/tools/quake3/q3map2/game_qfusion.h +++ b/tools/quake3/q3map2/game_qfusion.h @@ -115,6 +115,7 @@ game_t struct qfalse, /* wolf lighting model? */ 512, /* lightmap width/height */ 1.0f, /* lightmap gamma */ + qfalse, /* lightmap 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 98d4c4b..be09468 100644 --- a/tools/quake3/q3map2/game_quake3.h +++ b/tools/quake3/q3map2/game_quake3.h @@ -112,6 +112,7 @@ game_t struct qfalse, /* wolf lighting model? */ 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ + qfalse, /* lightmap 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 1a50927..a9425a8 100644 --- a/tools/quake3/q3map2/game_quakelive.h +++ b/tools/quake3/q3map2/game_quakelive.h @@ -64,6 +64,7 @@ game_t struct qfalse, /* wolf lighting model? */ 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ + qfalse, /* lightmap 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 c81e724..97b01c4 100644 --- a/tools/quake3/q3map2/game_reaction.h +++ b/tools/quake3/q3map2/game_reaction.h @@ -84,6 +84,7 @@ game_t struct qfalse, /* wolf lighting model? */ 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ + qfalse, /* lightmap 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 931ec69..e7453f8 100644 --- a/tools/quake3/q3map2/game_sof2.h +++ b/tools/quake3/q3map2/game_sof2.h @@ -139,6 +139,7 @@ game_t struct qfalse, /* wolf lighting model? */ 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ + qfalse, /* lightmap 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 ab31215..2117aa4 100644 --- a/tools/quake3/q3map2/game_tenebrae.h +++ b/tools/quake3/q3map2/game_tenebrae.h @@ -112,6 +112,7 @@ game_t struct qfalse, /* wolf lighting model? */ 512, /* lightmap width/height */ 2.0f, /* lightmap gamma */ + qfalse, /* lightmap 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 5d42262..9a1cb79 100644 --- a/tools/quake3/q3map2/game_tremulous.h +++ b/tools/quake3/q3map2/game_tremulous.h @@ -70,6 +70,7 @@ game_t struct qfalse, /* wolf lighting model? */ 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ + qfalse, /* lightmap 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 157bfe3..fc55c88 100644 --- a/tools/quake3/q3map2/game_wolf.h +++ b/tools/quake3/q3map2/game_wolf.h @@ -129,6 +129,7 @@ game_t struct qtrue, /* wolf lighting model? */ 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ + qfalse, /* lightmap 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 3495f0d..fdda4d9 100644 --- a/tools/quake3/q3map2/game_wolfet.h +++ b/tools/quake3/q3map2/game_wolfet.h @@ -66,6 +66,7 @@ game_t struct qtrue, /* wolf lighting model? */ 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ + qfalse, /* lightmap 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 568c263..83d7715 100644 --- a/tools/quake3/q3map2/game_xonotic.h +++ b/tools/quake3/q3map2/game_xonotic.h @@ -63,6 +63,7 @@ game_t struct qfalse, /* wolf lighting model? */ 128, /* lightmap width/height */ 1.0f, /* lightmap gamma */ + qfalse, /* lightmap 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 5d5dfc5..25b5a87 100644 --- a/tools/quake3/q3map2/light.c +++ b/tools/quake3/q3map2/light.c @@ -2065,6 +2065,12 @@ int LightMain( int argc, char **argv ) lightmapGamma = game->lightmapGamma; Sys_Printf( " lightning gamma: %f\n", lightmapGamma ); + lightmapsRGB = game->lightmapsRGB; + if(lightmapsRGB) + Sys_Printf( " lightmap colorspace: sRGB\n" ); + else + Sys_Printf( " lightmap colorspace: linear\n" ); + lightmapCompensate = game->lightmapCompensate; Sys_Printf( " lightning compensation: %f\n", lightmapCompensate ); @@ -2204,6 +2210,13 @@ int LightMain( int argc, char **argv ) i++; } + else if( !strcmp( argv[ i ], "-sRGB" ) ) + { + lightmapsRGB = qtrue; + Sys_Printf( "Lighting is in sRGB\n" ); + i++; + } + else if( !strcmp( argv[ i ], "-exposure" ) ) { f = atof( argv[ i + 1 ] ); diff --git a/tools/quake3/q3map2/light_ydnar.c b/tools/quake3/q3map2/light_ydnar.c index f291e7a..09a8e48 100644 --- a/tools/quake3/q3map2/light_ydnar.c +++ b/tools/quake3/q3map2/light_ydnar.c @@ -44,6 +44,7 @@ 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; @@ -120,6 +121,14 @@ void ColorToBytes( const float *color, byte *colorBytes, float scale ) /* compensate for ingame overbrighting/bitshifting */ VectorScale( sample, (1.0f / lightmapCompensate), sample ); + + /* 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); + } /* store it off */ colorBytes[ 0 ] = sample[ 0 ]; diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index e86575e..3d3509a 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -565,6 +565,7 @@ typedef struct game_s qboolean wolfLight; /* when true, lights work like wolf q3map */ int lightmapSize; /* bsp lightmap width/height */ float lightmapGamma; /* default lightmap gamma */ + qboolean lightmapsRGB; /* default lightmap 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) */ @@ -2295,6 +2296,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 lightmapExposure Q_ASSIGN( 1.0f ); Q_EXTERN float lightmapCompensate Q_ASSIGN( 1.0f ); -- 2.39.2