Skip to content

Commit aa39608

Browse files
committed
Consolidate diffuse modulation for shading.
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.
1 parent 7b7e060 commit aa39608

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

src/materialsystem/stdshaders/character_ps20b.fxc

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ float4 main( PS_INPUT i ) : COLOR
211211
baseColor.xyz = lerp(baseColor.xyz, hsv2rgb(baseColorHSV), saturate(baseColor.a + g_fInverseBlendTintByBaseAlpha));
212212
#endif
213213

214+
// Optionally use basealpha to blend in the diffuse modulation (saturated add of g_fInverseBlendTintByBaseAlpha turns this on/off)
215+
baseColor.rgb *= lerp(float3(1.0f, 1.0f, 1.0f), g_DiffuseModulation.rgb, saturate(baseColor.a + g_fInverseBlendTintByBaseAlpha));
216+
214217
float flWrinkleAmount, flStretchAmount, flTextureAmount;
215218
#if ( WRINKLEMAP )
216219
{
@@ -326,7 +329,6 @@ float4 main( PS_INPUT i ) : COLOR
326329
}
327330
#endif
328331

329-
float3 albedo = baseColor.rgb;
330332

331333
float3 specularLighting = float3( 0.0f, 0.0f, 0.0f );
332334
float3 rimLighting = float3( 0.0f, 0.0f, 0.0f );
@@ -383,10 +385,7 @@ float4 main( PS_INPUT i ) : COLOR
383385
}
384386
#endif
385387

386-
// Optionally use basealpha to blend in the diffuse modulation (saturated add of g_fInverseBlendTintByBaseAlpha turns this on/off)
387-
diffuseLighting *= lerp( float3( 1.0f, 1.0f, 1.0f ), g_DiffuseModulation.rgb, saturate( baseColor.a + g_fInverseBlendTintByBaseAlpha ) );
388-
389-
float3 diffuseComponent = albedo * diffuseLighting;
388+
float3 diffuseComponent = baseColor.rgb * diffuseLighting;
390389

391390
#if ( SELFILLUM && !FLASHLIGHT )
392391
{
@@ -397,13 +396,13 @@ float4 main( PS_INPUT i ) : COLOR
397396
float3 vSelfIllumMask = tex2D( SelfIllumMaskSampler, i.baseTexCoordDetailTexCoord.xy );
398397
vSelfIllumMask = lerp( baseColor.aaa, vSelfIllumMask, g_SelfIllumMaskControl );
399398
float flSelfIllumFresnel = ( pow( saturate( dot( vVertexNormal.xyz, vEyeDir.xyz ) ), g_SelfIllumScaleBiasExpBrightness.z ) * g_SelfIllumScaleBiasExpBrightness.x ) + g_SelfIllumScaleBiasExpBrightness.y;
400-
diffuseComponent = lerp( diffuseComponent, g_SelfIllumTint_and_DetailBlendFactor.rgb * albedo * g_SelfIllumScaleBiasExpBrightness.w, vSelfIllumMask.rgb * saturate( flSelfIllumFresnel ) );
399+
diffuseComponent = lerp( diffuseComponent, g_SelfIllumTint_and_DetailBlendFactor.rgb * baseColor.rgb * g_SelfIllumScaleBiasExpBrightness.w, vSelfIllumMask.rgb * saturate( flSelfIllumFresnel ) );
401400
}
402401
#else
403402
{
404403
float3 vSelfIllumMask = tex2D( SelfIllumMaskSampler, i.baseTexCoordDetailTexCoord.xy );
405404
vSelfIllumMask = lerp( baseColor.aaa, vSelfIllumMask, g_SelfIllumMaskControl );
406-
diffuseComponent = lerp( diffuseComponent, g_SelfIllumTint_and_DetailBlendFactor.rgb * albedo, vSelfIllumMask );
405+
diffuseComponent = lerp( diffuseComponent, g_SelfIllumTint_and_DetailBlendFactor.rgb * baseColor.rgb, vSelfIllumMask );
407406
}
408407
#endif
409408

@@ -415,11 +414,11 @@ float4 main( PS_INPUT i ) : COLOR
415414
{
416415
if ( g_fNightVisionAmount < 1.0 )
417416
{
418-
diffuseComponent = lerp( diffuseComponent, albedo, g_fNightVisionAmount );
417+
diffuseComponent = lerp( diffuseComponent, baseColor.rgb, g_fNightVisionAmount );
419418
}
420419
else
421420
{
422-
diffuseComponent = albedo * g_fNightVisionAmount;
421+
diffuseComponent = baseColor.rgb * g_fNightVisionAmount;
423422
}
424423
}
425424
#endif

0 commit comments

Comments
 (0)