From 6c77608c345cfdbb8a456e1ff0360f53f5913d90 Mon Sep 17 00:00:00 2001 From: mittorn Date: Wed, 21 Feb 2024 21:07:54 +0300 Subject: [PATCH] ref_gl: implement color-modulate overbrigths with gl_vbo using texture GL_COMBINE --- ref/gl/gl_local.h | 1 + ref/gl/gl_opengl.c | 2 ++ ref/gl/gl_rmain.c | 3 ++- ref/gl/gl_rsurf.c | 23 +++++++++++++++++++---- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/ref/gl/gl_local.h b/ref/gl/gl_local.h index 627ea8c7..e276c322 100644 --- a/ref/gl/gl_local.h +++ b/ref/gl/gl_local.h @@ -780,6 +780,7 @@ extern convar_t r_traceglow; extern convar_t r_vbo; extern convar_t r_vbo_dlightmode; extern convar_t r_vbo_detail; +extern convar_t r_vbo_overbrightmode; extern convar_t r_studio_sort_textures; extern convar_t r_studio_drawelements; extern convar_t r_ripple; diff --git a/ref/gl/gl_opengl.c b/ref/gl/gl_opengl.c index 694adfe4..7e4a18fa 100644 --- a/ref/gl/gl_opengl.c +++ b/ref/gl/gl_opengl.c @@ -32,6 +32,7 @@ CVAR_DEFINE_AUTO( gl_round_down, "2", FCVAR_GLCONFIG|FCVAR_READ_ONLY, "round tex CVAR_DEFINE( r_vbo, "gl_vbo", "0", FCVAR_ARCHIVE, "draw world using VBO (known to be glitchy)" ); CVAR_DEFINE( r_vbo_detail, "gl_vbo_detail", "0", FCVAR_ARCHIVE, "detail vbo mode (0: disable, 1: multipass, 2: singlepass, broken decal dlights)" ); CVAR_DEFINE( r_vbo_dlightmode, "gl_vbo_dlightmode", "1", FCVAR_ARCHIVE, "vbo dlight rendering mode (0-1)" ); +CVAR_DEFINE( r_vbo_overbrightmode, "gl_vbo_overbrightmode", "0", FCVAR_ARCHIVE, "vbo overbright rendering mode (0-1)" ); CVAR_DEFINE_AUTO( r_ripple, "0", FCVAR_GLCONFIG, "enable software-like water texture ripple simulation" ); CVAR_DEFINE_AUTO( r_ripple_updatetime, "0.05", FCVAR_GLCONFIG, "how fast ripple simulation is" ); CVAR_DEFINE_AUTO( r_ripple_spawntime, "0.1", FCVAR_GLCONFIG, "how fast new ripples spawn" ); @@ -1248,6 +1249,7 @@ static void R_CheckVBO( void ) gEngfuncs.Cvar_RegisterVariable( &r_vbo ); gEngfuncs.Cvar_RegisterVariable( &r_vbo_dlightmode ); + gEngfuncs.Cvar_RegisterVariable( &r_vbo_overbrightmode ); gEngfuncs.Cvar_RegisterVariable( &r_vbo_detail ); } diff --git a/ref/gl/gl_rmain.c b/ref/gl/gl_rmain.c index 94d31ed3..62850504 100644 --- a/ref/gl/gl_rmain.c +++ b/ref/gl/gl_rmain.c @@ -1011,10 +1011,11 @@ static void R_CheckGamma( void ) ClearBits( gl_overbright.flags, FCVAR_CHANGED ); } - if( gl_overbright.value && FBitSet( r_vbo.flags, FCVAR_CHANGED )) + if( gl_overbright.value && ( FBitSet( r_vbo.flags, FCVAR_CHANGED ) || FBitSet( r_vbo_overbrightmode.flags, FCVAR_CHANGED ) ) ) { rebuild = true; ClearBits( r_vbo.flags, FCVAR_CHANGED ); + ClearBits( r_vbo_overbrightmode.flags, FCVAR_CHANGED ); } if( rebuild ) diff --git a/ref/gl/gl_rsurf.c b/ref/gl/gl_rsurf.c index 113f47b4..493cd63d 100644 --- a/ref/gl/gl_rsurf.c +++ b/ref/gl/gl_rsurf.c @@ -718,7 +718,7 @@ static void R_BuildLightMap( msurface_t *surf, byte *dest, int stride, qboolean tmax = ( info->lightextents[1] / sample_size ) + 1; size = smax * tmax; if( gl_overbright.value ) - lightscale = r_vbo.value ? 171 : 256; + lightscale = (r_vbo.value && !r_vbo_overbrightmode.value) ? 171 : 256; else lightscale = ( pow( 2.0f, 1.0f / v_lightgamma->value ) * 256 ) + 0.5; lm = surf->samples; @@ -2189,15 +2189,30 @@ static void R_SetLightmap( void ) if( gl_overbright.value ) { - // GLfloat color[4] = { 128.0f / 192.0f, 128.0f / 192.0f, 128.0f / 192.0f, 1.0f }; + if( r_vbo_overbrightmode.value == 1 ) + { + GLfloat color[4] = { 128.0f / 192.0f, 128.0f / 192.0f, 128.0f / 192.0f, 1.0f }; + int tmu = glState.activeTMU; + GL_SelectTexture( tmu - 1 ); + pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB ); + pglTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE ); + pglTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_CONSTANT_ARB ); + pglTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR ); + pglTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR ); + pglTexEnvi( GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_COLOR ); + pglTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE ); + // doesn't work here for some reason + pglTexEnvfv( GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color ); + GL_SelectTexture( tmu ); + } pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB ); pglTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE ); pglTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB ); pglTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE ); + pglTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE ); + pglTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS_ARB ); pglTexEnvi( GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2 ); - // doesn't work here for some reason - // pglTexEnvfv( GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color ); } else {