From 4e9b7e61a7a2e42b2b56c699d10dece83089e0c0 Mon Sep 17 00:00:00 2001 From: lightningterror <18107717+lightningterror@users.noreply.github.com> Date: Tue, 21 Feb 2023 17:37:29 +0100 Subject: [PATCH] GS-ogl: Check each channel individually if it overflows and do corrections. --- bin/resources/shaders/opengl/tfx_fs.glsl | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/bin/resources/shaders/opengl/tfx_fs.glsl b/bin/resources/shaders/opengl/tfx_fs.glsl index 9bb657db39..b2029da798 100644 --- a/bin/resources/shaders/opengl/tfx_fs.glsl +++ b/bin/resources/shaders/opengl/tfx_fs.glsl @@ -686,8 +686,10 @@ void ps_color_clamp_wrap(inout vec3 C) #endif } -void ps_blend(inout vec4 Color, inout float As) +void ps_blend(inout vec4 Color, inout vec4 As_rgba) { +float As = As_rgba.a; + #if SW_BLEND // PABE @@ -768,16 +770,15 @@ void ps_blend(inout vec4 Color, inout float As) #if PS_CLR_HW == 1 // Replace Af with As so we can do proper compensation for Alpha. #if PS_BLEND_C == 2 - As = Af; + As_rgba = vec4(Af); #endif // 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, // we divide by 255 the color because we don't know Cd value, // changed alpha should only be done for hw blend. - float min_color = min(min(Color.r, Color.g), Color.b); - float alpha_compensate = max(1.0f, min_color / 255.0f); - As -= alpha_compensate; + vec3 alpha_compensate = max(vec3(1.0f), Color.rgb / vec3(255.0f)); + As_rgba.rgb -= alpha_compensate; #elif PS_CLR_HW == 2 // Compensate slightly for Cd*(As + 1) - Cs*As. // The initial factor we chose is 1 (0.00392) @@ -927,9 +928,9 @@ void ps_main() #if SW_AD_TO_HW vec4 RT = trunc(fetch_rt() * 255.0f + 0.1f); - float alpha_blend = RT.a / 128.0f; + vec4 alpha_blend = vec4(RT.a / 128.0f); #else - float alpha_blend = C.a / 128.0f; + vec4 alpha_blend = vec4(C.a / 128.0f); #endif // Correct the ALPHA value based on the output format @@ -969,12 +970,12 @@ void ps_main() SV_Target0 = C / 255.0f; #endif #if !defined(DISABLE_DUAL_SOURCE) && !PS_NO_COLOR1 - SV_Target1 = vec4(alpha_blend); + SV_Target1 = alpha_blend; #endif #if PS_NO_ABLEND // write alpha blend factor into col0 - SV_Target0.a = alpha_blend; + SV_Target0.a = alpha_blend.a; #endif #if PS_ONLY_ALPHA // rgb isn't used