From 1d83d7107bd1e843eaa4f738d84a1d94d12f31d0 Mon Sep 17 00:00:00 2001 From: kitsune Date: Sat, 13 Dec 2025 15:07:17 +0100 Subject: [PATCH 1/4] Update .gitignore to exclude additional generated and local files. --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 14303b2d4..c1dacdb72 100644 --- a/.gitignore +++ b/.gitignore @@ -47,6 +47,9 @@ src/game/missionchooser/Release/ src/game/server/Debug_swarm/ src/game/server/Release_swarm/ src/ipch +src/materialsystem/shaderlib/Debug/ +src/materialsystem/shaderlib/Release/ +src/materialsystem/stdshaders/.vs/ src/materialsystem/stdshaders/Debug_dx9/ src/materialsystem/stdshaders/Release_dx9/ src/materialsystem/stdshaders/shaders/ From a8702ef3fe9d7b1d7cf0008ae1ded0a82e53b3f0 Mon Sep 17 00:00:00 2001 From: kitsune Date: Sat, 13 Dec 2025 16:03:28 +0100 Subject: [PATCH 2/4] Refactor process_shaders.ps1: add defaults and streamline argument construction. --- src/devtools/bin/process_shaders.ps1 | 35 +++++++++++----------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/devtools/bin/process_shaders.ps1 b/src/devtools/bin/process_shaders.ps1 index fb136c878..5f9531194 100644 --- a/src/devtools/bin/process_shaders.ps1 +++ b/src/devtools/bin/process_shaders.ps1 @@ -3,31 +3,22 @@ param ( [Parameter(Mandatory=$true, ValueFromPipeline=$true)][System.IO.FileInfo]$File, [Parameter(Mandatory=$true)][string]$Version, [Parameter(Mandatory=$false)][switch]$Dynamic, - [Parameter(Mandatory=$false)][System.UInt32]$Threads + [Parameter(Mandatory=$false)][System.UInt32]$Threads = 0, + [Parameter(Mandatory=$false)][System.UInt32]$Optimize = 3 ) -$Optimize = 3 +if ($Version -notin @("20b","30","40","41","50","51")) { return } -if ($Version -notin @("20b", "30", "40", "41", "50", "51")) { - return -} - -$fileList = $File.OpenText() -while ($null -ne ($line = $fileList.ReadLine())) { - if ($line -match '^\s*$' -or $line -match '^\s*//') { - continue - } - - if ($Dynamic) { - & "$PSScriptRoot\ShaderCompile" "-dynamic" "-ver" $Version "-shaderpath" $File.DirectoryName $line - continue - } +foreach ($line in Get-Content $File) { + if ($line -match '^\s*$' -or $line -match '^\s*//') { continue } - if ($Threads -ne 0) { - & "$PSScriptRoot\ShaderCompile" "-threads" $Threads "-ver" $Version "-shaderpath" $File.DirectoryName "-optimize" $Optimize $line - continue - } + $args = @() + if ($Dynamic) { $args += "-dynamic" } + if ($Threads -ne 0) { $args += "-threads"; $args += $Threads } + $args += "-ver"; $args += $Version + $args += "-shaderpath"; $args += $File.DirectoryName + if (-not $Dynamic) { $args += "-optimize"; $args += $Optimize } + $args += $line - & "$PSScriptRoot\ShaderCompile" "-ver" $Version "-shaderpath" $File.DirectoryName "-optimize" $Optimize $line + & "$PSScriptRoot\ShaderCompile" $args } -$fileList.Close() From 7b7e0603f53fc23fa3b1a6c572420b765fc6cec4 Mon Sep 17 00:00:00 2001 From: kitsune Date: Sat, 13 Dec 2025 19:31:42 +0100 Subject: [PATCH 3/4] Refactor RDCharacter shader parameter declarations. Reorganize and group SHADER_PARAM declarations in character_dx9.cpp into coherent sections (misc, base, bump, envmap, phong, detail, proxy). This is a structural refactor for readability and maintainability only. --- .../stdshaders/character_dx9.cpp | 118 +++++++++--------- 1 file changed, 60 insertions(+), 58 deletions(-) diff --git a/src/materialsystem/stdshaders/character_dx9.cpp b/src/materialsystem/stdshaders/character_dx9.cpp index bcb7b7865..30d989dd0 100644 --- a/src/materialsystem/stdshaders/character_dx9.cpp +++ b/src/materialsystem/stdshaders/character_dx9.cpp @@ -25,55 +25,70 @@ static bool s_bSeenCharacterProxy = false; BEGIN_VS_SHADER( RDCharacter, "Alien Swarm: Reactive Drop character shader" ) BEGIN_SHADER_PARAMS + // misc + SHADER_PARAM( FLASHLIGHTNOLAMBERT, SHADER_PARAM_TYPE_BOOL, "0", "Flashlight pass sets N.L=1.0" ) + SHADER_PARAM( AMBIENTOCCLUSION, SHADER_PARAM_TYPE_FLOAT, "0.0", "Amount of screen space ambient occlusion to use (0..1 range)" ) + SHADER_PARAM( LINEARWRITE, SHADER_PARAM_TYPE_INTEGER, "0", "Disables SRGB conversion of shader results." ) + SHADER_PARAM( SHADERSRGBREAD360, SHADER_PARAM_TYPE_BOOL, "0", "Simulate srgb read in shader code" ) + + // base SHADER_PARAM( ALBEDO, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "albedo (Base texture with no baked lighting)" ) + SHADER_PARAM( DISPLACEMENTMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Displacement map" ) SHADER_PARAM( COMPRESS, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "compression wrinklemap" ) SHADER_PARAM( STRETCH, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "expansion wrinklemap" ) - SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" ) - SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" ) - SHADER_PARAM( DETAILFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $detail" ) - SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" ) + + SHADER_PARAM( HSV, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "HSV color to transform $basetexture texture with" ) + + SHADER_PARAM( TINTMASKTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Separate tint mask texture (as opposed to using basetexture alpha)" ) + SHADER_PARAM( DESATURATEWITHBASEALPHA, SHADER_PARAM_TYPE_FLOAT, "0.0", "Use the base alpha to desaturate the base texture. Set to non-zero to enable, value gets multiplied into the alpha channel before desaturating." ) + + SHADER_PARAM( ALLOWDIFFUSEMODULATION, SHADER_PARAM_TYPE_BOOL, "1", "Allow per-instance color modulation" ) + SHADER_PARAM( BLENDTINTBYBASEALPHA, SHADER_PARAM_TYPE_BOOL, "0", "Use the base alpha to blend in the $color modulation" ) + + SHADER_PARAM( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + + // bumpmap + SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bump map" ) + SHADER_PARAM( BUMPCOMPRESS, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader3_normal", "compression bump map" ) + SHADER_PARAM( BUMPSTRETCH, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "expansion bump map" ) + SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + + // envmap SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "envmap frame number" ) SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" ) SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) SHADER_PARAM( ENVMAPMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$envmapmask texcoord transform" ) + SHADER_PARAM( BASEALPHAENVMAPMASKMINMAXEXP, SHADER_PARAM_TYPE_VEC3, "[1.0 0.0 1.0]", "" ) SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) - SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bump map" ) - SHADER_PARAM( BUMPCOMPRESS, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader3_normal", "compression bump map" ) - SHADER_PARAM( BUMPSTRETCH, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "expansion bump map" ) - SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) - SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" ) SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" ) + SHADER_PARAM( ENVMAPFRESNEL, SHADER_PARAM_TYPE_FLOAT, "0", "Degree to which Fresnel should be applied to env map" ) + SHADER_PARAM( ENVMAPFRESNELMINMAXEXP, SHADER_PARAM_TYPE_VEC3, "[0.0 1.0 2.0]", "Min/max fresnel range and exponent for vertexlitgeneric" ) + + // selfillum + SHADER_PARAM( SELFILLUMMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "If we bind a texture here, it overrides base alpha (if any) for self illum" ) SHADER_PARAM( SELFILLUM_ENVMAPMASK_ALPHA, SHADER_PARAM_TYPE_FLOAT, "0.0", "defines that self illum value comes from env map mask alpha" ) + SHADER_PARAM( SELFILLUMMASKSCALE, SHADER_PARAM_TYPE_FLOAT, "0", "Scale self illum effect strength" ) + SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" ) SHADER_PARAM( SELFILLUMFRESNEL, SHADER_PARAM_TYPE_BOOL, "0", "Self illum fresnel" ) SHADER_PARAM( SELFILLUMFRESNELMINMAXEXP, SHADER_PARAM_TYPE_VEC4, "0", "Self illum fresnel min, max, exp" ) - SHADER_PARAM( SELFILLUMMASKSCALE, SHADER_PARAM_TYPE_FLOAT, "0", "Scale self illum effect strength" ) - SHADER_PARAM( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) - SHADER_PARAM( FLASHLIGHTNOLAMBERT, SHADER_PARAM_TYPE_BOOL, "0", "Flashlight pass sets N.L=1.0" ) - // Debugging term for visualizing ambient data on its own - SHADER_PARAM( AMBIENTONLY, SHADER_PARAM_TYPE_INTEGER, "0", "Control drawing of non-ambient light ()" ) - - SHADER_PARAM( PHONGEXPONENT, SHADER_PARAM_TYPE_FLOAT, "5.0", "Phong exponent for local specular lights" ) - SHADER_PARAM( PHONGTINT, SHADER_PARAM_TYPE_VEC3, "5.0", "Phong tint for local specular lights" ) - SHADER_PARAM( PHONGALBEDOTINT, SHADER_PARAM_TYPE_BOOL, "1.0", "Apply tint by albedo (controlled by spec exponent texture" ) - SHADER_PARAM( LIGHTWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "1D ramp texture for tinting scalar diffuse term" ) - SHADER_PARAM( PHONGWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "warp the specular term" ) - SHADER_PARAM( PHONGFRESNELRANGES, SHADER_PARAM_TYPE_VEC3, "[0 0.5 1]", "Parameters for remapping fresnel output" ) - SHADER_PARAM( PHONGBOOST, SHADER_PARAM_TYPE_FLOAT, "1.0", "Phong overbrightening factor (specular mask channel should be authored to account for this)" ) + // Phong shading + //SHADER_PARAM( PHONG, SHADER_PARAM_TYPE_BOOL, "0", "enables phong lighting" ) SHADER_PARAM( PHONGEXPONENTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Phong Exponent map" ) + SHADER_PARAM( PHONGWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "warp the specular term" ) + SHADER_PARAM( LIGHTWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "1D ramp texture for tinting scalar diffuse term" ) SHADER_PARAM( BASEMAPALPHAPHONGMASK, SHADER_PARAM_TYPE_INTEGER, "0", "indicates that there is no normal map and that the phong mask is in base alpha" ) - SHADER_PARAM( INVERTPHONGMASK, SHADER_PARAM_TYPE_INTEGER, "0", "invert the phong mask (0=full phong, 1=no phong)" ) - SHADER_PARAM( ENVMAPFRESNEL, SHADER_PARAM_TYPE_FLOAT, "0", "Degree to which Fresnel should be applied to env map" ) - SHADER_PARAM( SELFILLUMMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "If we bind a texture here, it overrides base alpha (if any) for self illum" ) SHADER_PARAM( BASEMAPLUMINANCEPHONGMASK, SHADER_PARAM_TYPE_INTEGER, "0", "indicates that the base luminance should be used to mask phong" ) - - // detail texturing - SHADER_PARAM( DETAILBLENDMODE, SHADER_PARAM_TYPE_INTEGER, "0", "mode for combining detail texture with base. 0=normal, 1= additive, 2=alpha blend detail over base, 3=crossfade" ) - SHADER_PARAM( DETAILBLENDFACTOR, SHADER_PARAM_TYPE_FLOAT, "1", "blend amount for detail texture." ) - SHADER_PARAM( DETAILTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "detail texture tint" ) - SHADER_PARAM( DETAILTEXTURETRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$detail texcoord transform" ) + SHADER_PARAM( INVERTPHONGMASK, SHADER_PARAM_TYPE_INTEGER, "0", "invert the phong mask (0=full phong, 1=no phong)" ) + SHADER_PARAM( PHONGEXPONENT, SHADER_PARAM_TYPE_FLOAT, "5.0", "Phong exponent for local specular lights" ) + SHADER_PARAM( PHONGBOOST, SHADER_PARAM_TYPE_FLOAT, "1.0", "Phong overbrightening factor (specular mask channel should be authored to account for this)" ) + SHADER_PARAM( PHONGFRESNELRANGES, SHADER_PARAM_TYPE_VEC3, "[0 0.5 1]", "Parameters for remapping fresnel output" ) + SHADER_PARAM( PHONGTINT, SHADER_PARAM_TYPE_VEC3, "5.0", "Phong tint for local specular lights" ) + SHADER_PARAM( PHONGALBEDOTINT, SHADER_PARAM_TYPE_BOOL, "1.0", "Apply tint by albedo (controlled by spec exponent texture" ) + SHADER_PARAM( PHONGDISABLEHALFLAMBERT, SHADER_PARAM_TYPE_BOOL, "0", "Disable half lambert for phong" ) // Rim lighting terms SHADER_PARAM( RIMLIGHT, SHADER_PARAM_TYPE_BOOL, "0", "enables rim lighting" ) @@ -81,6 +96,16 @@ BEGIN_VS_SHADER( RDCharacter, "Alien Swarm: Reactive Drop character shader" ) SHADER_PARAM( RIMLIGHTBOOST, SHADER_PARAM_TYPE_FLOAT, "1.0", "Boost for rim lights" ) SHADER_PARAM( RIMMASK, SHADER_PARAM_TYPE_BOOL, "0", "Indicates whether or not to use alpha channel of exponent texture to mask the rim term" ) + // detail texturing + SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" ) + SHADER_PARAM( DETAILFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $detail" ) + SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" ) + SHADER_PARAM( DETAILBLENDMODE, SHADER_PARAM_TYPE_INTEGER, "0", "mode for combining detail texture with base. 0=normal, 1= additive, 2=alpha blend detail over base, 3=crossfade" ) + SHADER_PARAM( DETAILBLENDFACTOR, SHADER_PARAM_TYPE_FLOAT, "1", "blend amount for detail texture." ) + SHADER_PARAM( DETAILTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "detail texture tint" ) + SHADER_PARAM( DETAILTEXTURETRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$detail texcoord transform" ) + SHADER_PARAM( SEPARATEDETAILUVS, SHADER_PARAM_TYPE_BOOL, "0", "Use texcoord1 for detail texture" ) + // Emissive Scroll Pass SHADER_PARAM( EMISSIVEBLENDENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enable emissive blend pass" ) SHADER_PARAM( EMISSIVEBLENDBASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "self-illumination map" ) @@ -119,39 +144,16 @@ BEGIN_VS_SHADER( RDCharacter, "Alien Swarm: Reactive Drop character shader" ) SHADER_PARAM( FLESHGLOSSBRIGHTNESS, SHADER_PARAM_TYPE_FLOAT, "0.66", "Flesh gloss brightness" ) SHADER_PARAM( FLESHSCROLLSPEED, SHADER_PARAM_TYPE_FLOAT, "1.0", "Flesh scroll speed" ) - SHADER_PARAM( SEPARATEDETAILUVS, SHADER_PARAM_TYPE_BOOL, "0", "Use texcoord1 for detail texture" ) - SHADER_PARAM( LINEARWRITE, SHADER_PARAM_TYPE_INTEGER, "0", "Disables SRGB conversion of shader results." ) - - SHADER_PARAM( SHADERSRGBREAD360, SHADER_PARAM_TYPE_BOOL, "0", "Simulate srgb read in shader code" ) - - SHADER_PARAM( AMBIENTOCCLUSION, SHADER_PARAM_TYPE_FLOAT, "0.0", "Amount of screen space ambient occlusion to use (0..1 range)" ) - - SHADER_PARAM( DISPLACEMENTMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Displacement map" ) - - SHADER_PARAM( BLENDTINTBYBASEALPHA, SHADER_PARAM_TYPE_BOOL, "0", "Use the base alpha to blend in the $color modulation" ) - - SHADER_PARAM( DESATURATEWITHBASEALPHA, SHADER_PARAM_TYPE_FLOAT, "0.0", "Use the base alpha to desaturate the base texture. Set to non-zero to enable, value gets multiplied into the alpha channel before desaturating." ) - - SHADER_PARAM( ALLOWDIFFUSEMODULATION, SHADER_PARAM_TYPE_BOOL, "1", "Allow per-instance color modulation" ) - - // vertexlitgeneric envmap fresnel control - SHADER_PARAM( ENVMAPFRESNELMINMAXEXP, SHADER_PARAM_TYPE_VEC3, "[0.0 1.0 2.0]", "Min/max fresnel range and exponent for vertexlitgeneric" ) - SHADER_PARAM( BASEALPHAENVMAPMASKMINMAXEXP, SHADER_PARAM_TYPE_VEC3, "[1.0 0.0 1.0]", "" ) - - // This is to allow phong materials to disable half lambert. Half lambert has always been forced on in phong, - // so the only safe way to allow artists to disable half lambert is to create this param that disables the - // default behavior of forcing half lambert on. - SHADER_PARAM( PHONGDISABLEHALFLAMBERT, SHADER_PARAM_TYPE_BOOL, "0", "Disable half lambert for phong" ) - - SHADER_PARAM( TINTMASKTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Separate tint mask texture (as opposed to using basetexture alpha)" ) - SHADER_PARAM( HSV, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "HSV color to transform $basetexture texture with" ) - + // Character Proxy SHADER_PARAM( CHARACTER_PROXY_ATTACHED, SHADER_PARAM_TYPE_BOOL, "0", "Flag to determine whether material proxy has been successfully attached" ) SHADER_PARAM( CHARACTER_TEAM_COLOR, SHADER_PARAM_TYPE_COLOR, "[0 0 0 0]", "Glow color and intensity for team highlights." ) SHADER_PARAM( CHARACTER_STATUS_FX, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0]", "Intensity for fire, ice, shock, and night vision effects." ) SHADER_PARAM( CHARACTER_BURNING_LAYER, SHADER_PARAM_TYPE_TEXTURE, "effects/TiledFire/fire_tiled", "Fire effect texture" ) SHADER_PARAM( CHARACTER_FROZEN_LAYER, SHADER_PARAM_TYPE_TEXTURE, "effects/model_layer_ice_1", "Ice effect texture" ) SHADER_PARAM( CHARACTER_SHOCK_LAYER, SHADER_PARAM_TYPE_TEXTURE, "effects/model_layer_shock_1", "Shock effect texture" ) + + // Debugging term for visualizing ambient data on its own + SHADER_PARAM( AMBIENTONLY, SHADER_PARAM_TYPE_INTEGER, "0", "Control drawing of non-ambient light ()" ) END_SHADER_PARAMS void SetupVars( Character_DX9_Vars_t &info ) From aa3960899d3ddf5b4b5f4648fbab1d077dfa060a Mon Sep 17 00:00:00 2001 From: kitsune Date: Sat, 13 Dec 2025 20:56:48 +0100 Subject: [PATCH 4/4] Consolidate diffuse modulation for shading. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, diffuse modulation was applied only to the diffuse lighting terms while other shading paths—such as self-illumination, night vision, and Phong-based effects—continued to use the unmodulated base color. This led to inconsistent material appearance and visual artifacts when per-instance color overrides (e.g., rendercolor or proxy-driven modulation) were used. This change applies diffuse modulation to the base color itself before any shading calculations, ensuring that all subsequent lighting and shading paths operate on the fully modulated color. The visual output is now consistent, and the shader behavior aligns with the intended use of diffuse modulation as a persistent per-instance color modification. --- .../stdshaders/character_ps20b.fxc | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/materialsystem/stdshaders/character_ps20b.fxc b/src/materialsystem/stdshaders/character_ps20b.fxc index eda393fbe..2666584a2 100644 --- a/src/materialsystem/stdshaders/character_ps20b.fxc +++ b/src/materialsystem/stdshaders/character_ps20b.fxc @@ -211,6 +211,9 @@ float4 main( PS_INPUT i ) : COLOR baseColor.xyz = lerp(baseColor.xyz, hsv2rgb(baseColorHSV), saturate(baseColor.a + g_fInverseBlendTintByBaseAlpha)); #endif + // Optionally use basealpha to blend in the diffuse modulation (saturated add of g_fInverseBlendTintByBaseAlpha turns this on/off) + baseColor.rgb *= lerp(float3(1.0f, 1.0f, 1.0f), g_DiffuseModulation.rgb, saturate(baseColor.a + g_fInverseBlendTintByBaseAlpha)); + float flWrinkleAmount, flStretchAmount, flTextureAmount; #if ( WRINKLEMAP ) { @@ -326,7 +329,6 @@ float4 main( PS_INPUT i ) : COLOR } #endif - float3 albedo = baseColor.rgb; float3 specularLighting = float3( 0.0f, 0.0f, 0.0f ); float3 rimLighting = float3( 0.0f, 0.0f, 0.0f ); @@ -383,10 +385,7 @@ float4 main( PS_INPUT i ) : COLOR } #endif - // Optionally use basealpha to blend in the diffuse modulation (saturated add of g_fInverseBlendTintByBaseAlpha turns this on/off) - diffuseLighting *= lerp( float3( 1.0f, 1.0f, 1.0f ), g_DiffuseModulation.rgb, saturate( baseColor.a + g_fInverseBlendTintByBaseAlpha ) ); - - float3 diffuseComponent = albedo * diffuseLighting; + float3 diffuseComponent = baseColor.rgb * diffuseLighting; #if ( SELFILLUM && !FLASHLIGHT ) { @@ -397,13 +396,13 @@ float4 main( PS_INPUT i ) : COLOR float3 vSelfIllumMask = tex2D( SelfIllumMaskSampler, i.baseTexCoordDetailTexCoord.xy ); vSelfIllumMask = lerp( baseColor.aaa, vSelfIllumMask, g_SelfIllumMaskControl ); float flSelfIllumFresnel = ( pow( saturate( dot( vVertexNormal.xyz, vEyeDir.xyz ) ), g_SelfIllumScaleBiasExpBrightness.z ) * g_SelfIllumScaleBiasExpBrightness.x ) + g_SelfIllumScaleBiasExpBrightness.y; - diffuseComponent = lerp( diffuseComponent, g_SelfIllumTint_and_DetailBlendFactor.rgb * albedo * g_SelfIllumScaleBiasExpBrightness.w, vSelfIllumMask.rgb * saturate( flSelfIllumFresnel ) ); + diffuseComponent = lerp( diffuseComponent, g_SelfIllumTint_and_DetailBlendFactor.rgb * baseColor.rgb * g_SelfIllumScaleBiasExpBrightness.w, vSelfIllumMask.rgb * saturate( flSelfIllumFresnel ) ); } #else { float3 vSelfIllumMask = tex2D( SelfIllumMaskSampler, i.baseTexCoordDetailTexCoord.xy ); vSelfIllumMask = lerp( baseColor.aaa, vSelfIllumMask, g_SelfIllumMaskControl ); - diffuseComponent = lerp( diffuseComponent, g_SelfIllumTint_and_DetailBlendFactor.rgb * albedo, vSelfIllumMask ); + diffuseComponent = lerp( diffuseComponent, g_SelfIllumTint_and_DetailBlendFactor.rgb * baseColor.rgb, vSelfIllumMask ); } #endif @@ -415,11 +414,11 @@ float4 main( PS_INPUT i ) : COLOR { if ( g_fNightVisionAmount < 1.0 ) { - diffuseComponent = lerp( diffuseComponent, albedo, g_fNightVisionAmount ); + diffuseComponent = lerp( diffuseComponent, baseColor.rgb, g_fNightVisionAmount ); } else { - diffuseComponent = albedo * g_fNightVisionAmount; + diffuseComponent = baseColor.rgb * g_fNightVisionAmount; } } #endif