diff --git a/src/engine/renderer/Material.cpp b/src/engine/renderer/Material.cpp index 6559446550..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++; @@ -680,7 +679,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++; @@ -773,15 +773,13 @@ 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 ", - "fullbright ", - "vertex overbright vertex-lit ", - "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" ); uint32_t variants = 0; for ( int i = 0; i < ShaderStageVariant::ALL && variants < pStage->variantOffset; i++ ) { @@ -1157,7 +1155,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 ); @@ -1240,7 +1238,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; @@ -1269,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 ) { @@ -1388,9 +1385,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 ); - const bool mayUseVertexOverbright = pStage->type == stageType_t::ST_COLORMAP - && surface->bspSurface && pStage->shaderBinder == BindShaderGeneric3D; + SetLightDeluxeMode( surface, pStage, lightMode, deluxeMode ); const bool vertexLit = lightMode == lightMode_t::VERTEX && pStage->shaderBinder == BindShaderLightMapping; const bool fullbright = lightMode == lightMode_t::FULLBRIGHT && pStage->shaderBinder == BindShaderLightMapping; @@ -1476,8 +1471,8 @@ void MaterialSystem::ProcessStage( MaterialSurface* surface, shaderStage_t* pSta pStage->useMaterialSystem = true; pStage->initialized = true; - AddStage( surface, pStage, stage, mayUseVertexOverbright, vertexLit, fullbright ); - AddStageTextures( surface, shader, pStage, stage, &materials[previousMaterialID] ); + AddStage( surface, pStage, stage, vertexLit, fullbright ); + AddStageTextures( surface, pStage, stage, &materials[previousMaterialID] ); surface->materialIDs[stage] = previousMaterialID; surface->materialPackIDs[stage] = materialPack; @@ -1537,7 +1532,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; @@ -1568,7 +1563,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..3997c4d6d7 100644 --- a/src/engine/renderer/Material.h +++ b/src/engine/renderer/Material.h @@ -374,9 +374,9 @@ 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 ); + 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/ShadeCommon.h b/src/engine/renderer/ShadeCommon.h index 7d8f107439..da4cac0fcd 100644 --- a/src/engine/renderer/ShadeCommon.h +++ b/src/engine/renderer/ShadeCommon.h @@ -114,18 +114,23 @@ 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 ( stage->forceVertexLighting ) + { + lightMode = lightMode_t::VERTEX; + deluxeMode = deluxeMode_t::NONE; + } + else 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 +142,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/gl_shader.h b/src/engine/renderer/gl_shader.h index ec6faee19a..dcf2678820 100644 --- a/src/engine/renderer/gl_shader.h +++ b/src/engine/renderer/gl_shader.h @@ -2737,14 +2737,11 @@ struct colorModulation_t { float colorGen = 0.0f; float alphaGen = 0.0f; float lightFactor = 1.0f; - bool useVertexLightFactor = false; - bool alphaAddOne = true; }; static colorModulation_t ColorModulateColorGen( const colorGen_t colorGen, const alphaGen_t alphaGen, - const bool vertexOverbright, const bool useMapLightFactor ) { colorModulation_t colorModulation = {}; @@ -2752,23 +2749,10 @@ 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 - // 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: - colorModulation.alphaAddOne = false; colorModulation.colorGen = -1.0f; break; @@ -2778,19 +2762,16 @@ static colorModulation_t ColorModulateColorGen( if ( useMapLightFactor ) { - DAEMON_ASSERT_EQ( vertexOverbright, false ); colorModulation.lightFactor = tr.mapLightFactor; } 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; @@ -2813,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( " @@ -2821,13 +2801,12 @@ 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 ] = colorModulation.alphaAddOne; + colorModulate_Float[ 2 ] = {}; colorModulate_Float[ 3 ] = colorModulation.alphaGen; this->SetValue( colorModulate_Float ); @@ -2844,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( " @@ -2852,16 +2830,14 @@ 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, 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, LIGHTFACTOR_BIT1 = 29, LIGHTFACTOR_BIT2 = 30, @@ -2879,10 +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.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 ) << Util::ordinal( ColorModulate_Bit::LIGHTFACTOR_BIT0 ); @@ -2894,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 1c7013a74d..141f632261 100644 --- a/src/engine/renderer/glsl_source/common.glsl +++ b/src/engine/renderer/glsl_source/common.glsl @@ -68,17 +68,13 @@ 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 << 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[ 2 ]: alpha = 1 +colorMod[ 1 ]: lightFactor colorMod[ 3 ]: alpha * f */ vec4 ColorModulateToColor( const in colorModulatePack colorMod ) @@ -99,33 +95,12 @@ vec4 ColorModulateToColor( const in colorModulatePack colorMod ) return vec4( rgb, rgb, rgb, alpha ); } -struct ModBits_t -{ - bool alphaAddOne; - bool useVertexLightFactor; -}; - -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 - - 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 } @@ -156,14 +131,8 @@ void ColorModulateColor_lightFactor( inout vec4 color ) { vec4 colorModulation = ColorModulateToColor( colorMod ); - 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 ); unpackedColor.rgb *= lightFactor; 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..a0d618d383 100644 --- a/src/engine/renderer/tr_local.h +++ b/src/engine/renderer/tr_local.h @@ -964,17 +964,18 @@ 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); + 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 @@ -1033,6 +1034,8 @@ enum bool highQuality; bool forceHighQuality; + bool forceVertexLighting; + bool hasDepthFade; // for soft particles float depthFadeValue; diff --git a/src/engine/renderer/tr_shade.cpp b/src/engine/renderer/tr_shade.cpp index 19c481d928..b26fa27aa1 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 ); @@ -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 ); @@ -1000,7 +999,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 ); @@ -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 ); @@ -1507,7 +1506,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 ); 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 ) )