From f478b3959c2e2e5cab8d5f6a8cbb85a6b3175b33 Mon Sep 17 00:00:00 2001 From: lightningterror <18107717+lightningterror@users.noreply.github.com> Date: Sun, 26 Feb 2023 21:58:34 +0100 Subject: [PATCH] GS-d3d: Add clr3 case for blend mix 2. When Cs*(Alpha + 1) overflows compensate with adjusting Alpha output for Cd*Alpha. --- bin/resources/shaders/dx11/tfx.fx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/bin/resources/shaders/dx11/tfx.fx b/bin/resources/shaders/dx11/tfx.fx index f310a0d80b..12d93a0b4d 100644 --- a/bin/resources/shaders/dx11/tfx.fx +++ b/bin/resources/shaders/dx11/tfx.fx @@ -821,9 +821,8 @@ void ps_blend(inout float4 Color, inout float4 As_rgba, float2 pos_xy) if (PS_CLR_HW == 1) { - // Replace Af with As so we can do proper compensation for Alpha. - if (PS_BLEND_C == 2) - As_rgba = (float4)Af; + // As or Af + As_rgba.rgb = (float3)C; // Subtract 1 for alpha to compensate for the changed equation, // if c.rgb > 255.0f then we further need to adjust alpha accordingly, // we pick the lowest overflow from all colors because it's the safest, @@ -842,6 +841,16 @@ void ps_blend(inout float4 Color, inout float4 As_rgba, float2 pos_xy) float color_compensate = 1.0f * (C + 1.0f); Color.rgb -= (float3)color_compensate; } + else if (PS_CLR_HW == 3) + { + // As, Ad or Af clamped. + As_rgba.rgb = (float3)C_clamped; + // Cs*(Alpha + 1) might overflow, if it does then adjust alpha value + // that is sent on second output to compensate. + float3 overflow_check = (Color.rgb - (float3)255.0f) / 255.0f; + float3 alpha_compensate = max((float3)0.0f, overflow_check); + As_rgba.rgb -= alpha_compensate; + } } else {