From a3ecf0b0bda446b3e4faf89deada4ca119f390da Mon Sep 17 00:00:00 2001 From: lightningterror <18107717+lightningterror@users.noreply.github.com> Date: Sun, 26 Feb 2023 21:59:24 +0100 Subject: [PATCH] GS-vk: Add clr3 case for blend mix 2. When Cs*(Alpha + 1) overflows compensate with adjusting Alpha output for Cd*Alpha. --- bin/resources/shaders/vulkan/tfx.glsl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/resources/shaders/vulkan/tfx.glsl b/bin/resources/shaders/vulkan/tfx.glsl index 95ccb63df1..fdcc73481b 100644 --- a/bin/resources/shaders/vulkan/tfx.glsl +++ b/bin/resources/shaders/vulkan/tfx.glsl @@ -1096,10 +1096,8 @@ void ps_blend(inout vec4 Color, inout vec4 As_rgba) #endif #if PS_CLR_HW == 1 - // Replace Af with As so we can do proper compensation for Alpha. - #if PS_BLEND_C == 2 - As_rgba = vec4(Af); - #endif + // As or Af + As_rgba.rgb = vec3(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, @@ -1115,6 +1113,14 @@ void ps_blend(inout vec4 Color, inout vec4 As_rgba) // blended value it can be. float color_compensate = 1.0f * (C + 1.0f); Color.rgb -= vec3(color_compensate); + #elif PS_CLR_HW == 3 + // As, Ad or Af clamped. + As_rgba.rgb = vec3(C_clamped); + // Cs*(Alpha + 1) might overflow, if it does then adjust alpha value + // that is sent on second output to compensate. + vec3 overflow_check = (Color.rgb - vec3(255.0f)) / 255.0f; + vec3 alpha_compensate = max(vec3(0.0f), overflow_check); + As_rgba.rgb -= alpha_compensate; #endif #else