mirror of https://github.com/PCSX2/pcsx2.git
glsl: add shader implementation of impossible blend
Issue: I don't know if destination alpha value must be multiplied by 2.0f
This commit is contained in:
parent
f029e4763f
commit
7fac25edb0
|
@ -375,6 +375,43 @@ vec4 ps_color()
|
|||
return c;
|
||||
}
|
||||
|
||||
void ps_blend(inout vec4 c, in float As)
|
||||
{
|
||||
vec4 rt = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0);
|
||||
// FIXME Ad or Ad * 2?
|
||||
float Ad = rt.a;
|
||||
|
||||
#if PS_BLEND == 1
|
||||
// {4, D3DBLENDOP_SUBTRACT, D3DBLEND_SRCALPHA, D3DBLEND_SRCALPHA}, //*0100: (Cs - Cd)*As + Cs ==> Cs*(As + 1) - Cd*As
|
||||
c.rgb = c.rgb * (As + 1.0f) - rt.rgb * As;
|
||||
#elif PS_BLEND == 2
|
||||
// {5, D3DBLENDOP_SUBTRACT, D3DBLEND_DESTALPHA, D3DBLEND_DESTALPHA}, //*0110: (Cs - Cd)*Ad + Cs ==> Cs*(Ad + 1) - Cd*Ad
|
||||
c.rgb = c.rgb * (Ad + 1.0f) - rt.rgb * Ad;
|
||||
#elif PS_BLEND == 3
|
||||
// {6, D3DBLENDOP_SUBTRACT, D3DBLEND_BLENDFACTOR, D3DBLEND_BLENDFACTOR}, //*0120: (Cs - Cd)*F + Cs ==> Cs*(F + 1) - Cd*F
|
||||
c.rgb = c.rgb * (Af.x + 1.0f) - rt.rgb * Af.x;
|
||||
#elif PS_BLEND == 4
|
||||
// {7, D3DBLENDOP_ADD, D3DBLEND_SRCALPHA, D3DBLEND_ZERO}, //*0200: (Cs - 0)*As + Cs ==> Cs*(As + 1)
|
||||
c.rgb = c.rgb * (As + 1.0f); // FIXME Not bogus
|
||||
#elif PS_BLEND == 5
|
||||
// {8, D3DBLENDOP_ADD, D3DBLEND_DESTALPHA, D3DBLEND_ZERO}, //*0210: (Cs - 0)*Ad + Cs ==> Cs*(Ad + 1)
|
||||
c.rgb = c.rgb * (Ad + 1.0f);
|
||||
#elif PS_BLEND == 6
|
||||
// {9, D3DBLENDOP_ADD, D3DBLEND_BLENDFACTOR, D3DBLEND_ZERO}, //*0220: (Cs - 0)*F + Cs ==> Cs*(F + 1)
|
||||
besoin du fix
|
||||
c.rgb = c.rgb * (Af.x + 1.0f); // FIXME Not bogus
|
||||
#elif PS_BLEND == 7
|
||||
// {10,D3DBLENDOP_REVSUBTRACT, D3DBLEND_SRCALPHA, D3DBLEND_SRCALPHA}, //*1001: (Cd - Cs)*As + Cd ==> Cd*(As + 1) - Cs*As
|
||||
c.rgb = rt.rgb * (As + 1.0f) - c.rgb * As;
|
||||
#elif PS_BLEND == 8
|
||||
// {11,D3DBLENDOP_REVSUBTRACT, D3DBLEND_DESTALPHA, D3DBLEND_DESTALPHA}, //*1011: (Cd - Cs)*Ad + Cd ==> Cd*(Ad + 1) - Cs*Ad
|
||||
c.rgb = rt.rgb * (Ad + 1.0f) - c.rgb * Ad;
|
||||
#elif PS_BLEND == 9
|
||||
// {12,D3DBLENDOP_REVSUBTRACT, D3DBLEND_BLENDFACTOR, D3DBLEND_BLENDFACTOR},//*1021: (Cd - Cs)*F + Cd ==> Cd*(F + 1) - Cs*F
|
||||
c.rgb = rt.rgb * (Af.x + 1.0f) - c.rgb * Af.x;
|
||||
#endif
|
||||
}
|
||||
|
||||
void ps_main()
|
||||
{
|
||||
#if (PS_DATE & 3) == 1 && !defined(DISABLE_GL42_image)
|
||||
|
@ -446,6 +483,10 @@ void ps_main()
|
|||
}
|
||||
#endif
|
||||
|
||||
#if PS_BLEND > 0
|
||||
ps_blend(c, alpha);
|
||||
#endif
|
||||
|
||||
SV_Target0 = c;
|
||||
SV_Target1 = vec4(alpha, alpha, alpha, alpha);
|
||||
}
|
||||
|
|
|
@ -1089,6 +1089,43 @@ static const char* tfx_fs_all_glsl =
|
|||
" return c;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"void ps_blend(inout vec4 c, in float As)\n"
|
||||
"{\n"
|
||||
" vec4 rt = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0);\n"
|
||||
" // FIXME Ad or Ad * 2?\n"
|
||||
" float Ad = rt.a;\n"
|
||||
"\n"
|
||||
"#if PS_BLEND == 1\n"
|
||||
" // {4, D3DBLENDOP_SUBTRACT, D3DBLEND_SRCALPHA, D3DBLEND_SRCALPHA}, //*0100: (Cs - Cd)*As + Cs ==> Cs*(As + 1) - Cd*As\n"
|
||||
" c.rgb = c.rgb * (As + 1.0f) - rt.rgb * As;\n"
|
||||
"#elif PS_BLEND == 2\n"
|
||||
" // {5, D3DBLENDOP_SUBTRACT, D3DBLEND_DESTALPHA, D3DBLEND_DESTALPHA}, //*0110: (Cs - Cd)*Ad + Cs ==> Cs*(Ad + 1) - Cd*Ad\n"
|
||||
" c.rgb = c.rgb * (Ad + 1.0f) - rt.rgb * Ad;\n"
|
||||
"#elif PS_BLEND == 3\n"
|
||||
" // {6, D3DBLENDOP_SUBTRACT, D3DBLEND_BLENDFACTOR, D3DBLEND_BLENDFACTOR}, //*0120: (Cs - Cd)*F + Cs ==> Cs*(F + 1) - Cd*F\n"
|
||||
" c.rgb = c.rgb * (Af.x + 1.0f) - rt.rgb * Af.x;\n"
|
||||
"#elif PS_BLEND == 4\n"
|
||||
" // {7, D3DBLENDOP_ADD, D3DBLEND_SRCALPHA, D3DBLEND_ZERO}, //*0200: (Cs - 0)*As + Cs ==> Cs*(As + 1)\n"
|
||||
" c.rgb = c.rgb * (As + 1.0f); // FIXME Not bogus\n"
|
||||
"#elif PS_BLEND == 5\n"
|
||||
" // {8, D3DBLENDOP_ADD, D3DBLEND_DESTALPHA, D3DBLEND_ZERO}, //*0210: (Cs - 0)*Ad + Cs ==> Cs*(Ad + 1)\n"
|
||||
" c.rgb = c.rgb * (Ad + 1.0f);\n"
|
||||
"#elif PS_BLEND == 6\n"
|
||||
" // {9, D3DBLENDOP_ADD, D3DBLEND_BLENDFACTOR, D3DBLEND_ZERO}, //*0220: (Cs - 0)*F + Cs ==> Cs*(F + 1)\n"
|
||||
" besoin du fix\n"
|
||||
" c.rgb = c.rgb * (Af.x + 1.0f); // FIXME Not bogus\n"
|
||||
"#elif PS_BLEND == 7\n"
|
||||
" // {10,D3DBLENDOP_REVSUBTRACT, D3DBLEND_SRCALPHA, D3DBLEND_SRCALPHA}, //*1001: (Cd - Cs)*As + Cd ==> Cd*(As + 1) - Cs*As\n"
|
||||
" c.rgb = rt.rgb * (As + 1.0f) - c.rgb * As;\n"
|
||||
"#elif PS_BLEND == 8\n"
|
||||
" // {11,D3DBLENDOP_REVSUBTRACT, D3DBLEND_DESTALPHA, D3DBLEND_DESTALPHA}, //*1011: (Cd - Cs)*Ad + Cd ==> Cd*(Ad + 1) - Cs*Ad\n"
|
||||
" c.rgb = rt.rgb * (Ad + 1.0f) - c.rgb * Ad;\n"
|
||||
"#elif PS_BLEND == 9\n"
|
||||
" // {12,D3DBLENDOP_REVSUBTRACT, D3DBLEND_BLENDFACTOR, D3DBLEND_BLENDFACTOR},//*1021: (Cd - Cs)*F + Cd ==> Cd*(F + 1) - Cs*F\n"
|
||||
" c.rgb = rt.rgb * (Af.x + 1.0f) - c.rgb * Af.x;\n"
|
||||
"#endif\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"void ps_main()\n"
|
||||
"{\n"
|
||||
"#if (PS_DATE & 3) == 1 && !defined(DISABLE_GL42_image)\n"
|
||||
|
@ -1160,6 +1197,10 @@ static const char* tfx_fs_all_glsl =
|
|||
" }\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
"#if PS_BLEND > 0\n"
|
||||
" ps_blend(c, alpha);\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
" SV_Target0 = c;\n"
|
||||
" SV_Target1 = vec4(alpha, alpha, alpha, alpha);\n"
|
||||
"}\n"
|
||||
|
|
Loading…
Reference in New Issue