Skip to content

Commit

Permalink
Implement r_teleporterFlash cvar
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
drjaska committed Nov 10, 2024
1 parent f259765 commit 81bc2fc
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 3 deletions.
6 changes: 5 additions & 1 deletion code/renderer/tr_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions code/renderer/tr_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 2 additions & 0 deletions code/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion code/renderer2/tr_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions code/renderer2/tr_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 2 additions & 0 deletions code/renderer2/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion code/renderervk/tr_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions code/renderervk/tr_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 2 additions & 0 deletions code/renderervk/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 81bc2fc

Please sign in to comment.