From 1382fe9c6c1ff317b9a614f91d5cd52b0c003c6a Mon Sep 17 00:00:00 2001 From: lightningterror <18107717+lightningterror@users.noreply.github.com> Date: Mon, 6 Mar 2023 02:40:49 +0100 Subject: [PATCH] GS-metal: 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. --- pcsx2/GS/Renderers/Metal/tfx.metal | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pcsx2/GS/Renderers/Metal/tfx.metal b/pcsx2/GS/Renderers/Metal/tfx.metal index a12f5e5ff4..441b1e64ea 100644 --- a/pcsx2/GS/Renderers/Metal/tfx.metal +++ b/pcsx2/GS/Renderers/Metal/tfx.metal @@ -927,8 +927,13 @@ struct PSMain 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.f / 128.f); + // 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.f / max(128.f, max_color); + Color.rgb *= float3(color_compensate); } } }