From 3d6aa05694cdfbfd630edb95f1096ed107b6a5d4 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Sun, 4 Feb 2018 11:15:13 -0600 Subject: [PATCH] OpenGL2: Fix dark lightmap on shader in mpteam6 Team Arena's mpteam6 map has a shader textures/base_wall2/space_concrete that contains an opaque stage, two non-lightmap blendfunc filter stages, a blendfunc add stage, and a lightmap stage. The lightmap was attached to all four of the non-lightmap stages causing the filter stages to darken the lightmap multiple times. Change setting up the lightall GLSL shader to only use lightmap if it's the first stage or not a blendfunc filter stage. Now only the opaque and blendfunc add stages of the mpteam6 shader use the lightmap. Reported by Alexander Nadeau (wareya). --- code/renderergl2/tr_shader.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/code/renderergl2/tr_shader.c b/code/renderergl2/tr_shader.c index b4f47004..b1c88f9b 100644 --- a/code/renderergl2/tr_shader.c +++ b/code/renderergl2/tr_shader.c @@ -2421,6 +2421,8 @@ static int CollapseStagesToGLSL(void) if (!skip) { + qboolean usedLightmap = qfalse; + for (i = 0; i < MAX_SHADER_STAGES; i++) { shaderStage_t *pStage = &stages[i]; @@ -2479,7 +2481,16 @@ static int CollapseStagesToGLSL(void) case ST_COLORMAP: if (pStage2->bundle[0].tcGen == TCGEN_LIGHTMAP) { - lightmap = pStage2; + int blendBits = pStage->stateBits & ( GLS_DSTBLEND_BITS | GLS_SRCBLEND_BITS ); + + // Only add lightmap to blendfunc filter stage if it's the first time lightmap is used + // otherwise it will cause the shader to be darkened by the lightmap multiple times. + if (!usedLightmap || (blendBits != (GLS_DSTBLEND_SRC_COLOR | GLS_SRCBLEND_ZERO) + && blendBits != (GLS_DSTBLEND_ZERO | GLS_SRCBLEND_DST_COLOR))) + { + lightmap = pStage2; + usedLightmap = qtrue; + } } break;