diff --git a/code/renderer_oa/tr_backend.c b/code/renderer_oa/tr_backend.c index cd11e4d0..3220cf02 100644 --- a/code/renderer_oa/tr_backend.c +++ b/code/renderer_oa/tr_backend.c @@ -1142,6 +1142,8 @@ const void *RB_SwapBuffers( const void *data ) { RB_ShowImages(); } + R_BrightScreen(); // leilei - alternate brightness - do it here so we hit evereything + cmd = (const swapBuffersCommand_t *)data; // we measure overdraw by reading back the stencil buffer and @@ -1175,10 +1177,12 @@ const void *RB_SwapBuffers( const void *data ) { backEnd.doneBloom = qfalse; backEnd.donepostproc = qfalse; + backEnd.doneAltBrightness = qfalse; + backEnd.doneFilm = qfalse; backEnd.doneSurfaces = qfalse; backEnd.doneSun = qfalse; backEnd.doneSunFlare = qfalse; - + return (const void *)(cmd + 1); } @@ -1203,6 +1207,8 @@ void RB_ExecuteRenderCommands( const void *data ) { //Check if it's time for BLOOM! R_PostprocessScreen(); R_BloomScreen(); + R_FilmScreen(); + data = RB_StretchPic( data ); break; case RC_DRAW_SURFS: @@ -1215,6 +1221,9 @@ void RB_ExecuteRenderCommands( const void *data ) { //Check if it's time for BLOOM! R_PostprocessScreen(); R_BloomScreen(); + R_FilmScreen(); + + data = RB_SwapBuffers( data ); break; case RC_SCREENSHOT: diff --git a/code/renderer_oa/tr_bloom.c b/code/renderer_oa/tr_bloom.c index 9f0b69e4..96d37d3c 100644 --- a/code/renderer_oa/tr_bloom.c +++ b/code/renderer_oa/tr_bloom.c @@ -38,7 +38,9 @@ static cvar_t *r_bloom_dry; static cvar_t *r_bloom_reflection; // LEILEI static cvar_t *r_bloom_sky_only; // LEILEI + cvar_t *r_film; +int fakeit = 0; /* ============================================================================== @@ -879,3 +881,162 @@ void R_BloomInit( void ) { void R_PostprocessingInit(void) { memset( &postproc, 0, sizeof( postproc )); } + + + + + + + + +/* +============================================================================== + + Alternate brightness + + Because X11 sucks. + +============================================================================== +*/ + +extern cvar_t *r_alternateBrightness; +// shamelessly ripped off from tr_bloom.c +static void ID_INLINE R_Brighter_Quad( int width, int height, float texX, float texY, float texWidth, float texHeight ) { + int x = 0; + int y = 0; + x = 0; + y += glConfig.vidHeight - height; + width += x; + height += y; + + texWidth += texX; + texHeight += texY; + + qglBegin( GL_QUADS ); + qglTexCoord2f( texX, texHeight ); + qglVertex2f( x, y ); + + qglTexCoord2f( texX, texY ); + qglVertex2f( x, height ); + + qglTexCoord2f( texWidth, texY ); + qglVertex2f( width, height ); + + qglTexCoord2f( texWidth, texHeight ); + qglVertex2f( width, y ); + qglEnd (); +} + +extern cvar_t *r_overBrightBits; + +void R_BrightItUp (int dst, int src, float intensity) +{ + GL_State( GLS_DEPTHTEST_DISABLE | dst | src); + GL_Bind( tr.whiteImage ); + GL_Cull( CT_TWO_SIDED ); + + float alpha=intensity; // why + qglColor4f( alpha,alpha,alpha, 1.0f ); + if (!fakeit) + R_Brighter_Quad( glConfig.vidWidth, glConfig.vidHeight, 0, 0, 1, 1 ); + +} + +void R_BrightScreen( void ) +{ + + + if( !r_alternateBrightness->value) + return; + if ( backEnd.doneAltBrightness ) + return; + if ( !backEnd.projection2D ) + RB_SetGL2D(); + //if (!fakeit) + backEnd.doneAltBrightness = qtrue; + + // Handle Overbrights first + int eh, ah; + if (r_overBrightBits->integer) + { + + ah = r_overBrightBits->integer; + if (ah < 1) ah = 1; if (ah > 2) ah = 2; // clamp so it never looks stupid + + // do a loop for every overbright bit enabled + for (eh=0; ehinteger; eh++){ + R_BrightItUp(GLS_SRCBLEND_DST_COLOR, GLS_DSTBLEND_ONE, 1.0f); } + + + } + + + +} + +void R_AltBrightnessInit( void ) { + + r_alternateBrightness = ri.Cvar_Get( "r_alternateBrightness", "0", CVAR_ARCHIVE | CVAR_LATCH); + r_film = ri.Cvar_Get( "r_film", "0", CVAR_ARCHIVE ); +} + + + +/* +============================================================================== + + Film postprocess + +============================================================================== +*/ + +void R_FilmScreen( void ) +{ + + if( !r_film->integer ) + return; + if ( backEnd.doneFilm ) + return; + if ( !backEnd.projection2D ) + RB_SetGL2D(); + backEnd.doneFilm = qtrue; + + + // darken vignette. + GL_State( GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO);GL_Bind( tr.dlightImage ); GL_Cull( CT_TWO_SIDED ); + qglColor4f( 0.941177, 0.952941, 0.968628, 1.0f ); + R_Brighter_Quad( glConfig.vidWidth, glConfig.vidHeight, 0.35f, 0.35f, 0.2f, 0.2f ); + + + + // brighten. + GL_State( GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ONE);GL_Bind( tr.dlightImage ); GL_Cull( CT_TWO_SIDED ); + qglColor4f( 0.941177, 0.952941, 0.968628, 1.0f ); + R_Brighter_Quad( glConfig.vidWidth, glConfig.vidHeight, 0.25f, 0.25f, 0.48f, 0.48f ); + + // invoort. + GL_State( GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_ONE_MINUS_DST_COLOR | GLS_DSTBLEND_ONE_MINUS_SRC_COLOR);GL_Bind( tr.whiteImage ); GL_Cull( CT_TWO_SIDED ); + qglColor4f(0.85098, 0.85098, 0.815686, 1.0f ); + R_Brighter_Quad( glConfig.vidWidth, glConfig.vidHeight, 0, 0, 1, 1 ); + + // brighten. + GL_State( GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_SRC_COLOR);GL_Bind( tr.whiteImage ); GL_Cull( CT_TWO_SIDED ); + qglColor4f( 0.615686, 0.615686, 0.615686, 1.0f ); + R_Brighter_Quad( glConfig.vidWidth, glConfig.vidHeight, 0, 0, 1, 1 ); + + + // invoort. + GL_State( GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_ONE_MINUS_DST_COLOR | GLS_DSTBLEND_ONE_MINUS_SRC_COLOR);GL_Bind( tr.whiteImage ); GL_Cull( CT_TWO_SIDED ); + qglColor4f(1.0f, 1.0f, 1.0f , 1.0f ); + R_Brighter_Quad( glConfig.vidWidth, glConfig.vidHeight, 0, 0, 1, 1 ); + + // brighten. + GL_State( GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_SRC_COLOR);GL_Bind( tr.whiteImage ); GL_Cull( CT_TWO_SIDED ); + qglColor4f( 0.866667, 0.847059, 0.776471, 1.0f ); + R_Brighter_Quad( glConfig.vidWidth, glConfig.vidHeight, 0, 0, 1, 1 ); + + + + + +} diff --git a/code/renderer_oa/tr_image.c b/code/renderer_oa/tr_image.c index 1f1b6a7b..fc755399 100644 --- a/code/renderer_oa/tr_image.c +++ b/code/renderer_oa/tr_image.c @@ -1317,6 +1317,7 @@ void R_CreateBuiltinImages( void ) { } +extern cvar_t *r_alternateBrightness; /* =============== R_SetColorMappings @@ -1330,12 +1331,12 @@ void R_SetColorMappings( void ) { // setup the overbright lighting tr.overbrightBits = r_overBrightBits->integer; - if ( !glConfig.deviceSupportsGamma ) { + if ( !glConfig.deviceSupportsGamma && !r_alternateBrightness->integer) { tr.overbrightBits = 0; // need hardware gamma for overbright } // never overbright in windowed mode - if ( !glConfig.isFullscreen ) + if ( !glConfig.isFullscreen && !r_alternateBrightness->integer) { tr.overbrightBits = 0; } @@ -1398,6 +1399,7 @@ void R_SetColorMappings( void ) { if ( glConfig.deviceSupportsGamma ) { + if(!r_alternateBrightness->integer) GLimp_SetGamma( s_gammatable, s_gammatable, s_gammatable ); } } diff --git a/code/renderer_oa/tr_init.c b/code/renderer_oa/tr_init.c index 21f95d1f..5f8a1aab 100644 --- a/code/renderer_oa/tr_init.c +++ b/code/renderer_oa/tr_init.c @@ -188,6 +188,7 @@ cvar_t *r_envMode; //cvar_t *r_waveMode; cvar_t *r_flaresDlight; //cvar_t *r_flaresSurfradii; +cvar_t *r_alternateBrightness; // leilei - linux overbright fix /* ** InitOpenGL @@ -464,8 +465,9 @@ void RB_TakeScreenshot(int x, int y, int width, int height, char *fileName) memcount = linelen * height; // gamma correct - if(glConfig.deviceSupportsGamma) + if ( glConfig.deviceSupportsGamma && !r_alternateBrightness->integer) { R_GammaCorrect(allbuf + offset, memcount); + } ri.FS_WriteFile(fileName, buffer, memcount + 18); @@ -1367,6 +1369,7 @@ void R_Init( void ) { R_BloomInit(); R_PostprocessingInit(); + R_AltBrightnessInit(); // leilei - alternate brightness max_polys = r_maxpolys->integer; if (max_polys < MAX_POLYS) max_polys = MAX_POLYS; diff --git a/code/renderer_oa/tr_local.h b/code/renderer_oa/tr_local.h index 296e3d03..75469aa3 100644 --- a/code/renderer_oa/tr_local.h +++ b/code/renderer_oa/tr_local.h @@ -53,7 +53,6 @@ typedef struct dlight_s { } dlight_t; -// leilei - sun spazzing workaround // a trRefEntity_t has all the information passed in by // the client game, as well as some locally derived info @@ -964,6 +963,8 @@ typedef struct { qboolean vertexes2D; // shader needs to be finished qboolean doneBloom; // done bloom this frame qboolean donepostproc; // done postprocess this frame + qboolean doneAltBrightness; // leilei - done alternate brightness this frame + qboolean doneFilm; // leilei - done film filtering this frame qboolean doneSun; // leilei - done drawing a sun qboolean doneSunFlare; // leilei - done drawing a sun flare qboolean doneSurfaces; // done any 3d surfaces already @@ -1207,6 +1208,8 @@ extern cvar_t *r_specMode; extern cvar_t *r_flaresDlight; //extern cvar_t *r_flaresSurfradii; +extern cvar_t *r_alternateBrightness; // leilei - alternate brightness + //==================================================================== void R_SwapBuffers( int ); @@ -2029,4 +2032,9 @@ void R_BloomScreen( void ); void R_PostprocessScreen( void ); void R_PostprocessingInit(void); +// leilei +void R_BrightScreen( void ); +void R_AltBrightnessInit( void ); +void R_FilmScreen( void ); // leilei - film effect + #endif //TR_LOCAL_H