From 81bc2fc22b2f76d86bab207d69b9cb4ea1735eaa Mon Sep 17 00:00:00 2001 From: drjaska Date: Sun, 10 Nov 2024 22:18:45 +0200 Subject: [PATCH] Implement r_teleporterFlash cvar r_teleporerFlash is a new cvar which allows more photosensitive users to opt out of seeing a white flash every time they are in hyperspace between a teleporter entrance and its exit. For now there is only a fade to black option implemented alongside the fade to white original and default option. As a concept this is not new, DeFRaG has had a shader for this for a long time and recently cnq3 (CPMA) added an engine cvar too. I have not looked at other engines or mods for what they are doing. I chose the same cvar name as cnq3 for cross-engine config compatibility and user intuitivity as I do not see a reason to change it. This cvar is future-proof and extendable as more styles are easy to add with the cvar value being 2 or above. 0 for black, 1 for white, 2 and above for new funky variants. These changes implement the cvar in renderer, renderer2 and renderervk. Signed-off-by: drjaska --- code/renderer/tr_backend.c | 6 +++++- code/renderer/tr_init.c | 4 ++++ code/renderer/tr_local.h | 2 ++ code/renderer2/tr_backend.c | 6 +++++- code/renderer2/tr_init.c | 4 ++++ code/renderer2/tr_local.h | 2 ++ code/renderervk/tr_backend.c | 6 +++++- code/renderervk/tr_init.c | 4 ++++ code/renderervk/tr_local.h | 2 ++ 9 files changed, 33 insertions(+), 3 deletions(-) diff --git a/code/renderer/tr_backend.c b/code/renderer/tr_backend.c index 2d6247dd9..32f6439de 100644 --- a/code/renderer/tr_backend.c +++ b/code/renderer/tr_backend.c @@ -454,7 +454,11 @@ static void RB_Hyperspace( void ) { RB_SetGL2D(); - c.rgba[0] = c.rgba[1] = c.rgba[2] = (backEnd.refdef.time & 255); + if (r_teleporterFlash->integer == 0) { + c.rgba[0] = c.rgba[1] = c.rgba[2] = (backEnd.refdef.time & 0); // fade to black + } else { + c.rgba[0] = c.rgba[1] = c.rgba[2] = (backEnd.refdef.time & 255); // fade to white + } c.rgba[3] = 255; RB_AddQuadStamp2( backEnd.refdef.x, backEnd.refdef.y, backEnd.refdef.width, backEnd.refdef.height, diff --git a/code/renderer/tr_init.c b/code/renderer/tr_init.c index d6f5e7b17..35e5a9501 100644 --- a/code/renderer/tr_init.c +++ b/code/renderer/tr_init.c @@ -60,6 +60,8 @@ cvar_t *r_greyscale; static cvar_t *r_ignorehwgamma; +cvar_t *r_teleporterFlash; + cvar_t *r_fastsky; cvar_t *r_neatsky; cvar_t *r_drawSun; @@ -1548,6 +1550,8 @@ static void R_Register( void ) ri.Cvar_SetDescription( r_stereoSeparation, "Control eye separation. Resulting separation is \\r_zproj divided by this value in standard units." ); r_ignoreGLErrors = ri.Cvar_Get( "r_ignoreGLErrors", "1", CVAR_ARCHIVE_ND ); ri.Cvar_SetDescription( r_ignoreGLErrors, "Ignore OpenGL errors." ); + r_teleporterFlash = ri.Cvar_Get( "r_teleporterFlash", "1", CVAR_ARCHIVE ); + ri.Cvar_SetDescription( r_teleporterFlash, "Show a white screen instead of a black screen when being teleported in hyperspace." ); r_fastsky = ri.Cvar_Get( "r_fastsky", "0", CVAR_ARCHIVE_ND ); ri.Cvar_SetDescription( r_fastsky, "Draw flat colored skies." ); r_drawSun = ri.Cvar_Get( "r_drawSun", "0", CVAR_ARCHIVE_ND ); diff --git a/code/renderer/tr_local.h b/code/renderer/tr_local.h index 39c8299ae..3053a606c 100644 --- a/code/renderer/tr_local.h +++ b/code/renderer/tr_local.h @@ -1218,6 +1218,8 @@ extern cvar_t *r_stereoSeparation; // separation of cameras for stereo renderi extern cvar_t *r_lodbias; // push/pull LOD transitions extern cvar_t *r_lodscale; +extern cvar_t *r_teleporterFlash; // teleport hyperspace visual + extern cvar_t *r_fastsky; // controls whether sky should be cleared or drawn extern cvar_t *r_neatsky; // nomip and nopicmip for skyboxes, cnq3 like look extern cvar_t *r_drawSun; // controls drawing of sun quad diff --git a/code/renderer2/tr_backend.c b/code/renderer2/tr_backend.c index 08438bbf7..e4b441245 100644 --- a/code/renderer2/tr_backend.c +++ b/code/renderer2/tr_backend.c @@ -295,7 +295,11 @@ static void RB_Hyperspace( void ) { // do initialization shit } - c = ( backEnd.refdef.time & 255 ) / 255.0f; + if (r_teleporterFlash->integer == 0) { + c = ( backEnd.refdef.time & 0 ) / 255.0f; // fade to black + } else { + c = ( backEnd.refdef.time & 255 ) / 255.0f; // fade to white + } qglClearColor( c, c, c, 1 ); qglClear( GL_COLOR_BUFFER_BIT ); qglClearColor(0.0f, 0.0f, 0.0f, 1.0f); diff --git a/code/renderer2/tr_init.c b/code/renderer2/tr_init.c index 5268d451c..b212997e2 100644 --- a/code/renderer2/tr_init.c +++ b/code/renderer2/tr_init.c @@ -60,6 +60,8 @@ cvar_t *r_greyscale; cvar_t *r_ignorehwgamma; cvar_t *r_measureOverdraw; +cvar_t *r_teleporterFlash; + cvar_t *r_fastsky; cvar_t *r_drawSun; cvar_t *r_dynamiclight; @@ -1270,6 +1272,8 @@ static void R_Register( void ) ri.Cvar_SetDescription( r_stereoSeparation, "Control eye separation. Resulting separation is \\r_zproj divided by this value in standard units." ); r_ignoreGLErrors = ri.Cvar_Get( "r_ignoreGLErrors", "1", CVAR_ARCHIVE ); ri.Cvar_SetDescription( r_ignoreGLErrors, "Ignore OpenGL errors." ); + r_teleporterFlash = ri.Cvar_Get( "r_teleporterFlash", "1", CVAR_ARCHIVE ); + ri.Cvar_SetDescription( r_teleporterFlash, "Show a white screen instead of a black screen when being teleported in hyperspace." ); r_fastsky = ri.Cvar_Get( "r_fastsky", "0", CVAR_ARCHIVE ); ri.Cvar_SetDescription( r_fastsky, "Draw flat colored skies." ); r_drawSun = ri.Cvar_Get( "r_drawSun", "0", CVAR_ARCHIVE ); diff --git a/code/renderer2/tr_local.h b/code/renderer2/tr_local.h index 50f3289c6..9f765eda4 100644 --- a/code/renderer2/tr_local.h +++ b/code/renderer2/tr_local.h @@ -1686,6 +1686,8 @@ extern cvar_t *r_measureOverdraw; // enables stencil buffer overdraw measuremen extern cvar_t *r_lodbias; // push/pull LOD transitions extern cvar_t *r_lodscale; +extern cvar_t *r_teleporterFlash; // teleport hyperspace visual + extern cvar_t *r_fastsky; // controls whether sky should be cleared or drawn extern cvar_t *r_drawSun; // controls drawing of sun quad extern cvar_t *r_dynamiclight; // dynamic lights enabled/disabled diff --git a/code/renderervk/tr_backend.c b/code/renderervk/tr_backend.c index ab77522b5..0f71dc690 100644 --- a/code/renderervk/tr_backend.c +++ b/code/renderervk/tr_backend.c @@ -464,7 +464,11 @@ static void RB_Hyperspace( void ) { RB_SetGL2D(); - c.rgba[0] = c.rgba[1] = c.rgba[2] = (backEnd.refdef.time & 255); + if (r_teleporterFlash->integer == 0) { + c.rgba[0] = c.rgba[1] = c.rgba[2] = (backEnd.refdef.time & 0); // fade to black + } else { + c.rgba[0] = c.rgba[1] = c.rgba[2] = (backEnd.refdef.time & 255); // fade to white + } c.rgba[3] = 255; RB_AddQuadStamp2( backEnd.refdef.x, backEnd.refdef.y, backEnd.refdef.width, backEnd.refdef.height, diff --git a/code/renderervk/tr_init.c b/code/renderervk/tr_init.c index 6d7d0cd22..ef4a0661b 100644 --- a/code/renderervk/tr_init.c +++ b/code/renderervk/tr_init.c @@ -65,6 +65,8 @@ cvar_t *r_presentBits; static cvar_t *r_ignorehwgamma; +cvar_t *r_teleporterFlash; + cvar_t *r_fastsky; cvar_t *r_neatsky; cvar_t *r_drawSun; @@ -1575,6 +1577,8 @@ static void R_Register( void ) ri.Cvar_SetDescription( r_stereoSeparation, "Control eye separation. Resulting separation is \\r_zproj divided by this value in standard units." ); r_ignoreGLErrors = ri.Cvar_Get( "r_ignoreGLErrors", "1", CVAR_ARCHIVE_ND ); ri.Cvar_SetDescription( r_ignoreGLErrors, "Ignore OpenGL errors." ); + r_teleporterFlash = ri.Cvar_Get( "r_teleporterFlash", "1", CVAR_ARCHIVE ); + ri.Cvar_SetDescription( r_teleporterFlash, "Show a white screen instead of a black screen when being teleported in hyperspace." ); r_fastsky = ri.Cvar_Get( "r_fastsky", "0", CVAR_ARCHIVE_ND ); ri.Cvar_SetDescription( r_fastsky, "Draw flat colored skies." ); r_drawSun = ri.Cvar_Get( "r_drawSun", "0", CVAR_ARCHIVE_ND ); diff --git a/code/renderervk/tr_local.h b/code/renderervk/tr_local.h index 07959994b..ac0542f34 100644 --- a/code/renderervk/tr_local.h +++ b/code/renderervk/tr_local.h @@ -1303,6 +1303,8 @@ extern cvar_t *r_stereoSeparation; // separation of cameras for stereo renderi extern cvar_t *r_lodbias; // push/pull LOD transitions extern cvar_t *r_lodscale; +extern cvar_t *r_teleporterFlash; // teleport hyperspace visual + extern cvar_t *r_fastsky; // controls whether sky should be cleared or drawn extern cvar_t *r_neatsky; // nomip and nopicmip for skyboxes, cnq3 like look extern cvar_t *r_drawSun; // controls drawing of sun quad