From 9773f1066938e624758c6674245d04aec7517241 Mon Sep 17 00:00:00 2001 From: slipher Date: Fri, 17 Oct 2025 10:48:08 -0500 Subject: [PATCH 1/5] NUKE alphaAddOne bit in color modulate There are no differences in my screenshot test suite as a result of removing this. This alpha := 1 thing only existed in the `generic` shader; its absence in lightMapping is further evidence suggesting it is not needed. --- src/engine/renderer/gl_shader.h | 11 +---------- src/engine/renderer/glsl_source/common.glsl | 10 +--------- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/src/engine/renderer/gl_shader.h b/src/engine/renderer/gl_shader.h index ec6faee19a..2fe9ae8878 100644 --- a/src/engine/renderer/gl_shader.h +++ b/src/engine/renderer/gl_shader.h @@ -2738,7 +2738,6 @@ struct colorModulation_t { float alphaGen = 0.0f; float lightFactor = 1.0f; bool useVertexLightFactor = false; - bool alphaAddOne = true; }; static colorModulation_t ColorModulateColorGen( @@ -2752,8 +2751,6 @@ static colorModulation_t ColorModulateColorGen( switch ( colorGen ) { case colorGen_t::CGEN_VERTEX: - colorModulation.alphaAddOne = false; - if ( vertexOverbright ) { // vertexOverbright is only needed for non-lightmapped cases. When there is a @@ -2768,7 +2765,6 @@ static colorModulation_t ColorModulateColorGen( break; case colorGen_t::CGEN_ONE_MINUS_VERTEX: - colorModulation.alphaAddOne = false; colorModulation.colorGen = -1.0f; break; @@ -2785,12 +2781,10 @@ static colorModulation_t ColorModulateColorGen( switch ( alphaGen ) { case alphaGen_t::AGEN_VERTEX: - colorModulation.alphaAddOne = false;; colorModulation.alphaGen = 1.0f; break; case alphaGen_t::AGEN_ONE_MINUS_VERTEX: - colorModulation.alphaAddOne = false;; colorModulation.alphaGen = -1.0f; break; @@ -2827,7 +2821,7 @@ class u_ColorModulateColorGen_Float : colorModulate_Float[ 0 ] = colorModulation.colorGen; colorModulate_Float[ 1 ] = colorModulation.lightFactor; colorModulate_Float[ 1 ] *= colorModulation.useVertexLightFactor ? -1.0f : 1.0f; - colorModulate_Float[ 2 ] = colorModulation.alphaAddOne; + colorModulate_Float[ 2 ] = {}; colorModulate_Float[ 3 ] = colorModulation.alphaGen; this->SetValue( colorModulate_Float ); @@ -2859,7 +2853,6 @@ class u_ColorModulateColorGen_Uint : COLOR_MINUS_ONE = 1, ALPHA_ONE = 2, ALPHA_MINUS_ONE = 3, - ALPHA_ADD_ONE = 4, // <-- Insert new bits there. IS_LIGHT_STYLE = 27, LIGHTFACTOR_BIT0 = 28, @@ -2879,8 +2872,6 @@ class u_ColorModulateColorGen_Uint : << Util::ordinal( ColorModulate_Bit::ALPHA_ONE ); colorModulate_Uint |= ( colorModulation.alphaGen == -1.0f ) << Util::ordinal( ColorModulate_Bit::ALPHA_MINUS_ONE ); - colorModulate_Uint |= colorModulation.alphaAddOne - << Util::ordinal( ColorModulate_Bit::ALPHA_ADD_ONE ); colorModulate_Uint |= colorModulation.useVertexLightFactor << Util::ordinal( ColorModulate_Bit::IS_LIGHT_STYLE ); colorModulate_Uint |= uint32_t( colorModulation.lightFactor ) diff --git a/src/engine/renderer/glsl_source/common.glsl b/src/engine/renderer/glsl_source/common.glsl index 1c7013a74d..e90fd5474b 100644 --- a/src/engine/renderer/glsl_source/common.glsl +++ b/src/engine/renderer/glsl_source/common.glsl @@ -68,8 +68,7 @@ colorMod << 0: color * 1 colorMod << 1: color * ( -1 ) colorMod << 2: alpha * 1 colorMod << 3: alpha * ( -1 ) -colorMod << 4: alpha = 1 -colorMod << 5-26: available for future usage +colorMod << 4-26: available for future usage colorMod << 27: color += lightFactor colorMod << 28-31: lightFactor @@ -78,7 +77,6 @@ colorMod float format: colorMod[ 0 ]: color * f colorMod[ 1 ] absolute value: lightFactor colorMod[ 1 ] minus sign: color += lightFactor -colorMod[ 2 ]: alpha = 1 colorMod[ 3 ]: alpha * f */ vec4 ColorModulateToColor( const in colorModulatePack colorMod ) @@ -101,7 +99,6 @@ vec4 ColorModulateToColor( const in colorModulatePack colorMod ) struct ModBits_t { - bool alphaAddOne; bool useVertexLightFactor; }; @@ -110,10 +107,8 @@ ModBits_t ColorModulateToBits( const in colorModulatePack colorMod ) ModBits_t modBits; #if defined(HAVE_EXT_gpu_shader4) - modBits.alphaAddOne = bool( ( colorMod >> 4u ) & 1u ); modBits.useVertexLightFactor = bool( ( colorMod >> 27u ) & 1u ); #else - modBits.alphaAddOne = colorMod.b != 0; modBits.useVertexLightFactor = colorMod.g < 0; #endif @@ -159,9 +154,6 @@ void ColorModulateColor_lightFactor( ModBits_t modBits = ColorModulateToBits( colorMod ); float lightFactor = ColorModulateToLightFactor( colorMod ); - // This is used to skip vertex colours if the colorMod doesn't need them. - color.a = modBits.alphaAddOne ? 1.0 : color.a; - colorModulation.rgb += vec3( modBits.useVertexLightFactor ? lightFactor : 0 ); vec4 unpackedColor = UnpackColor( packedColor ); From 5dde91b34eed3c3fe4385829bef27e027f32675d Mon Sep 17 00:00:00 2001 From: slipher Date: Fri, 17 Oct 2025 11:38:56 -0500 Subject: [PATCH 2/5] Fix /listMaterialSystemStages variant descriptions Also add a static assert that the descriptions list has the right size. --- src/engine/renderer/Material.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/engine/renderer/Material.cpp b/src/engine/renderer/Material.cpp index 6559446550..c901c63852 100644 --- a/src/engine/renderer/Material.cpp +++ b/src/engine/renderer/Material.cpp @@ -776,12 +776,14 @@ static std::string GetStageInfo( const shaderStage_t* pStage, const uint32_t dyn "base variant ", "vertex overbright ", "vertex-lit ", - "fullbright ", "vertex overbright vertex-lit ", + "fullbright ", "vertex overbright fullbright ", "vertex-lit fullbright ", "vertex overbright vertex-lit fullbright" }; + static_assert( ARRAY_LEN( stageVariants ) == ShaderStageVariant::ALL, + "update stage variant text descriptions" ); uint32_t variants = 0; for ( int i = 0; i < ShaderStageVariant::ALL && variants < pStage->variantOffset; i++ ) { From dd0b9607b20f7035db6cbf756304f063b23a7654 Mon Sep 17 00:00:00 2001 From: slipher Date: Fri, 17 Oct 2025 16:32:39 -0500 Subject: [PATCH 3/5] Refactor SetLightDeluxeMode arguments Take pointer to stage instead of pointer to shader plus stage type. --- src/engine/renderer/Material.cpp | 12 ++++++------ src/engine/renderer/Material.h | 2 +- src/engine/renderer/ShadeCommon.h | 10 +++++----- src/engine/renderer/tr_shade.cpp | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/engine/renderer/Material.cpp b/src/engine/renderer/Material.cpp index c901c63852..f2c8c24e90 100644 --- a/src/engine/renderer/Material.cpp +++ b/src/engine/renderer/Material.cpp @@ -1159,7 +1159,7 @@ void ProcessMaterialLightMapping( Material* material, shaderStage_t* pStage, Mat lightMode_t lightMode; deluxeMode_t deluxeMode; - SetLightDeluxeMode( surface, pStage->shader, pStage->type, lightMode, deluxeMode ); + SetLightDeluxeMode( surface, pStage, lightMode, deluxeMode ); bool enableDeluxeMapping = ( deluxeMode == deluxeMode_t::MAP ); bool enableGridLighting = ( lightMode == lightMode_t::GRID ); @@ -1242,7 +1242,7 @@ void ProcessMaterialLiquid( Material* material, shaderStage_t* pStage, MaterialS lightMode_t lightMode; deluxeMode_t deluxeMode; - SetLightDeluxeMode( surface, pStage->shader, pStage->type, lightMode, deluxeMode ); + SetLightDeluxeMode( surface, pStage, lightMode, deluxeMode ); material->hasHeightMapInNormalMap = pStage->hasHeightMapInNormalMap; material->enableReliefMapping = pStage->enableReliefMapping; @@ -1390,7 +1390,7 @@ void MaterialSystem::ProcessStage( MaterialSurface* surface, shaderStage_t* pSta uint32_t& previousMaterialID, bool skipStageSync ) { lightMode_t lightMode; deluxeMode_t deluxeMode; - SetLightDeluxeMode( surface, shader, pStage->type, lightMode, deluxeMode ); + SetLightDeluxeMode( surface, pStage, lightMode, deluxeMode ); const bool mayUseVertexOverbright = pStage->type == stageType_t::ST_COLORMAP && surface->bspSurface && pStage->shaderBinder == BindShaderGeneric3D; const bool vertexLit = lightMode == lightMode_t::VERTEX && pStage->shaderBinder == BindShaderLightMapping; @@ -1479,7 +1479,7 @@ void MaterialSystem::ProcessStage( MaterialSurface* surface, shaderStage_t* pSta pStage->initialized = true; AddStage( surface, pStage, stage, mayUseVertexOverbright, vertexLit, fullbright ); - AddStageTextures( surface, shader, pStage, stage, &materials[previousMaterialID] ); + AddStageTextures( surface, pStage, stage, &materials[previousMaterialID] ); surface->materialIDs[stage] = previousMaterialID; surface->materialPackIDs[stage] = materialPack; @@ -1539,7 +1539,7 @@ void MaterialSystem::GLSLRestart() { } } -void MaterialSystem::AddStageTextures( MaterialSurface* surface, shader_t* shader, shaderStage_t* pStage, const uint32_t stage, Material* material ) { +void MaterialSystem::AddStageTextures( MaterialSurface* surface, shaderStage_t* pStage, const uint32_t stage, Material* material ) { TextureData textureData; int bundleNum = 0; @@ -1570,7 +1570,7 @@ void MaterialSystem::AddStageTextures( MaterialSurface* surface, shader_t* shade // Add lightmap and deluxemap for this surface to the material as well lightMode_t lightMode; deluxeMode_t deluxeMode; - SetLightDeluxeMode( surface, shader, pStage->type, lightMode, deluxeMode ); + SetLightDeluxeMode( surface, pStage, lightMode, deluxeMode ); // u_Map, u_DeluxeMap image_t* lightmap = SetLightMap( surface, lightMode ); diff --git a/src/engine/renderer/Material.h b/src/engine/renderer/Material.h index e9eb42eb1a..219cacc1c0 100644 --- a/src/engine/renderer/Material.h +++ b/src/engine/renderer/Material.h @@ -374,7 +374,7 @@ class MaterialSystem { return texData.size(); } - void AddStageTextures( MaterialSurface* surface, shader_t* shader, shaderStage_t* pStage, const uint32_t stage, Material* material ); + void AddStageTextures( MaterialSurface* surface, shaderStage_t* pStage, const uint32_t stage, Material* material ); void AddStage( MaterialSurface* surface, shaderStage_t* pStage, uint32_t stage, const bool mayUseVertexOverbright, const bool vertexLit, const bool fullbright ); void ProcessStage( MaterialSurface* surface, shaderStage_t* pStage, shader_t* shader, uint32_t* packIDs, uint32_t& stage, diff --git a/src/engine/renderer/ShadeCommon.h b/src/engine/renderer/ShadeCommon.h index 7d8f107439..50388194db 100644 --- a/src/engine/renderer/ShadeCommon.h +++ b/src/engine/renderer/ShadeCommon.h @@ -114,18 +114,18 @@ template bool isExplicitelyVertexLitSurface( Obj* obj ) return lastStage != stages && stages[0].rgbGen == colorGen_t::CGEN_VERTEX; } -template void SetLightDeluxeMode( Obj* obj, shader_t* shader, - stageType_t stageType, +template void SetLightDeluxeMode( + const Obj *obj, const shaderStage_t *stage, lightMode_t& lightMode, deluxeMode_t& deluxeMode ) { lightMode = lightMode_t::FULLBRIGHT; deluxeMode = deluxeMode_t::NONE; - if ( hasExplicitelyDisabledLightMap( shader ) && !isExplicitelyVertexLitSurface( shader ) ) + if ( hasExplicitelyDisabledLightMap( stage->shader ) && !isExplicitelyVertexLitSurface( stage->shader ) ) { // Use fullbright on “surfaceparm nolightmap” materials. } - else if ( stageType == stageType_t::ST_COLLAPSE_COLORMAP ) + else if ( stage->type == stageType_t::ST_COLLAPSE_COLORMAP ) { /* Use fullbright for collapsed stages without lightmaps, for example: @@ -137,7 +137,7 @@ template void SetLightDeluxeMode( Obj* obj, shader_t* shader, This is doable for some complex multi-stage materials. */ } - else if( stageType == stageType_t::ST_LIQUIDMAP ) + else if( stage->type == stageType_t::ST_LIQUIDMAP ) { lightMode = tr.modelLight; deluxeMode = tr.modelDeluxe; diff --git a/src/engine/renderer/tr_shade.cpp b/src/engine/renderer/tr_shade.cpp index 19c481d928..bc261a58a3 100644 --- a/src/engine/renderer/tr_shade.cpp +++ b/src/engine/renderer/tr_shade.cpp @@ -795,7 +795,7 @@ void ProcessShaderGeneric3D( const shaderStage_t* pStage ) { void ProcessShaderLightMapping( const shaderStage_t* pStage ) { lightMode_t lightMode; deluxeMode_t deluxeMode; - SetLightDeluxeMode( &tess, tess.surfaceShader, pStage->type, lightMode, deluxeMode ); + SetLightDeluxeMode( &tess, pStage, lightMode, deluxeMode ); bool enableDeluxeMapping = ( deluxeMode == deluxeMode_t::MAP ); bool enableGridLighting = ( lightMode == lightMode_t::GRID ); @@ -845,7 +845,7 @@ void ProcessShaderHeatHaze( const shaderStage_t* pStage ) { void ProcessShaderLiquid( const shaderStage_t* pStage ) { lightMode_t lightMode; deluxeMode_t deluxeMode; - SetLightDeluxeMode( &tess, tess.surfaceShader, pStage->type, lightMode, deluxeMode ); + SetLightDeluxeMode( &tess, pStage, lightMode, deluxeMode ); gl_liquidShader->SetHeightMapInNormalMap( pStage->hasHeightMapInNormalMap ); @@ -1000,7 +1000,7 @@ void Render_lightMapping( shaderStage_t *pStage ) lightMode_t lightMode; deluxeMode_t deluxeMode; - SetLightDeluxeMode( &tess, tess.surfaceShader, pStage->type, lightMode, deluxeMode ); + SetLightDeluxeMode( &tess, pStage, lightMode, deluxeMode ); // u_Map, u_DeluxeMap image_t *lightmap = SetLightMap( &tess, lightMode ); @@ -1507,7 +1507,7 @@ void Render_liquid( shaderStage_t *pStage ) lightMode_t lightMode; deluxeMode_t deluxeMode; - SetLightDeluxeMode( &tess, tess.surfaceShader, pStage->type, lightMode, deluxeMode ); + SetLightDeluxeMode( &tess, pStage, lightMode, deluxeMode ); // choose right shader program ProcessShaderLiquid( pStage ); From 84e4ca542b370d9bf6492cdaf6167bab76b65ee7 Mon Sep 17 00:00:00 2001 From: slipher Date: Fri, 17 Oct 2025 09:21:11 -0500 Subject: [PATCH 4/5] Enable realtime lights for vertex-lit surfaces Use the lightMapping GLSL shader instead of `generic` to render BSP surfaces that are vertex-lit due to an explicit `rgbGen vertex`. This makes them use the same code path as BSP surfaces where vertex lighting is automatically selected due to the absence of a lightmap. So now it is possible to render realtime lights on explicitly vertex-lit surfaces, though they are still not as bright as they should be due to https://github.com/DaemonEngine/Daemon/issues/1415. In the following commit, this will let us remove some ugly code used for applying the overbright factor to the `generic` shader. --- src/engine/renderer/Material.cpp | 3 ++- src/engine/renderer/ShadeCommon.h | 7 ++++++- src/engine/renderer/tr_bsp.cpp | 2 +- src/engine/renderer/tr_local.h | 4 ++++ src/engine/renderer/tr_shader.cpp | 9 +++++++++ 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/engine/renderer/Material.cpp b/src/engine/renderer/Material.cpp index f2c8c24e90..59f02e9731 100644 --- a/src/engine/renderer/Material.cpp +++ b/src/engine/renderer/Material.cpp @@ -680,7 +680,8 @@ void MaterialSystem::GenerateWorldCommandBuffer( std::vector& s surfaceCommand.drawCommand.baseInstance |= surface.texDataDynamic[stage] ? ( surface.texDataIDs[stage] + texData.size() ) << TEX_BUNDLE_BITS : surface.texDataIDs[stage] << TEX_BUNDLE_BITS; - surfaceCommand.drawCommand.baseInstance |= ( HasLightMap( &surface ) ? GetLightMapNum( &surface ) : 255 ) << LIGHTMAP_BITS; + surfaceCommand.drawCommand.baseInstance |= + ( !pStage->forceVertexLighting && HasLightMap( &surface ) ? GetLightMapNum( &surface ) : 255 ) << LIGHTMAP_BITS; surfaceCommands[cmdID] = surfaceCommand; material->drawCommandCount++; diff --git a/src/engine/renderer/ShadeCommon.h b/src/engine/renderer/ShadeCommon.h index 50388194db..da4cac0fcd 100644 --- a/src/engine/renderer/ShadeCommon.h +++ b/src/engine/renderer/ShadeCommon.h @@ -121,7 +121,12 @@ template void SetLightDeluxeMode( lightMode = lightMode_t::FULLBRIGHT; deluxeMode = deluxeMode_t::NONE; - if ( hasExplicitelyDisabledLightMap( stage->shader ) && !isExplicitelyVertexLitSurface( stage->shader ) ) + if ( stage->forceVertexLighting ) + { + lightMode = lightMode_t::VERTEX; + deluxeMode = deluxeMode_t::NONE; + } + else if ( hasExplicitelyDisabledLightMap( stage->shader ) && !isExplicitelyVertexLitSurface( stage->shader ) ) { // Use fullbright on “surfaceparm nolightmap” materials. } diff --git a/src/engine/renderer/tr_bsp.cpp b/src/engine/renderer/tr_bsp.cpp index 120ddbe28d..3f025727f5 100644 --- a/src/engine/renderer/tr_bsp.cpp +++ b/src/engine/renderer/tr_bsp.cpp @@ -871,7 +871,7 @@ static shader_t* ShaderForShaderNum( int shaderNum ) { dshader_t* dsh = &s_worldData.shaders[shaderNum]; - shader_t* shader = R_FindShader( dsh->shader, RSF_3D ); + shader_t* shader = R_FindShader( dsh->shader, RSF_3D | RSF_BSP ); // If the shader had errors, just use default shader if ( shader->defaultShader ) { diff --git a/src/engine/renderer/tr_local.h b/src/engine/renderer/tr_local.h index ea4553b9b2..e1ad634ddc 100644 --- a/src/engine/renderer/tr_local.h +++ b/src/engine/renderer/tr_local.h @@ -964,6 +964,8 @@ enum // TODO(0.56): move to the public RegisterShaderFlags_t interface #define RSF_3D ( BIT( 30 ) ) +#define RSF_BSP ( BIT ( 29 ) ) + using stageRenderer_t = void(*)(shaderStage_t *); using stageShaderBuildMarker_t = void(*)(const shaderStage_t*); using surfaceDataUpdater_t = void(*)(uint32_t*, shaderStage_t*, bool, bool, bool); @@ -1033,6 +1035,8 @@ enum bool highQuality; bool forceHighQuality; + bool forceVertexLighting; + bool hasDepthFade; // for soft particles float depthFadeValue; diff --git a/src/engine/renderer/tr_shader.cpp b/src/engine/renderer/tr_shader.cpp index a110943f8d..ba69ed6df9 100644 --- a/src/engine/renderer/tr_shader.cpp +++ b/src/engine/renderer/tr_shader.cpp @@ -5202,6 +5202,14 @@ static void FinishStages() lightStageFound = true; break; + case stageType_t::ST_COLORMAP: + if ( stage->rgbGen == colorGen_t::CGEN_VERTEX && shader.registerFlags & RSF_BSP ) + { + // vertex colors used as lighting detected. Enable overbright and realtime lights + stage->type = stageType_t::ST_DIFFUSEMAP; + stage->forceVertexLighting = true; // use vertex lighting even if there is a lightmap + } + default: break; } @@ -6453,6 +6461,7 @@ class ListShadersCmd : public Cmd::StaticCmd shader->registerFlags & RSF_FORCE_LIGHTMAP ? 'L' : '_', shader->registerFlags & RSF_SPRITE ? 'S' : '_', shader->registerFlags & RSF_3D ? '3' : '_', + shader->registerFlags & RSF_BSP ? 'B' : '_', }; if ( !shaderSortName.count( (shaderSort_t) shader->sort ) ) From 349ddb2656e7de2308b1272131dd308bda682d5c Mon Sep 17 00:00:00 2001 From: slipher Date: Fri, 17 Oct 2025 12:36:51 -0500 Subject: [PATCH 5/5] NUKE vertex overbright code for `generic` shader This is unused following the previous commit which make shaders that need overbright with `rgbGen vertex` run on the `lightMapping` shader instead of `generic`. Note: IS_LIGHT_STYLE was misnamed. It actually meant vertex overbright --- src/engine/renderer/Material.cpp | 48 +++++++++------------ src/engine/renderer/Material.h | 22 +++++----- src/engine/renderer/gl_shader.h | 30 +++---------- src/engine/renderer/glsl_source/common.glsl | 29 ++----------- src/engine/renderer/tr_local.h | 9 ++-- src/engine/renderer/tr_shade.cpp | 5 +-- 6 files changed, 45 insertions(+), 98 deletions(-) diff --git a/src/engine/renderer/Material.cpp b/src/engine/renderer/Material.cpp index 59f02e9731..8cd370a6fd 100644 --- a/src/engine/renderer/Material.cpp +++ b/src/engine/renderer/Material.cpp @@ -134,14 +134,14 @@ All of these functions must write stage material data regardless of whether pSta because stages here are combined into as few as possible, and the stage chosen for storage might not have all of those enabled */ -void UpdateSurfaceDataNONE( uint32_t*, shaderStage_t*, bool, bool, bool ) { +void UpdateSurfaceDataNONE( uint32_t*, shaderStage_t*, bool, bool ) { ASSERT_UNREACHABLE(); } -void UpdateSurfaceDataNOP( uint32_t*, shaderStage_t*, bool, bool, bool ) { +void UpdateSurfaceDataNOP( uint32_t*, shaderStage_t*, bool, bool ) { } -void UpdateSurfaceDataGeneric3D( uint32_t* materials, shaderStage_t* pStage, bool mayUseVertexOverbright, bool, bool ) { +void UpdateSurfaceDataGeneric3D( uint32_t* materials, shaderStage_t* pStage, bool, bool ) { // shader_t* shader = pStage->shader; materials += pStage->bufferOffset; @@ -154,7 +154,7 @@ void UpdateSurfaceDataGeneric3D( uint32_t* materials, shaderStage_t* pStage, boo alphaGen_t alphaGen = SetAlphaGen( pStage ); const bool styleLightMap = pStage->type == stageType_t::ST_STYLELIGHTMAP || pStage->type == stageType_t::ST_STYLECOLORMAP; - gl_genericShaderMaterial->SetUniform_ColorModulateColorGen_Uint( rgbGen, alphaGen, mayUseVertexOverbright, styleLightMap ); + gl_genericShaderMaterial->SetUniform_ColorModulateColorGen_Uint( rgbGen, alphaGen, styleLightMap ); Tess_ComputeColor( pStage ); gl_genericShaderMaterial->SetUniform_Color_Uint( tess.svars.color ); @@ -164,7 +164,7 @@ void UpdateSurfaceDataGeneric3D( uint32_t* materials, shaderStage_t* pStage, boo gl_genericShaderMaterial->WriteUniformsToBuffer( materials ); } -void UpdateSurfaceDataLightMapping( uint32_t* materials, shaderStage_t* pStage, bool, bool vertexLit, bool fullbright ) { +void UpdateSurfaceDataLightMapping( uint32_t* materials, shaderStage_t* pStage, bool vertexLit, bool fullbright ) { shader_t* shader = pStage->shader; materials += pStage->bufferOffset; @@ -181,7 +181,7 @@ void UpdateSurfaceDataLightMapping( uint32_t* materials, shaderStage_t* pStage, } // u_ColorModulate - gl_lightMappingShaderMaterial->SetUniform_ColorModulateColorGen_Uint( rgbGen, alphaGen, false, !fullbright ); + gl_lightMappingShaderMaterial->SetUniform_ColorModulateColorGen_Uint( rgbGen, alphaGen, !fullbright ); // u_Color gl_lightMappingShaderMaterial->SetUniform_Color_Uint( tess.svars.color ); @@ -210,7 +210,7 @@ void UpdateSurfaceDataLightMapping( uint32_t* materials, shaderStage_t* pStage, gl_lightMappingShaderMaterial->WriteUniformsToBuffer( materials ); } -void UpdateSurfaceDataReflection( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ) { +void UpdateSurfaceDataReflection( uint32_t* materials, shaderStage_t* pStage, bool, bool ) { shader_t* shader = pStage->shader; materials += pStage->bufferOffset; @@ -247,7 +247,7 @@ void UpdateSurfaceDataReflection( uint32_t* materials, shaderStage_t* pStage, bo gl_reflectionShaderMaterial->WriteUniformsToBuffer( materials ); } -void UpdateSurfaceDataSkybox( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ) { +void UpdateSurfaceDataSkybox( uint32_t* materials, shaderStage_t* pStage, bool, bool ) { // shader_t* shader = pStage->shader; materials += pStage->bufferOffset; @@ -258,7 +258,7 @@ void UpdateSurfaceDataSkybox( uint32_t* materials, shaderStage_t* pStage, bool, gl_skyboxShaderMaterial->WriteUniformsToBuffer( materials ); } -void UpdateSurfaceDataScreen( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ) { +void UpdateSurfaceDataScreen( uint32_t* materials, shaderStage_t* pStage, bool, bool ) { // shader_t* shader = pStage->shader; materials += pStage->bufferOffset; @@ -271,7 +271,7 @@ void UpdateSurfaceDataScreen( uint32_t* materials, shaderStage_t* pStage, bool, gl_screenShaderMaterial->WriteUniformsToBuffer( materials ); } -void UpdateSurfaceDataHeatHaze( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ) { +void UpdateSurfaceDataHeatHaze( uint32_t* materials, shaderStage_t* pStage, bool, bool ) { // shader_t* shader = pStage->shader; materials += pStage->bufferOffset; @@ -288,7 +288,7 @@ void UpdateSurfaceDataHeatHaze( uint32_t* materials, shaderStage_t* pStage, bool gl_heatHazeShaderMaterial->WriteUniformsToBuffer( materials ); } -void UpdateSurfaceDataLiquid( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ) { +void UpdateSurfaceDataLiquid( uint32_t* materials, shaderStage_t* pStage, bool, bool ) { // shader_t* shader = pStage->shader; materials += pStage->bufferOffset; @@ -334,7 +334,7 @@ void UpdateSurfaceDataLiquid( uint32_t* materials, shaderStage_t* pStage, bool, gl_liquidShaderMaterial->WriteUniformsToBuffer( materials ); } -void UpdateSurfaceDataFog( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ) { +void UpdateSurfaceDataFog( uint32_t* materials, shaderStage_t* pStage, bool, bool ) { // shader_t* shader = pStage->shader; materials += pStage->bufferOffset; @@ -436,14 +436,13 @@ void MaterialSystem::GenerateMaterialsBuffer( std::vector& stage uint32_t variants = 0; for ( int i = 0; i < ShaderStageVariant::ALL && variants < pStage->variantOffset; i++ ) { if ( pStage->variantOffsets[i] != -1 ) { - const bool mayUseVertexOverbright = i & ShaderStageVariant::VERTEX_OVERBRIGHT; const bool vertexLit = i & ShaderStageVariant::VERTEX_LIT; const bool fullbright = i & ShaderStageVariant::FULLBRIGHT; const uint32_t variantOffset = pStage->variantOffsets[i] * pStage->paddedSize; pStage->bufferOffset += variantOffset; - pStage->surfaceDataUpdater( materialsData, pStage, mayUseVertexOverbright, vertexLit, fullbright ); + pStage->surfaceDataUpdater( materialsData, pStage, vertexLit, fullbright ); pStage->bufferOffset -= variantOffset; variants++; @@ -774,14 +773,10 @@ static std::string GetStageInfo( const shaderStage_t* pStage, const uint32_t dyn stageShaderNames.at( pStage->shaderBinder ), pStage->materialOffset, pStage->bufferOffset ); static const char* stageVariants[] = { - "base variant ", - "vertex overbright ", - "vertex-lit ", - "vertex overbright vertex-lit ", - "fullbright ", - "vertex overbright fullbright ", - "vertex-lit fullbright ", - "vertex overbright vertex-lit fullbright" + "base variant ", + "vertex-lit ", + "fullbright ", + "vertex-lit fullbright", }; static_assert( ARRAY_LEN( stageVariants ) == ShaderStageVariant::ALL, "update stage variant text descriptions" ); @@ -1272,9 +1267,8 @@ void ProcessMaterialFog( Material* material, shaderStage_t* pStage, MaterialSurf } void MaterialSystem::AddStage( MaterialSurface* surface, shaderStage_t* pStage, uint32_t stage, - const bool mayUseVertexOverbright, const bool vertexLit, const bool fullbright ) { - const int variant = ( mayUseVertexOverbright ? ShaderStageVariant::VERTEX_OVERBRIGHT : 0 ) - | ( vertexLit ? ShaderStageVariant::VERTEX_LIT : 0 ) + const bool vertexLit, const bool fullbright ) { + const int variant = ( vertexLit ? ShaderStageVariant::VERTEX_LIT : 0 ) | ( fullbright ? ShaderStageVariant::FULLBRIGHT : 0 ); if ( pStage->variantOffsets[variant] == -1 ) { @@ -1392,8 +1386,6 @@ void MaterialSystem::ProcessStage( MaterialSurface* surface, shaderStage_t* pSta lightMode_t lightMode; deluxeMode_t deluxeMode; SetLightDeluxeMode( surface, pStage, lightMode, deluxeMode ); - const bool mayUseVertexOverbright = pStage->type == stageType_t::ST_COLORMAP - && surface->bspSurface && pStage->shaderBinder == BindShaderGeneric3D; const bool vertexLit = lightMode == lightMode_t::VERTEX && pStage->shaderBinder == BindShaderLightMapping; const bool fullbright = lightMode == lightMode_t::FULLBRIGHT && pStage->shaderBinder == BindShaderLightMapping; @@ -1479,7 +1471,7 @@ void MaterialSystem::ProcessStage( MaterialSurface* surface, shaderStage_t* pSta pStage->useMaterialSystem = true; pStage->initialized = true; - AddStage( surface, pStage, stage, mayUseVertexOverbright, vertexLit, fullbright ); + AddStage( surface, pStage, stage, vertexLit, fullbright ); AddStageTextures( surface, pStage, stage, &materials[previousMaterialID] ); surface->materialIDs[stage] = previousMaterialID; diff --git a/src/engine/renderer/Material.h b/src/engine/renderer/Material.h index 219cacc1c0..3997c4d6d7 100644 --- a/src/engine/renderer/Material.h +++ b/src/engine/renderer/Material.h @@ -376,7 +376,7 @@ class MaterialSystem { void AddStageTextures( MaterialSurface* surface, shaderStage_t* pStage, const uint32_t stage, Material* material ); void AddStage( MaterialSurface* surface, shaderStage_t* pStage, uint32_t stage, - const bool mayUseVertexOverbright, const bool vertexLit, const bool fullbright ); + const bool vertexLit, const bool fullbright ); void ProcessStage( MaterialSurface* surface, shaderStage_t* pStage, shader_t* shader, uint32_t* packIDs, uint32_t& stage, uint32_t& previousMaterialID, bool skipStageSync = false ); void GenerateMaterial( MaterialSurface* surface, int globalFog ); @@ -451,16 +451,16 @@ extern GLSSBO debugSSBO; // Global extern MaterialSystem materialSystem; -void UpdateSurfaceDataNONE( uint32_t*, shaderStage_t*, bool, bool, bool ); -void UpdateSurfaceDataNOP( uint32_t*, shaderStage_t*, bool, bool, bool ); -void UpdateSurfaceDataGeneric3D( uint32_t* materials, shaderStage_t* pStage, bool mayUseVertexOverbright, bool, bool ); -void UpdateSurfaceDataLightMapping( uint32_t* materials, shaderStage_t* pStage, bool, bool vertexLit, bool fullbright ); -void UpdateSurfaceDataReflection( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ); -void UpdateSurfaceDataSkybox( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ); -void UpdateSurfaceDataScreen( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ); -void UpdateSurfaceDataHeatHaze( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ); -void UpdateSurfaceDataLiquid( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ); -void UpdateSurfaceDataFog( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ); +void UpdateSurfaceDataNONE( uint32_t*, shaderStage_t*, bool, bool ); +void UpdateSurfaceDataNOP( uint32_t*, shaderStage_t*, bool, bool ); +void UpdateSurfaceDataGeneric3D( uint32_t* materials, shaderStage_t* pStage, bool, bool ); +void UpdateSurfaceDataLightMapping( uint32_t* materials, shaderStage_t* pStage, bool vertexLit, bool fullbright ); +void UpdateSurfaceDataReflection( uint32_t* materials, shaderStage_t* pStage, bool, bool ); +void UpdateSurfaceDataSkybox( uint32_t* materials, shaderStage_t* pStage, bool, bool ); +void UpdateSurfaceDataScreen( uint32_t* materials, shaderStage_t* pStage, bool, bool ); +void UpdateSurfaceDataHeatHaze( uint32_t* materials, shaderStage_t* pStage, bool, bool ); +void UpdateSurfaceDataLiquid( uint32_t* materials, shaderStage_t* pStage, bool, bool ); +void UpdateSurfaceDataFog( uint32_t* materials, shaderStage_t* pStage, bool, bool ); void BindShaderNONE( Material* ); void BindShaderNOP( Material* ); diff --git a/src/engine/renderer/gl_shader.h b/src/engine/renderer/gl_shader.h index 2fe9ae8878..dcf2678820 100644 --- a/src/engine/renderer/gl_shader.h +++ b/src/engine/renderer/gl_shader.h @@ -2737,13 +2737,11 @@ struct colorModulation_t { float colorGen = 0.0f; float alphaGen = 0.0f; float lightFactor = 1.0f; - bool useVertexLightFactor = false; }; static colorModulation_t ColorModulateColorGen( const colorGen_t colorGen, const alphaGen_t alphaGen, - const bool vertexOverbright, const bool useMapLightFactor ) { colorModulation_t colorModulation = {}; @@ -2751,17 +2749,7 @@ static colorModulation_t ColorModulateColorGen( switch ( colorGen ) { case colorGen_t::CGEN_VERTEX: - if ( vertexOverbright ) - { - // vertexOverbright is only needed for non-lightmapped cases. When there is a - // lightmap, this is done by multiplying with the overbright-scaled white image - colorModulation.useVertexLightFactor = true; - colorModulation.lightFactor = tr.mapLightFactor; - } - else - { - colorModulation.colorGen = 1.0f; - } + colorModulation.colorGen = 1.0f; break; case colorGen_t::CGEN_ONE_MINUS_VERTEX: @@ -2774,7 +2762,6 @@ static colorModulation_t ColorModulateColorGen( if ( useMapLightFactor ) { - DAEMON_ASSERT_EQ( vertexOverbright, false ); colorModulation.lightFactor = tr.mapLightFactor; } @@ -2807,7 +2794,6 @@ class u_ColorModulateColorGen_Float : void SetUniform_ColorModulateColorGen_Float( const colorGen_t colorGen, const alphaGen_t alphaGen, - const bool vertexOverbright = false, const bool useMapLightFactor = false ) { GLIMP_LOGCOMMENT( "--- u_ColorModulate::SetUniform_ColorModulateColorGen_Float( " @@ -2815,12 +2801,11 @@ class u_ColorModulateColorGen_Float : _shader->_name.c_str(), Util::enum_str( colorGen ), Util::enum_str( alphaGen ) ); colorModulation_t colorModulation = ColorModulateColorGen( - colorGen, alphaGen, vertexOverbright, useMapLightFactor ); + colorGen, alphaGen, useMapLightFactor ); vec4_t colorModulate_Float; colorModulate_Float[ 0 ] = colorModulation.colorGen; colorModulate_Float[ 1 ] = colorModulation.lightFactor; - colorModulate_Float[ 1 ] *= colorModulation.useVertexLightFactor ? -1.0f : 1.0f; colorModulate_Float[ 2 ] = {}; colorModulate_Float[ 3 ] = colorModulation.alphaGen; @@ -2838,7 +2823,6 @@ class u_ColorModulateColorGen_Uint : void SetUniform_ColorModulateColorGen_Uint( const colorGen_t colorGen, const alphaGen_t alphaGen, - const bool vertexOverbright = false, const bool useMapLightFactor = false ) { GLIMP_LOGCOMMENT( "--- u_ColorModulate::SetUniform_ColorModulateColorGen_Uint( " @@ -2846,7 +2830,7 @@ class u_ColorModulateColorGen_Uint : _shader->_name.c_str(), Util::enum_str( colorGen ), Util::enum_str( alphaGen ) ); colorModulation_t colorModulation = ColorModulateColorGen( - colorGen, alphaGen, vertexOverbright, useMapLightFactor ); + colorGen, alphaGen, useMapLightFactor ); enum class ColorModulate_Bit { COLOR_ONE = 0, @@ -2854,7 +2838,6 @@ class u_ColorModulateColorGen_Uint : ALPHA_ONE = 2, ALPHA_MINUS_ONE = 3, // <-- Insert new bits there. - IS_LIGHT_STYLE = 27, LIGHTFACTOR_BIT0 = 28, LIGHTFACTOR_BIT1 = 29, LIGHTFACTOR_BIT2 = 30, @@ -2872,8 +2855,6 @@ class u_ColorModulateColorGen_Uint : << Util::ordinal( ColorModulate_Bit::ALPHA_ONE ); colorModulate_Uint |= ( colorModulation.alphaGen == -1.0f ) << Util::ordinal( ColorModulate_Bit::ALPHA_MINUS_ONE ); - colorModulate_Uint |= colorModulation.useVertexLightFactor - << Util::ordinal( ColorModulate_Bit::IS_LIGHT_STYLE ); colorModulate_Uint |= uint32_t( colorModulation.lightFactor ) << Util::ordinal( ColorModulate_Bit::LIGHTFACTOR_BIT0 ); @@ -2885,16 +2866,15 @@ template void SetUniform_ColorModulateColorGen( Shader* shader, const colorGen_t colorGen, const alphaGen_t alphaGen, - const bool vertexOverbright = false, const bool useMapLightFactor = false ) { if( glConfig.gpuShader4Available ) { - shader->SetUniform_ColorModulateColorGen_Uint( colorGen, alphaGen, vertexOverbright, useMapLightFactor ); + shader->SetUniform_ColorModulateColorGen_Uint( colorGen, alphaGen, useMapLightFactor ); } else { - shader->SetUniform_ColorModulateColorGen_Float( colorGen, alphaGen, vertexOverbright, useMapLightFactor ); + shader->SetUniform_ColorModulateColorGen_Float( colorGen, alphaGen, useMapLightFactor ); } } diff --git a/src/engine/renderer/glsl_source/common.glsl b/src/engine/renderer/glsl_source/common.glsl index e90fd5474b..141f632261 100644 --- a/src/engine/renderer/glsl_source/common.glsl +++ b/src/engine/renderer/glsl_source/common.glsl @@ -68,15 +68,13 @@ colorMod << 0: color * 1 colorMod << 1: color * ( -1 ) colorMod << 2: alpha * 1 colorMod << 3: alpha * ( -1 ) -colorMod << 4-26: available for future usage -colorMod << 27: color += lightFactor +colorMod << 4-27: available for future usage colorMod << 28-31: lightFactor colorMod float format: colorMod[ 0 ]: color * f -colorMod[ 1 ] absolute value: lightFactor -colorMod[ 1 ] minus sign: color += lightFactor +colorMod[ 1 ]: lightFactor colorMod[ 3 ]: alpha * f */ vec4 ColorModulateToColor( const in colorModulatePack colorMod ) @@ -97,30 +95,12 @@ vec4 ColorModulateToColor( const in colorModulatePack colorMod ) return vec4( rgb, rgb, rgb, alpha ); } -struct ModBits_t -{ - bool useVertexLightFactor; -}; - -ModBits_t ColorModulateToBits( const in colorModulatePack colorMod ) -{ - ModBits_t modBits; - -#if defined(HAVE_EXT_gpu_shader4) - modBits.useVertexLightFactor = bool( ( colorMod >> 27u ) & 1u ); -#else - modBits.useVertexLightFactor = colorMod.g < 0; -#endif - - return modBits; -} - float ColorModulateToLightFactor( const in colorModulatePack colorMod ) { #if defined(HAVE_EXT_gpu_shader4) return float( colorMod >> 28u ); #else - return abs( colorMod.g ); + return colorMod.g; #endif } @@ -151,11 +131,8 @@ void ColorModulateColor_lightFactor( inout vec4 color ) { vec4 colorModulation = ColorModulateToColor( colorMod ); - ModBits_t modBits = ColorModulateToBits( colorMod ); float lightFactor = ColorModulateToLightFactor( colorMod ); - colorModulation.rgb += vec3( modBits.useVertexLightFactor ? lightFactor : 0 ); - vec4 unpackedColor = UnpackColor( packedColor ); unpackedColor.rgb *= lightFactor; diff --git a/src/engine/renderer/tr_local.h b/src/engine/renderer/tr_local.h index e1ad634ddc..a0d618d383 100644 --- a/src/engine/renderer/tr_local.h +++ b/src/engine/renderer/tr_local.h @@ -968,15 +968,14 @@ enum using stageRenderer_t = void(*)(shaderStage_t *); using stageShaderBuildMarker_t = void(*)(const shaderStage_t*); - using surfaceDataUpdater_t = void(*)(uint32_t*, shaderStage_t*, bool, bool, bool); + using surfaceDataUpdater_t = void(*)(uint32_t*, shaderStage_t*, bool, bool); using stageShaderBinder_t = void(*)(Material*); using stageMaterialProcessor_t = void(*)(Material*, shaderStage_t*, MaterialSurface*); enum ShaderStageVariant { - VERTEX_OVERBRIGHT = 1, - VERTEX_LIT = BIT( 1 ), - FULLBRIGHT = BIT( 2 ), - ALL = BIT( 3 ) + VERTEX_LIT = BIT( 0 ), + FULLBRIGHT = BIT( 1 ), + ALL = BIT( 2 ) }; struct shaderStage_t diff --git a/src/engine/renderer/tr_shade.cpp b/src/engine/renderer/tr_shade.cpp index bc261a58a3..b26fa27aa1 100644 --- a/src/engine/renderer/tr_shade.cpp +++ b/src/engine/renderer/tr_shade.cpp @@ -904,9 +904,8 @@ void Render_generic3D( shaderStage_t *pStage ) colorGen_t rgbGen = SetRgbGen( pStage ); alphaGen_t alphaGen = SetAlphaGen( pStage ); - bool mayUseVertexOverbright = pStage->type == stageType_t::ST_COLORMAP && tess.bspSurface; const bool styleLightMap = pStage->type == stageType_t::ST_STYLELIGHTMAP || pStage->type == stageType_t::ST_STYLECOLORMAP; - SetUniform_ColorModulateColorGen( gl_genericShader, rgbGen, alphaGen, mayUseVertexOverbright, styleLightMap ); + SetUniform_ColorModulateColorGen( gl_genericShader, rgbGen, alphaGen, styleLightMap ); // u_Color SetUniform_Color( gl_genericShader, tess.svars.color ); @@ -1083,7 +1082,7 @@ void Render_lightMapping( shaderStage_t *pStage ) gl_lightMappingShader->SetUniform_Time( backEnd.refdef.floatTime - backEnd.currentEntity->e.shaderTime ); // u_ColorModulate - SetUniform_ColorModulateColorGen( gl_lightMappingShader, rgbGen, alphaGen, false, lightMode != lightMode_t::FULLBRIGHT ); + SetUniform_ColorModulateColorGen( gl_lightMappingShader, rgbGen, alphaGen, lightMode != lightMode_t::FULLBRIGHT ); // u_Color SetUniform_Color( gl_lightMappingShader, tess.svars.color );