From e8cf4822b123fd371df6acaa14aef3498b9c4c6e Mon Sep 17 00:00:00 2001 From: lightningterror <18107717+lightningterror@users.noreply.github.com> Date: Mon, 6 Mar 2023 02:40:00 +0100 Subject: [PATCH] GS-d3d: Automatically adjust color compensation based on rgb value for hw blend clr3 case. Auto adjust when any color is higher than 128 ( 1.0f) to get more accurate color results. --- bin/resources/shaders/dx11/tfx.fx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bin/resources/shaders/dx11/tfx.fx b/bin/resources/shaders/dx11/tfx.fx index 12d93a0b4d..8ab748abb8 100644 --- a/bin/resources/shaders/dx11/tfx.fx +++ b/bin/resources/shaders/dx11/tfx.fx @@ -872,9 +872,13 @@ void ps_blend(inout float4 Color, inout float4 As_rgba, float2 pos_xy) else if (PS_CLR_HW == 3) { // Needed for Cs*Ad, Cs*Ad + Cd, Cd - Cs*Ad - // Multiply Color.rgb by (255/128) to compensate for wrong Ad/255 value - - Color.rgb *= (255.0f / 128.0f); + // Multiply Color.rgb by (255/128) to compensate for wrong Ad/255 value when rgb are below 128. + // When any color channel is higher than 128 then adjust the compensation automatically + // to give us more accurate colors, otherwise they will be wrong. + // The higher the value (>128) the lower the compensation will be. + float max_color = max(max(Color.r, Color.g), Color.b); + float color_compensate = 255.0f / max(128.0f, max_color); + Color.rgb *= (float3)color_compensate; } } }