diff --git a/changelog.txt b/changelog.txt index 0e3f59b..5129cce 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,6 +1,8 @@ DD Mmm 17 - 1.49 +fix: r_lightmap is now archived and actually does its job + add: r_greyscale to control how monochromatic the final image looks r_greyscale 0 (default) = full color (nothing done) r_greyscale 1 = monochrome diff --git a/code/renderer/tr_backend.cpp b/code/renderer/tr_backend.cpp index ce8471e..9df397d 100644 --- a/code/renderer/tr_backend.cpp +++ b/code/renderer/tr_backend.cpp @@ -120,16 +120,10 @@ void GL_TexEnv( int env ) switch ( env ) { case GL_MODULATE: - qglTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); - break; case GL_REPLACE: - qglTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE ); - break; case GL_DECAL: - qglTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL ); - break; case GL_ADD: - qglTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD ); + qglTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, env ); break; default: ri.Error( ERR_DROP, "GL_TexEnv: invalid env '%d' passed\n", env ); diff --git a/code/renderer/tr_bsp.cpp b/code/renderer/tr_bsp.cpp index 52ad015..36a5738 100644 --- a/code/renderer/tr_bsp.cpp +++ b/code/renderer/tr_bsp.cpp @@ -65,30 +65,6 @@ static void R_LoadLightmaps( const lump_t* l ) int i, j, k; byte image[LIGHTMAP_SIZE * LIGHTMAP_SIZE * 4]; - for(k = 0; k < 3; k++) { - if(strlen(r_maplightColor->string) == 3) { - int hexNum = r_maplightColor->string[k] - 48 < 0 ? 0 : r_maplightColor->string[k] - 48; - hexNum = hexNum > 15 ? hexNum - 65 + 48 + 10: hexNum; - hexNum = hexNum > 15 ? hexNum - 97 + 65: hexNum; - - vMaplightColorFilter[k] = ((float)hexNum * 16.0f) / 255.0f; - } - else if(strlen(r_maplightColor->string) == 6) { - int hexHigh = r_maplightColor->string[k * 2] - 48 < 0 ? 0 : r_maplightColor->string[k * 2] - 48; - hexHigh = hexHigh > 15 ? hexHigh - 65 + 48 + 10: hexHigh; - hexHigh = hexHigh > 15 ? hexHigh - 97 + 65: hexHigh; - - int hexLow = r_maplightColor->string[k * 2 + 1] - 48 < 0 ? 0 : r_maplightColor->string[k * 2 + 1] - 48; - hexLow = hexLow > 15 ? hexLow - 65 + 48 + 10: hexLow; - hexLow = hexLow > 15 ? hexLow - 97 + 65: hexLow; - - vMaplightColorFilter[k] = (((float)hexHigh * 16.0f) + (float)hexLow) / 255.0f; - } - else { - vMaplightColorFilter[k] = 1.0f; - } - } - // if we are in r_vertexLight mode, we don't need the lightmaps at all if (r_vertexLight->integer) return; @@ -112,25 +88,14 @@ static void R_LoadLightmaps( const lump_t* l ) for ( i = 0; i < tr.numLightmaps; ++i ) { // expand the 24 bit on-disk to 32 bit for ( j = 0; j < LIGHTMAP_SIZE * LIGHTMAP_SIZE; ++j ) { - R_ColorShiftLightingBytes( &p[j*3], &image[j*4] ); - image[j*4+3] = 255; - - vec3_t vColor = {(float)image[j * 4 + 0] / 255.0f, (float)image[j * 4 + 1] / 255.0f, (float)image[j * 4 + 2] / 255.0f}; - float greyColor = (vColor[0] + vColor[1] + vColor[2]) / 3.0f; + R_ColorShiftLightingBytes( &p[j * 3], &image[j * 4] ); - for(k = 0; k < 3; k++) { - if(r_maplightColorMode->integer > 0) { - vColor[k] = vColor[k] * r_maplightSaturation->value + greyColor * (1.0f - r_maplightSaturation->value); - } - else { - vColor[k] = greyColor; - } - vColor[k] *= r_maplightBrightness->value; - vColor[k] *= vMaplightColorFilter[k]; - vColor[k] = vColor[k] < 0.0f ? 0.0f : vColor[k]; - vColor[k] = vColor[k] > 1.0f ? 1.0f : vColor[k]; - image[j * 4 + k] = (byte)(vColor[k] * 255.0f); + for ( k = 0; k < 3; ++k ) { + const float c1 = (float)image[j * 4 + k] / 255.0f; + const float c2 = Com_Clamp( 0.0f, 1.0f, c1 ); + image[j * 4 + k] = (byte)(c2 * 255.0f); } + image[j * 4 + 3] = 255; } tr.lightmaps[i] = R_CreateImage( va("*lightmap%d",i), image, LIGHTMAP_SIZE, LIGHTMAP_SIZE, GL_RGB, IMG_NOMIPMAP | IMG_NOPICMIP, GL_CLAMP ); diff --git a/code/renderer/tr_gl2.cpp b/code/renderer/tr_gl2.cpp index 711cad6..d59c025 100644 --- a/code/renderer/tr_gl2.cpp +++ b/code/renderer/tr_gl2.cpp @@ -175,17 +175,33 @@ static void GL2_DynLights_LightingPass() /////////////////////////////////////////////////////////////// -static void GL2_DynLights_MultitextureStage( int stage ) +// returns qtrue if needs to break early +static qbool GL2_DynLights_MultitextureStage( int stage ) { - // everything we care about from the first stage is already done - const shaderStage_t* pStage = tess.xstages[++stage]; + static stageVars_t svarsMT; // this is a huge struct + + const shaderStage_t* pPrevStage = tess.xstages[stage++]; + const shaderStage_t* pStage = tess.xstages[stage]; + const qbool lightmapOnly = r_lightmap->integer && (pStage->type == ST_LIGHTMAP || pPrevStage->type == ST_LIGHTMAP); + + if ( lightmapOnly ) { + const int prevEnv = glState.texEnv[glState.currenttmu]; + GL_TexEnv( GL_REPLACE ); + if ( pStage->type == ST_LIGHTMAP ) { + R_BindAnimatedImage( &pStage->bundle ); + R_ComputeTexCoords( pStage, svarsMT ); + qglTexCoordPointer( 2, GL_FLOAT, 0, svarsMT.texcoords ); + } + qglDrawElements( GL_TRIANGLES, tess.numIndexes, GL_INDEX_TYPE, tess.indexes ); + GL_TexEnv( prevEnv ); + return qtrue; + } GL_SelectTexture( 1 ); qglEnable( GL_TEXTURE_2D ); GL_TexEnv( pStage->mtEnv ); R_BindAnimatedImage( &pStage->bundle ); - - static stageVars_t svarsMT; // this is a huge struct + R_ComputeTexCoords( pStage, svarsMT ); qglEnableClientState( GL_TEXTURE_COORD_ARRAY ); qglTexCoordPointer( 2, GL_FLOAT, 0, svarsMT.texcoords ); @@ -194,6 +210,8 @@ static void GL2_DynLights_MultitextureStage( int stage ) qglDisable( GL_TEXTURE_2D ); GL_SelectTexture( 0 ); + + return qfalse; } @@ -231,6 +249,7 @@ void GL2_DynLights_StageIterator() const shaderStage_t* pStage = tess.xstages[stage]; R_ComputeColors( pStage, tess.svars ); R_ComputeTexCoords( pStage, tess.svars ); + R_BindAnimatedImage( &pStage->bundle ); GL_State( pStage->stateBits ); @@ -239,11 +258,12 @@ void GL2_DynLights_StageIterator() // so color changes are ignored unless we "update" the color pointer again qglColorPointer( 4, GL_UNSIGNED_BYTE, 0, tess.svars.colors ); qglTexCoordPointer( 2, GL_FLOAT, 0, tess.svars.texcoords ); - - if (pStage->mtStages) { + + if ( pStage->mtStages ) { // we can't really cope with massive collapses, so assert( pStage->mtStages == 1 ); - GL2_DynLights_MultitextureStage( stage ); + if ( GL2_DynLights_MultitextureStage( stage ) ) + break; stage += pStage->mtStages; continue; } diff --git a/code/renderer/tr_init.cpp b/code/renderer/tr_init.cpp index 18b8e5a..7e238e8 100644 --- a/code/renderer/tr_init.cpp +++ b/code/renderer/tr_init.cpp @@ -60,6 +60,7 @@ cvar_t *r_drawentities; cvar_t *r_drawworld; cvar_t *r_speeds; cvar_t *r_fullbright; +cvar_t *r_lightmap; cvar_t *r_novis; cvar_t *r_nocull; cvar_t *r_nocurves; @@ -70,7 +71,6 @@ cvar_t *r_msaa; cvar_t *r_ignoreGLErrors; -cvar_t *r_lightmap; cvar_t *r_vertexLight; cvar_t *r_uiFullScreen; cvar_t *r_mode; @@ -481,15 +481,6 @@ static void R_Register() r_ext_compressed_textures = ri.Cvar_Get( "r_ext_compressed_textures", "0", CVAR_ARCHIVE | CVAR_LATCH ); r_ext_max_anisotropy = ri.Cvar_Get( "r_ext_max_anisotropy", "16", CVAR_ARCHIVE | CVAR_LATCH ); r_msaa = ri.Cvar_Get( "r_msaa", "0", CVAR_ARCHIVE | CVAR_LATCH ); - - /////////////////////////////////////////////////////////////// - r_maplightBrightness = ri.Cvar_Get("r_maplightBrightness", "1", CVAR_ARCHIVE | CVAR_LATCH); - AssertCvarRange(r_maplightBrightness, 0.0f, 8.0f, qfalse); - r_maplightSaturation = ri.Cvar_Get("r_maplightSaturation", "1", CVAR_ARCHIVE | CVAR_LATCH); - AssertCvarRange(r_maplightSaturation, 0.0f, 4.0f, qfalse); - r_maplightColorMode = ri.Cvar_Get("r_maplightColorMode", "1", CVAR_ARCHIVE | CVAR_LATCH); - AssertCvarRange(r_maplightColorMode, 0, 1, qtrue); - r_maplightColor = ri.Cvar_Get("r_maplightColor", "ffffff", CVAR_ARCHIVE | CVAR_LATCH); r_picmip = ri.Cvar_Get ("r_picmip", "0", CVAR_ARCHIVE | CVAR_LATCH ); AssertCvarRange( r_picmip, 0, 16, qtrue ); @@ -508,6 +499,7 @@ static void R_Register() r_customaspect = ri.Cvar_Get( "r_customaspect", "1.333", CVAR_ARCHIVE | CVAR_LATCH ); r_vertexLight = ri.Cvar_Get( "r_vertexLight", "0", CVAR_ARCHIVE | CVAR_LATCH ); r_fullbright = ri.Cvar_Get( "r_fullbright", "0", CVAR_ARCHIVE | CVAR_LATCH ); + r_lightmap = ri.Cvar_Get( "r_lightmap", "0", CVAR_ARCHIVE ); r_subdivisions = ri.Cvar_Get( "r_subdivisions", "4", CVAR_ARCHIVE | CVAR_LATCH ); #ifdef USE_R_SMP r_smp = ri.Cvar_Get( "r_smp", "0", CVAR_ARCHIVE | CVAR_LATCH ); @@ -560,7 +552,6 @@ static void R_Register() r_nocurves = ri.Cvar_Get ("r_nocurves", "0", CVAR_CHEAT ); r_drawworld = ri.Cvar_Get ("r_drawworld", "1", CVAR_CHEAT ); - r_lightmap = ri.Cvar_Get ("r_lightmap", "0", 0 ); r_portalOnly = ri.Cvar_Get ("r_portalOnly", "0", CVAR_CHEAT ); r_flareSize = ri.Cvar_Get ("r_flareSize", "40", CVAR_CHEAT); diff --git a/code/renderer/tr_local.h b/code/renderer/tr_local.h index 15a134f..16ba4d5 100644 --- a/code/renderer/tr_local.h +++ b/code/renderer/tr_local.h @@ -1011,14 +1011,6 @@ extern cvar_t *r_flareSize; extern cvar_t *r_flareFade; extern cvar_t *r_flareCoeff; -/////////////////////////////////////////////////////////////// -extern cvar_t *r_maplightBrightness; -extern cvar_t *r_maplightSaturation; -extern cvar_t *r_maplightColor; -extern cvar_t *r_maplightColorMode; -extern vec3_t vMaplightColorFilter; -/////////////////////////////////////////////////////////////// - void R_NoiseInit(); double R_NoiseGet4f( double x, double y, double z, double t ); @@ -1214,7 +1206,6 @@ void R_ComputeTexCoords( const shaderStage_t* pStage, stageVars_t& svars ); void R_BindAnimatedImage( const textureBundle_t* bundle ); void RB_FogPass(); -void RB_StageIteratorGeneric(); void RB_StageIteratorSky(); void RB_AddQuadStamp( vec3_t origin, vec3_t left, vec3_t up, byte *color ); diff --git a/code/renderer/tr_shade.cpp b/code/renderer/tr_shade.cpp index 141de02..4d5434f 100644 --- a/code/renderer/tr_shade.cpp +++ b/code/renderer/tr_shade.cpp @@ -262,33 +262,7 @@ void R_ComputeColors( const shaderStage_t* pStage, stageVars_t& svars ) } break; case CGEN_EXACT_VERTEX: - if(r_fullbright->integer < 0) { - for (i = 0; i < tess.numVertexes; i++) { - int k; - - vec3_t vColor = {(float)tess.vertexColors[i][0] * tr.identityLight / 255.0f, (float)tess.vertexColors[i][1] * tr.identityLight / 255.0f, (float)tess.vertexColors[i][2] * tr.identityLight / 255.0f}; - float greyColor = (vColor[0] + vColor[1] + vColor[2]) / 3.0f; - - for(k = 0; k < 3; k++) { - if(r_maplightColorMode->integer > 0) { - vColor[k] = vColor[k] * r_maplightSaturation->value + greyColor * (1.0f - r_maplightSaturation->value); - } - else { - vColor[k] = greyColor; - } - vColor[k] *= r_maplightBrightness->value; - vColor[k] *= vMaplightColorFilter[k]; - vColor[k] = vColor[k] < 0.0f ? 0.0f : vColor[k]; - vColor[k] = vColor[k] > 1.0f ? 1.0f : vColor[k]; - svars.colors[i][k] = (byte)(vColor[k] * 255.0f); - } - - svars.colors[i][3] = tess.vertexColors[i][3]; - } - } - else { - Com_Memcpy( svars.colors, tess.vertexColors, tess.numVertexes * sizeof( tess.vertexColors[0] ) ); - } + Com_Memcpy( svars.colors, tess.vertexColors, tess.numVertexes * sizeof( tess.vertexColors[0] ) ); break; case CGEN_ONE_MINUS_VERTEX: if ( tr.identityLight == 1 ) @@ -503,82 +477,3 @@ void R_ComputeTexCoords( const shaderStage_t* pStage, stageVars_t& svars ) } } - -/////////////////////////////////////////////////////////////// - - -static void RB_IterateStagesGeneric( const shaderCommands_t* input ) -{ - for (int stage = 0; stage < MAX_SHADER_STAGES; ++stage) - { - const shaderStage_t* pStage = tess.xstages[stage]; - if ( !pStage ) - break; - - R_ComputeColors( pStage, tess.svars ); - R_ComputeTexCoords( pStage, tess.svars ); - - if ( r_lightmap->integer && (pStage->type == ST_LIGHTMAP) ) - GL_TexEnv( GL_REPLACE ); - - R_BindAnimatedImage( &pStage->bundle ); - GL_State( pStage->stateBits ); - R_DrawElements( input->numIndexes, input->indexes ); - - // allow skipping out to show just lightmaps during development - if ( r_lightmap->integer && (pStage->type == ST_LIGHTMAP) ) { - GL_TexEnv( GL_MODULATE ); - break; - } - } -} - - -void RB_StageIteratorGeneric() -{ - shaderCommands_t* input = &tess; - - if (tess.pass == shaderCommands_t::TP_LIGHT) - return; - - GL_Program(); - - RB_DeformTessGeometry(); - - GL_Cull( input->shader->cullType ); - - if ( input->shader->polygonOffset ) - { - qglEnable( GL_POLYGON_OFFSET_FILL ); - //qglPolygonOffset( r_offsetFactor->value, r_offsetUnits->value ); - } - - // geometry is per-shader and can be compiled - // color and tc are per-stage, and can't - - qglDisableClientState( GL_COLOR_ARRAY ); - qglDisableClientState( GL_TEXTURE_COORD_ARRAY ); - - qglVertexPointer( 3, GL_FLOAT, 16, input->xyz ); // padded for SIMD - qglLockArraysEXT( 0, input->numVertexes ); - - qglEnableClientState( GL_COLOR_ARRAY ); - qglColorPointer( 4, GL_UNSIGNED_BYTE, 0, input->svars.colors ); - qglEnableClientState( GL_TEXTURE_COORD_ARRAY ); - qglTexCoordPointer( 2, GL_FLOAT, 0, input->svars.texcoords[0] ); - - // call shader function - RB_IterateStagesGeneric( input ); - - if ( tess.fogNum && tess.shader->fogPass ) { - RB_FogPass(); - } - - qglUnlockArraysEXT(); - - if ( input->shader->polygonOffset ) - { - qglDisable( GL_POLYGON_OFFSET_FILL ); - } -} - diff --git a/code/renderer/tr_shader.cpp b/code/renderer/tr_shader.cpp index c08ce37..82e6d76 100644 --- a/code/renderer/tr_shader.cpp +++ b/code/renderer/tr_shader.cpp @@ -1541,8 +1541,6 @@ static void ComputeStageIteratorFunc() } shader.siFunc = GL2_DynLights_StageIterator; - - //shader.siFunc = RB_StageIteratorGeneric; } @@ -2398,8 +2396,6 @@ void R_ShaderList_f( void ) ri.Printf( PRINT_ALL, " " ); } else if ( shader->siFunc == RB_StageIteratorSky ) { ri.Printf( PRINT_ALL, "sky " ); - } else if ( shader->siFunc == RB_StageIteratorGeneric ) { - ri.Printf( PRINT_ALL, "lgc " ); } else { ri.Printf( PRINT_ALL, "??? " ); }