From f36392c1288106919534acd937eaaa365da92807 Mon Sep 17 00:00:00 2001 From: myT Date: Thu, 9 Jan 2020 23:09:39 +0100 Subject: [PATCH] fixed r_lightmap affecting non-opaque surfaces --- code/renderer/tr_shader.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/code/renderer/tr_shader.cpp b/code/renderer/tr_shader.cpp index dba6135..0f4bbd0 100644 --- a/code/renderer/tr_shader.cpp +++ b/code/renderer/tr_shader.cpp @@ -2128,10 +2128,20 @@ static shader_t* FinishShader() stages[i].bundle.image[0] = tr.whiteImage; } } - } else if ( r_lightmap->integer ) { + } else if ( + r_lightmap->integer && + ( shader.contentFlags & CONTENTS_TRANSLUCENT ) == 0 && + shader.sort <= SS_OPAQUE ) { // we reduce it down to a single lightmap stage with the same state bits as // the current first stage (if the shader uses a lightmap at all) + // @NOTE: we ignore all surfaces that aren't fully opaque because: + // a) it's hard to know what level of uniform opacity would emulate the original look best + // b) alpha-tested surfaces that have been turned into alpha-blended ones can't just use any given sort key: + // you can always find or design a case that won't work correctly + // for decals entirely pressed against opaque surfaces, we could use a keyword ("polygonoffset" or something new) + // to know that we should not draw them at all, but we just shouldn't trust level designers + // look for "real" lightmaps first (straight from the .bsp file itself) int stageIndex = -1; for ( int i = 0; i < shader.numStages; ++i ) { @@ -2153,7 +2163,7 @@ static shader_t* FinishShader() const int stateBits = stages[0].stateBits; if ( stageIndex > 0 ) - memcpy(stages, stages + stageIndex, sizeof(stages[0])); + memcpy( stages, stages + stageIndex, sizeof( stages[0] ) ); if ( stageIndex >= 0 ) { for ( int i = 1; i < shader.numStages; ++i ) {