From 614fde1f8431e944632e57f47936213217a93937 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Mon, 22 Aug 2022 15:32:06 +0200 Subject: [PATCH] q3map2: add -externalnames option to write explicit external lightmap names when writing style shaders It makes possible for game engines to run less code on each rendering frame by not doing any computation to find the file. On some game engines it may even make the lightmaps be processed with simpler GLSL code as they will be processed as simple colormaps instead of more complex code purposed for usual lightmaps with features that aren't needed in such situation anyway. Or some engine may implement a specific GLSL code to blend multiple colormaps in a single pass without having to implement alternate code for lightmaps. Example with scripts/q3map2_gloom2.shader: ``` -gloom2/7C9AD47A87BC98CCA1FF30C4D788DD47 +gloom2/72353935F9542782B847B2E329A8CC80 { // Q3Map2 defaulted { map $lightmap rgbGen identity } // Q3Map2 custom lightstyle stage(s) { - map $lightmap + map maps/gloom2/lm_0000.tga blendFunc GL_SRC_ALPHA GL_ONE rgbGen wave noise 1 .75 1.6 4.2 // style 2 tcGen lightmap tcMod transform 1 0 0 1 0.54492 0.10156 } { - map $lightmap + map maps/gloom2/lm_0000.tga blendFunc GL_SRC_ALPHA GL_ONE rgbGen wave noise 1 .5 3.7 4.9 // style 3 tcGen lightmap tcMod transform 1 0 0 1 -0.38672 0.19043 } { - map $lightmap + map maps/gloom2/lm_0000.tga blendFunc GL_SRC_ALPHA GL_ONE rgbGen wave noise 1 1 2.6 1.3 // style 4 tcGen lightmap tcMod transform 1 0 0 1 0.24023 0.19043 } { map textures/gloom2/e8clangfloor05c.tga blendFunc GL_DST_COLOR GL_ZERO rgbGen identity } } ``` --- tools/quake3/q3map2/help.c | 1 + tools/quake3/q3map2/light.c | 6 ++++++ tools/quake3/q3map2/lightmaps_ydnar.c | 3 ++- tools/quake3/q3map2/q3map2.h | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/quake3/q3map2/help.c b/tools/quake3/q3map2/help.c index 60631e3d..f21476a0 100644 --- a/tools/quake3/q3map2/help.c +++ b/tools/quake3/q3map2/help.c @@ -215,6 +215,7 @@ void HelpLight() {"-export", "Export lightmaps when compile finished (like `-export` mode)"}, {"-exposure ", "Lightmap exposure to better support overbright spots"}, {"-external", "Force external lightmaps even if at size of internal lightmaps"}, + {"-externalnames", "Write lightstyle shader using external lightmap names"}, {"-extradist ", "Extra distance for lights in map units"}, {"-extravisnudge", "Broken feature to nudge the luxel origin to a better vis cluster"}, {"-extrawide", "Deprecated alias for `-super 2 -filter`"}, diff --git a/tools/quake3/q3map2/light.c b/tools/quake3/q3map2/light.c index 99d79484..39e5c7ad 100644 --- a/tools/quake3/q3map2/light.c +++ b/tools/quake3/q3map2/light.c @@ -2546,6 +2546,12 @@ int LightMain( int argc, char **argv ){ Sys_Printf( "Storing all lightmaps externally\n" ); } + else if ( !strcmp( argv[ i ], "-externalnames" ) ) { + externalLightmaps = qtrue; + externalLightmapNames = qtrue; + Sys_Printf( "Writing lightstyle shader using external lightmap names\n" ); + } + else if ( !strcmp( argv[ i ], "-lightmapsize" ) ) { lmCustomSize = atoi( argv[ i + 1 ] ); diff --git a/tools/quake3/q3map2/lightmaps_ydnar.c b/tools/quake3/q3map2/lightmaps_ydnar.c index 37bb6da4..70e59b2f 100644 --- a/tools/quake3/q3map2/lightmaps_ydnar.c +++ b/tools/quake3/q3map2/lightmaps_ydnar.c @@ -3355,7 +3355,8 @@ void StoreSurfaceLightmaps( qboolean fastAllocate, qboolean storeForReal ){ olm = &outLightmaps[ lm->outLightmapNums[ lightmapNum ] ]; /* lightmap name */ - if ( lm->outLightmapNums[ lightmapNum ] == lm->outLightmapNums[ 0 ] ) { + if ( !externalLightmapNames + && lm->outLightmapNums[ lightmapNum ] == lm->outLightmapNums[ 0 ] ) { strcpy( lightmapName, "$lightmap" ); } else{ diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 5721ae25..42c71210 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -2310,6 +2310,7 @@ Q_EXTERN qboolean noCollapse Q_ASSIGN( qfalse ); Q_EXTERN int lightmapSearchBlockSize Q_ASSIGN( 0 ); Q_EXTERN qboolean exportLightmaps Q_ASSIGN( qfalse ); Q_EXTERN qboolean externalLightmaps Q_ASSIGN( qfalse ); +Q_EXTERN qboolean externalLightmapNames Q_ASSIGN( qfalse ); Q_EXTERN int lmCustomSize Q_ASSIGN( LIGHTMAP_WIDTH ); Q_EXTERN char * lmCustomDir Q_ASSIGN( NULL ); Q_EXTERN int lmLimitSize Q_ASSIGN( 0 ); -- 2.39.2