From f3145a9649b735f16a575c13d05f125a5545e015 Mon Sep 17 00:00:00 2001 From: slipher Date: Wed, 25 Feb 2026 05:31:46 -0600 Subject: [PATCH 1/4] Cleanup: remove GLShader::MissesRequiredMacros For checking if a macro can't be used without another macro, we can just use HasConflictingMacros(). No need to have separate functions to check flags that must be on and flags that must be off. The one override of MissesRequiredMacros wasn't even using it for the right thing (a global GL config setting instead of a macro). --- src/engine/renderer/gl_shader.cpp | 19 +++++-------------- src/engine/renderer/gl_shader.h | 6 ------ 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/engine/renderer/gl_shader.cpp b/src/engine/renderer/gl_shader.cpp index f23055feb4..17a4f0ba69 100644 --- a/src/engine/renderer/gl_shader.cpp +++ b/src/engine/renderer/gl_shader.cpp @@ -868,7 +868,11 @@ static bool IsUnusedPermutation( const char *compileMacros ) const char* token; while ( *( token = COM_ParseExt2( &compileMacros, false ) ) ) { - if ( strcmp( token, "USE_DELUXE_MAPPING" ) == 0 ) + if ( strcmp( token, "USE_VERTEX_SKINNING" ) == 0 ) + { + if ( !glConfig.vboVertexSkinningAvailable ) return true; + } + else if ( strcmp( token, "USE_DELUXE_MAPPING" ) == 0 ) { if ( !glConfig.deluxeMapping ) return true; } @@ -2042,11 +2046,6 @@ bool GLCompileMacro_USE_VERTEX_SKINNING::HasConflictingMacros( size_t permutatio return false; } -bool GLCompileMacro_USE_VERTEX_SKINNING::MissesRequiredMacros( size_t /*permutation*/, const std::vector< GLCompileMacro * > &/*macros*/ ) const -{ - return !glConfig.vboVertexSkinningAvailable; -} - bool GLCompileMacro_USE_VERTEX_ANIMATION::HasConflictingMacros( size_t permutation, const std::vector< GLCompileMacro * > ¯os ) const { for (const GLCompileMacro* macro : macros) @@ -2246,10 +2245,6 @@ uint32_t GLShader::GetUniqueCompileMacros( size_t permutation, const int type ) continue; } - if ( macro->MissesRequiredMacros( permutation, _compileMacros ) ) { - continue; - } - if ( !( macro->GetShaderTypes() & type ) ) { continue; } @@ -2270,10 +2265,6 @@ bool GLShader::GetCompileMacrosString( size_t permutation, std::string &compileM return false; } - if ( macro->MissesRequiredMacros( permutation, _compileMacros ) ) { - return false; - } - if ( !( macro->GetShaderTypes() & type ) ) { return false; } diff --git a/src/engine/renderer/gl_shader.h b/src/engine/renderer/gl_shader.h index 781438e1b5..0f857de57c 100644 --- a/src/engine/renderer/gl_shader.h +++ b/src/engine/renderer/gl_shader.h @@ -952,11 +952,6 @@ class GLCompileMacro return false; } - virtual bool MissesRequiredMacros( size_t, const std::vector& ) const - { - return false; - } - virtual uint32_t GetRequiredVertexAttributes() const { return 0; @@ -1075,7 +1070,6 @@ class GLCompileMacro_USE_VERTEX_SKINNING : } bool HasConflictingMacros( size_t permutation, const std::vector< GLCompileMacro * > ¯os ) const override; - bool MissesRequiredMacros( size_t permutation, const std::vector< GLCompileMacro * > ¯os ) const override; uint32_t GetRequiredVertexAttributes() const override { From 3763d817d1c74051f0a4841ebb4523609185446f Mon Sep 17 00:00:00 2001 From: slipher Date: Wed, 25 Feb 2026 05:50:35 -0600 Subject: [PATCH 2/4] GL shaders: never build grid deluxe without grid lighting --- src/engine/renderer/gl_shader.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/engine/renderer/gl_shader.cpp b/src/engine/renderer/gl_shader.cpp index 17a4f0ba69..5e149a6c13 100644 --- a/src/engine/renderer/gl_shader.cpp +++ b/src/engine/renderer/gl_shader.cpp @@ -2116,6 +2116,12 @@ bool GLCompileMacro_USE_GRID_DELUXE_MAPPING::HasConflictingMacros(size_t permuta { return true; } + + // grid lighting is required + if ((macro->GetType() == USE_GRID_LIGHTING) && !(permutation & macro->GetBit())) + { + return true; + } } return false; From e0facd712bf9b64e5ff34d6869bb2a8806325594 Mon Sep 17 00:00:00 2001 From: slipher Date: Sat, 21 Feb 2026 02:53:38 -0600 Subject: [PATCH 3/4] Use grid deluxe for world with r_lightMode 2 Increased macro permutations isn't much of a concern any more since we don't build unused ones by default. --- src/engine/renderer/gl_shader.cpp | 15 +-------------- src/engine/renderer/gl_shader.h | 2 -- src/engine/renderer/tr_bsp.cpp | 6 +++++- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/engine/renderer/gl_shader.cpp b/src/engine/renderer/gl_shader.cpp index 5e149a6c13..540dd24dc6 100644 --- a/src/engine/renderer/gl_shader.cpp +++ b/src/engine/renderer/gl_shader.cpp @@ -2112,7 +2112,7 @@ bool GLCompileMacro_USE_GRID_DELUXE_MAPPING::HasConflictingMacros(size_t permuta { for (const GLCompileMacro* macro : macros) { - if ((permutation & macro->GetBit()) != 0 && (macro->GetType() == USE_DELUXE_MAPPING || macro->GetType() == USE_BSP_SURFACE)) + if ((permutation & macro->GetBit()) != 0 && (macro->GetType() == USE_DELUXE_MAPPING)) { return true; } @@ -2140,19 +2140,6 @@ bool GLCompileMacro_USE_GRID_LIGHTING::HasConflictingMacros(size_t permutation, return false; } -bool GLCompileMacro_USE_BSP_SURFACE::HasConflictingMacros(size_t permutation, const std::vector ¯os) const -{ - for (const GLCompileMacro* macro : macros) - { - if ((permutation & macro->GetBit()) != 0 && (macro->GetType() == USE_GRID_DELUXE_MAPPING)) - { - return true; - } - } - - return false; -} - void GLShader::RegisterUniform( GLUniform* uniform ) { _uniforms.push_back( uniform ); } diff --git a/src/engine/renderer/gl_shader.h b/src/engine/renderer/gl_shader.h index 0f857de57c..809918df6f 100644 --- a/src/engine/renderer/gl_shader.h +++ b/src/engine/renderer/gl_shader.h @@ -1029,8 +1029,6 @@ class GLCompileMacro_USE_BSP_SURFACE : return "USE_BSP_SURFACE"; } - bool HasConflictingMacros(size_t permutation, const std::vector< GLCompileMacro * > ¯os) const override; - EGLCompileMacro GetType() const override { return EGLCompileMacro::USE_BSP_SURFACE; diff --git a/src/engine/renderer/tr_bsp.cpp b/src/engine/renderer/tr_bsp.cpp index 3655ea0fb2..aabcf32db6 100644 --- a/src/engine/renderer/tr_bsp.cpp +++ b/src/engine/renderer/tr_bsp.cpp @@ -4657,7 +4657,11 @@ static void SetWorldLight() { // Game model surfaces use grid lighting, they don't have vertex light colors. tr.modelDeluxe = deluxeMode_t::GRID; - // Only game models use emulated deluxe map from light direction grid. + // Only game models use emulated deluxe map from light direction grid, unless the + // `r_lightMode 2` debug option is used. + if ( tr.worldLight == lightMode_t::GRID ) { + tr.worldDeluxe = deluxeMode_t::GRID; + } } } From 2cef7e4157588cc0817933092b6d007f8f9e5125 Mon Sep 17 00:00:00 2001 From: slipher Date: Wed, 25 Feb 2026 15:00:41 -0600 Subject: [PATCH 4/4] Use half-Lambert lighting iff grid lighting is used Half-Lambert lighting makes goes well with the light grid: the single light direction is a crude approximation, so it makes sense to soften the directionality. For now this only changes anything for the `r_lightMode 2` debug option, but it may be useful for implementing grid lighting for BSP entities later. --- src/engine/renderer/glsl_source/computeLight_fp.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/renderer/glsl_source/computeLight_fp.glsl b/src/engine/renderer/glsl_source/computeLight_fp.glsl index f3c23bf9e9..aa0ad85f7f 100644 --- a/src/engine/renderer/glsl_source/computeLight_fp.glsl +++ b/src/engine/renderer/glsl_source/computeLight_fp.glsl @@ -84,7 +84,7 @@ void computeDeluxeLight( vec3 lightDir, vec3 normal, vec3 viewDir, vec3 lightCol // clamp( NdotL, 0.0, 1.0 ) is done below float NdotL = dot( normal, lightDir ); - #if !defined(USE_BSP_SURFACE) && defined(r_halfLambertLighting) + #if defined(USE_GRID_LIGHTING) && defined(r_halfLambertLighting) // http://developer.valvesoftware.com/wiki/Half_Lambert NdotL = NdotL * 0.5 + 0.5; NdotL *= NdotL;