Skip to content

Commit

Permalink
gsdx-hw: Implement per pixel alpha blending (PABE).
Browse files Browse the repository at this point in the history
Fixes Strawberry Shortcake character lighting/face shadow.
Fixes Cartoon Network Racing shadows.

Credits to Kojin.
  • Loading branch information
lightningterror committed Feb 6, 2021
1 parent d993e4e commit 3708906
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 14 deletions.
4 changes: 2 additions & 2 deletions plugins/GSdx/Renderers/DX11/GSDevice11.h
Expand Up @@ -233,8 +233,8 @@ class GSDevice11 final : public GSDevice
uint32 blend_c:2; // bit0
uint32 blend_d:2;
uint32 clr1:1;

uint32 colclip:1;
uint32 pabe:1;

// Others ways to fetch the texture
uint32 channel:3;
Expand All @@ -252,7 +252,7 @@ class GSDevice11 final : public GSDevice
uint32 point_sampler:1;
uint32 invalid_tex0:1; // Lupin the 3rd

uint32 _free:15;
uint32 _free:14;
};

uint64 key;
Expand Down
4 changes: 3 additions & 1 deletion plugins/GSdx/Renderers/DX11/GSRendererDX11.cpp
Expand Up @@ -470,7 +470,9 @@ void GSRendererDX11::EmulateBlending()
m_om_bsel.abe = 0;
}

// Breath of Fire Dragon Quarter, Strawberry Shortcake, Super Robot Wars.
// Breath of Fire Dragon Quarter, Strawberry Shortcake, Super Robot Wars, Cartoon Network Racing.
// fprintf(stderr, "%d: PABE mode ENABLED\n", s_n);
m_ps_sel.pabe = 1;
}

m_om_bsel.blend_index = uint8(((ALPHA.A * 3 + ALPHA.B) * 3 + ALPHA.C) * 3 + ALPHA.D);
Expand Down
1 change: 1 addition & 0 deletions plugins/GSdx/Renderers/DX11/GSTextureFX11.cpp
Expand Up @@ -219,6 +219,7 @@ void GSDevice11::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSe
sm.AddMacro("PS_BLEND_B", sel.blend_b);
sm.AddMacro("PS_BLEND_C", sel.blend_c);
sm.AddMacro("PS_BLEND_D", sel.blend_d);
sm.AddMacro("PS_PABE", sel.pabe);
sm.AddMacro("PS_DITHER", sel.dither);
sm.AddMacro("PS_ZCLAMP", sel.zclamp);

Expand Down
2 changes: 1 addition & 1 deletion plugins/GSdx/Renderers/OpenGL/GSDeviceOGL.cpp
Expand Up @@ -984,7 +984,7 @@ GLuint GSDeviceOGL::CompilePS(PSSelector sel)
+ format("#define PS_HDR %d\n", sel.hdr)
+ format("#define PS_DITHER %d\n", sel.dither)
+ format("#define PS_ZCLAMP %d\n", sel.zclamp)
// + format("#define PS_PABE %d\n", sel.pabe)
+ format("#define PS_PABE %d\n", sel.pabe)
;

if (GLLoader::buggy_sso_dual_src)
Expand Down
4 changes: 2 additions & 2 deletions plugins/GSdx/Renderers/OpenGL/GSDeviceOGL.h
Expand Up @@ -300,7 +300,7 @@ class GSDeviceOGL final : public GSDevice
uint32 clr1:1; // useful?
uint32 hdr:1;
uint32 colclip:1;
// uint32 pabe:1;
uint32 pabe:1;

// Others ways to fetch the texture
uint32 channel:3;
Expand All @@ -321,7 +321,7 @@ class GSDeviceOGL final : public GSDevice
uint32 point_sampler:1;
uint32 invalid_tex0:1; // Lupin the 3rd

uint32 _free2:7;
uint32 _free2:6;
};

uint64 key;
Expand Down
11 changes: 3 additions & 8 deletions plugins/GSdx/Renderers/OpenGL/GSRendererOGL.cpp
Expand Up @@ -420,14 +420,9 @@ void GSRendererOGL::EmulateBlending(bool& DATE_GL42, bool& DATE_GL45)
}

if (m_env.PABE.PABE) {
GL_INS("ERROR: ENV PABE not supported!");
if (m_sw_blending >= ACC_BLEND_MEDIUM) {
// m_ps_sel.pabe = 1;
m_require_full_barrier |= (ALPHA.C == 1);
sw_blending = true;
}
// Breath of Fire Dragon Quarter, Strawberry Shortcake, Super Robot Wars.
//ASSERT(0);
// Breath of Fire Dragon Quarter, Strawberry Shortcake, Super Robot Wars, Cartoon Network Racing.
GL_INS("PABE mode ENABLED");
m_ps_sel.pabe = 1;
}

// Compute the blending equation to detect special case
Expand Down
6 changes: 6 additions & 0 deletions plugins/GSdx/res/glsl/tfx_fs.glsl
Expand Up @@ -627,6 +627,7 @@ void ps_blend(inout vec4 Color, float As)
{
#if SW_BLEND
vec4 RT = trunc(texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0) * 255.0f + 0.1f);
vec4 Color_pabe = Color;

#if PS_DFMT == FMT_24
float Ad = 1.0f;
Expand Down Expand Up @@ -678,6 +679,11 @@ void ps_blend(inout vec4 Color, float As)
Color.rgb = trunc((A - B) * C + D);
#endif

// PABE
#if PS_PABE
Color.rgb = (Color_pabe.a >= 128.0f) ? Color.rgb : Color_pabe.rgb;
#endif

// Dithering
ps_dither(Color);

Expand Down
5 changes: 5 additions & 0 deletions plugins/GSdx/res/tfx.fx
Expand Up @@ -48,6 +48,7 @@
#define PS_BLEND_B 0
#define PS_BLEND_C 0
#define PS_BLEND_D 0
#define PS_PABE 0
#define PS_DITHER 0
#define PS_ZCLAMP 0
#endif
Expand Down Expand Up @@ -685,6 +686,10 @@ void ps_blend(inout float4 Color, float As, float2 pos_xy)

Cv = (PS_BLEND_A == PS_BLEND_B) ? D : trunc(((A - B) * C) + D);

// PABE
if (PS_PABE)
Cv = (Color.a >= 128.0f) ? Cv : Color.rgb;

// Dithering
ps_dither(Cv, pos_xy);

Expand Down

0 comments on commit 3708906

Please sign in to comment.