glsl: redo blending management to use A/B/C/D directly

1/ Code is much more readable
2/ It will allow to round differently the operation in the future
This commit is contained in:
Gregory Hainaut 2015-07-13 15:19:33 +02:00
parent e245b27c97
commit 784822a5c2
5 changed files with 90 additions and 469 deletions

View File

@ -659,7 +659,10 @@ GLuint GSDeviceOGL::CompilePS(PSSelector sel)
+ format("#define PS_DATE %d\n", sel.date)
+ format("#define PS_TCOFFSETHACK %d\n", sel.tcoffsethack)
//+ format("#define PS_POINT_SAMPLER %d\n", sel.point_sampler)
+ format("#define PS_BLEND %d\n", sel.blend)
+ format("#define PS_BLEND_A %d\n", sel.blend_a)
+ format("#define PS_BLEND_B %d\n", sel.blend_b)
+ format("#define PS_BLEND_C %d\n", sel.blend_c)
+ format("#define PS_BLEND_D %d\n", sel.blend_d)
+ format("#define PS_IIP %d\n", sel.iip)
+ format("#define PS_SHUFFLE %d\n", sel.shuffle)
+ format("#define PS_READ_BA %d\n", sel.read_ba)
@ -700,14 +703,10 @@ void GSDeviceOGL::SelfShaderTest()
sel.tfx = 4;
int ib = (i + 1) % 3;
#if 1
sel.blend = i*5;
#else
sel.blend_a = i;
sel.blend_b = ib;;
sel.blend_c = i;
sel.blend_d = i;
#endif
sel.colclip = colclip;
sel.dfmt = fmt;

View File

@ -354,7 +354,10 @@ class GSDeviceOGL : public GSDevice
//uint32 _free1:0;
// Word 2
uint32 blend:8;
uint32 blend_a:2;
uint32 blend_b:2;
uint32 blend_c:2;
uint32 blend_d:2;
uint32 dfmt:2;
uint32 fbmask:1;

View File

@ -789,7 +789,10 @@ void GSRendererOGL::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sour
GL_INS("!!! SW blending effect used (0x%x from sel %d) !!!", bogus_blend, blend_sel);
// select a shader that support blending
ps_sel.blend = bogus_blend & 0xFF;
ps_sel.blend_a = om_bsel.a;
ps_sel.blend_b = om_bsel.b;
ps_sel.blend_c = om_bsel.c;
ps_sel.blend_d = om_bsel.d;
dev->PSSetShaderResource(3, rt);

View File

@ -18,6 +18,8 @@
// And I say this as an ATI user.
#define ATI_SUCKS 0
#define SW_BLEND (PS_BLEND_A || PS_BLEND_B || PS_BLEND_D)
#ifdef FRAGMENT_SHADER
in SHADER
@ -408,9 +410,9 @@ void ps_fbmask(inout vec4 c)
#endif
}
#if PS_BLEND > 0
void ps_blend(inout vec4 c, in float As)
{
#if SW_BLEND
vec4 rt = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0);
#if PS_DFMT == FMT_24
float Ad = 1.0f;
@ -423,234 +425,42 @@ void ps_blend(inout vec4 c, in float As)
vec3 Cd = rt.rgb;
vec3 Cs = c.rgb;
#if PS_BLEND == 1
// 1 => 0000: (Cs - Cs)*As + Cs ==> Cs
; // nop
#if PS_BLEND_A == 0
vec3 A = Cs;
#elif PS_BLEND_A == 1
vec3 A = Cd;
#else
vec3 A = vec3(0.0f);
#endif
#elif PS_BLEND == 2
// 2 => 0001: (Cs - Cs)*As + Cd ==> Cd
c.rgb = Cd;
#if PS_BLEND_B == 0
vec3 B = Cs;
#elif PS_BLEND_B == 1
vec3 B = Cd;
#else
vec3 B = vec3(0.0f);
#endif
#elif PS_BLEND == 3
// 3 => 0002: (Cs - Cs)*As + 0 ==> 0
c.rgb = vec3(0.0);
#if PS_BLEND_C == 0
float C = As;
#elif PS_BLEND_C == 1
float C = Ad;
#else
float C = Af;
#endif
#elif PS_BLEND == 4
// 4 => *0100: (Cs - Cd)*As + Cs ==> Cs*(As + 1) - Cd*As
c.rgb = Cs * (As + 1.0f) - Cd * As;
#elif PS_BLEND == 5
// 5 => *0110: (Cs - Cd)*Ad + Cs ==> Cs*(Ad + 1) - Cd*Ad
c.rgb = Cs * (Ad + 1.0f) - Cd * Ad;
#elif PS_BLEND == 6
// 6 => *0120: (Cs - Cd)*F + Cs ==> Cs*(F + 1) - Cd*F
c.rgb = Cs * (Af + 1.0f) - Cd * Af;
#elif PS_BLEND == 7
// 7 => *0200: (Cs - 0)*As + Cs ==> Cs*(As + 1)
c.rgb = Cs * (As + 1.0f);
#elif PS_BLEND == 8
// 8 => *0210: (Cs - 0)*Ad + Cs ==> Cs*(Ad + 1)
c.rgb = Cs * (Ad + 1.0f);
#elif PS_BLEND == 9
// 9 => *0220: (Cs - 0)*F + Cs ==> Cs*(F + 1)
c.rgb = Cs * (Af + 1.0f);
#elif PS_BLEND == 10
// 10 => *1001: (Cd - Cs)*As + Cd ==> Cd*(As + 1) - Cs*As
c.rgb = Cd * (As + 1.0f) - Cs * As;
#elif PS_BLEND == 11
// 11 => *1011: (Cd - Cs)*Ad + Cd ==> Cd*(Ad + 1) - Cs*Ad
c.rgb = Cd * (Ad + 1.0f) - Cs * Ad;
#elif PS_BLEND == 12
// 12 => *1021: (Cd - Cs)*F + Cd ==> Cd*(F + 1) - Cs*F
c.rgb = Cd * (Af + 1.0f) - Cs * Af;
#elif PS_BLEND == 13
// 13 => 0101: (Cs - Cd)*As + Cd ==> Cs*As + Cd*(1 - As)
c.rgb = Cs * As + Cd * (1.0f - As);
#elif PS_BLEND == 14
// 14 => 0102: (Cs - Cd)*As + 0 ==> Cs*As - Cd*As
c.rgb = Cs * As - Cd * As;
#elif PS_BLEND == 15
// 15 => 0111: (Cs - Cd)*Ad + Cd ==> Cs*Ad + Cd*(1 - Ad)
c.rgb = Cs * Ad + Cd * (1.0f - Ad);
#elif PS_BLEND == 16
// 16 => 0112: (Cs - Cd)*Ad + 0 ==> Cs*Ad - Cd*Ad
c.rgb = Cs * Ad - Cd * Ad;
#elif PS_BLEND == 17
// 17 => 0121: (Cs - Cd)*F + Cd ==> Cs*F + Cd*(1 - F)
c.rgb = Cs * Af + Cd * (1.0f - Af);
#elif PS_BLEND == 18
// 18 => 0122: (Cs - Cd)*F + 0 ==> Cs*F - Cd*F
c.rgb = Cs * Af - Cd * Af;
#elif PS_BLEND == 19
// 19 => 0201: (Cs - 0)*As + Cd ==> Cs*As + Cd
c.rgb = Cs * As + Cd;
#elif PS_BLEND == 20
// 20 => 0202: (Cs - 0)*As + 0 ==> Cs*As
c.rgb = Cs * As;
#elif PS_BLEND == 21
// 21 => 0211: (Cs - 0)*Ad + Cd ==> Cs*Ad + Cd
c.rgb = Cs * Ad + Cd;
#elif PS_BLEND == 22
// 22 => 0212: (Cs - 0)*Ad + 0 ==> Cs*Ad
c.rgb = Cs * Ad;
#elif PS_BLEND == 23
// 23 => 0221: (Cs - 0)*F + Cd ==> Cs*F + Cd
c.rgb = Cs * Af + Cd;
#elif PS_BLEND == 24
// 24 => 0222: (Cs - 0)*F + 0 ==> Cs*F
c.rgb = Cs * Af;
#elif PS_BLEND == 25
// 25 => 1000: (Cd - Cs)*As + Cs ==> Cd*As + Cs*(1 - As)
c.rgb = Cd * As + Cs * (1.0f - As);
#elif PS_BLEND == 26
// 26 => 1002: (Cd - Cs)*As + 0 ==> Cd*As - Cs*As
c.rgb = Cd * As - Cs * As;
#elif PS_BLEND == 27
// 27 => 1010: (Cd - Cs)*Ad + Cs ==> Cd*Ad + Cs*(1 - Ad)
c.rgb = Cd * Ad + Cs * (1.0f - Ad);
#elif PS_BLEND == 28
// 28 => 1012: (Cd - Cs)*Ad + 0 ==> Cd*Ad - Cs*Ad
c.rgb = Cd * Ad - Cs * Ad;
#elif PS_BLEND == 29
// 29 => 1020: (Cd - Cs)*F + Cs ==> Cd*F + Cs*(1 - F)
c.rgb = Cd * Af + Cs * (1.0f - Af);
#elif PS_BLEND == 30
// 30 => 1022: (Cd - Cs)*F + 0 ==> Cd*F - Cs*F
c.rgb = Cd * Af - Cs * Af;
#elif PS_BLEND == 31
// 31 => 1200: (Cd - 0)*As + Cs ==> Cs + Cd*As
c.rgb = Cs + Cd * As;
#elif PS_BLEND == 55
// C_CLR | 55 => #1201: (Cd - 0)*As + Cd ==> Cd*(1 + As)
c.rgb = Cd * (1.0f + As);
#elif PS_BLEND == 32
// 32 => 1202: (Cd - 0)*As + 0 ==> Cd*As
c.rgb = Cd * As;
#elif PS_BLEND == 33
// 33 => 1210: (Cd - 0)*Ad + Cs ==> Cs + Cd*Ad
c.rgb = Cs + Cd * Ad;
#elif PS_BLEND == 56
// C_CLR | 56 => #1211: (Cd - 0)*Ad + Cd ==> Cd*(1 + Ad)
c.rgb = Cd * (1.0f + Ad);
#elif PS_BLEND == 34
// 34 => 1212: (Cd - 0)*Ad + 0 ==> Cd*Ad
c.rgb = Cd * Ad;
#elif PS_BLEND == 35
// 35 => 1220: (Cd - 0)*F + Cs ==> Cs + Cd*F
c.rgb = Cs + Cd * Af;
#elif PS_BLEND == 57
// C_CLR | 57 => #1221: (Cd - 0)*F + Cd ==> Cd*(1 + F)
c.rgb = Cd * (1.0f + Af);
#elif PS_BLEND == 36
// 36 => 1222: (Cd - 0)*F + 0 ==> Cd*F
c.rgb = Cd * Af;
#elif PS_BLEND == 37
// 37 => 2000: (0 - Cs)*As + Cs ==> Cs*(1 - As)
c.rgb = Cs * (1.0f - As);
#elif PS_BLEND == 38
// 38 => 2001: (0 - Cs)*As + Cd ==> Cd - Cs*As
c.rgb = Cd - Cs * As;
#elif PS_BLEND == 39
// 39 => 2002: (0 - Cs)*As + 0 ==> 0 - Cs*As
c.rgb = - Cs * As;
#elif PS_BLEND == 40
// 40 => 2010: (0 - Cs)*Ad + Cs ==> Cs*(1 - Ad)
c.rgb = Cs * (1.0f - Ad);
#elif PS_BLEND == 41
// 41 => 2011: (0 - Cs)*Ad + Cd ==> Cd - Cs*Ad
c.rgb = Cd - Cs * Ad;
#elif PS_BLEND == 42
// 42 => 2012: (0 - Cs)*Ad + 0 ==> 0 - Cs*Ad
c.rgb = - Cs * Ad;
#elif PS_BLEND == 43
// 43 => 2020: (0 - Cs)*F + Cs ==> Cs*(1 - F)
c.rgb = Cs * (1.0f - Af);
#elif PS_BLEND == 44
// 44 => 2021: (0 - Cs)*F + Cd ==> Cd - Cs*F
c.rgb = Cd - Cs * Af;
#elif PS_BLEND == 45
// 45 => 2022: (0 - Cs)*F + 0 ==> 0 - Cs*F
c.rgb = - Cs * Af;
#elif PS_BLEND == 46
// 46 => 2100: (0 - Cd)*As + Cs ==> Cs - Cd*As
c.rgb = Cs - Cd * As;
#elif PS_BLEND == 47
// 47 => 2101: (0 - Cd)*As + Cd ==> Cd*(1 - As)
c.rgb = Cd * (1.0f - As);
#elif PS_BLEND == 48
// 48 => 2102: (0 - Cd)*As + 0 ==> 0 - Cd*As
c.rgb = - Cd * As;
#elif PS_BLEND == 49
// 49 => 2110: (0 - Cd)*Ad + Cs ==> Cs - Cd*Ad
c.rgb = Cs - Cd * Ad;
#elif PS_BLEND == 50
// 50 => 2111: (0 - Cd)*Ad + Cd ==> Cd*(1 - Ad)
c.rgb = Cd * (1.0f - Ad);
#elif PS_BLEND == 51
// 51 => 2112: (0 - Cd)*Ad + 0 ==> 0 - Cd*Ad
c.rgb = - Cd * Ad;
#elif PS_BLEND == 52
// 52 => 2120: (0 - Cd)*F + Cs ==> Cs - Cd*F
c.rgb = Cs - Cd * Af;
#elif PS_BLEND == 53
// 53 => 2121: (0 - Cd)*F + Cd ==> Cd*(1 - F)
c.rgb = Cd * (1.0f - Af);
#elif PS_BLEND == 54
// 54 => 2122: (0 - Cd)*F + 0 ==> 0 - Cd*F
c.rgb = - Cd * Af;
#if PS_BLEND_D == 0
vec3 D = Cs;
#elif PS_BLEND_D == 1
vec3 D = Cd;
#else
vec3 D = vec3(0.0f);
#endif
#if PS_BLEND_A == PS_BLEND_B
c.rgb = D;
#else
c.rgb = ((A - B) * C) + D;
#endif
// FIXME dithering
@ -676,8 +486,8 @@ void ps_blend(inout vec4 c, in float As)
// Don't compile => unable to find compatible overloaded function "mod(vec3)"
//c.rgb = mod((c.rgb * 255.0f) + 256.5f) / 255.0f;
}
#endif
}
void ps_main()
{
@ -758,7 +568,7 @@ void ps_main()
#endif
// Must be done before alpha correction
float alpha = c.a * 255.0f / 128.0f;
float alpha_blend = c.a * 255.0f / 128.0f;
// Correct the ALPHA value based on the output format
// FIXME add support of alpha mask to replace properly PS_AOUT
@ -786,14 +596,12 @@ void ps_main()
}
#endif
#if PS_BLEND > 0
ps_blend(c, alpha);
#endif
ps_blend(c, alpha_blend);
ps_fbmask(c);
SV_Target0 = c;
SV_Target1 = vec4(alpha, alpha, alpha, alpha);
SV_Target1 = vec4(alpha_blend);
}
#endif

View File

@ -911,6 +911,8 @@ static const char* tfx_fs_all_glsl =
"// And I say this as an ATI user.\n"
"#define ATI_SUCKS 0\n"
"\n"
"#define SW_BLEND (PS_BLEND_A || PS_BLEND_B || PS_BLEND_D)\n"
"\n"
"#ifdef FRAGMENT_SHADER\n"
"\n"
"in SHADER\n"
@ -1301,9 +1303,9 @@ static const char* tfx_fs_all_glsl =
"#endif\n"
"}\n"
"\n"
"#if PS_BLEND > 0\n"
"void ps_blend(inout vec4 c, in float As)\n"
"{\n"
"#if SW_BLEND\n"
" vec4 rt = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0);\n"
"#if PS_DFMT == FMT_24\n"
" float Ad = 1.0f;\n"
@ -1316,234 +1318,42 @@ static const char* tfx_fs_all_glsl =
" vec3 Cd = rt.rgb;\n"
" vec3 Cs = c.rgb;\n"
"\n"
"#if PS_BLEND == 1\n"
" // 1 => 0000: (Cs - Cs)*As + Cs ==> Cs\n"
" ; // nop\n"
"#if PS_BLEND_A == 0\n"
" vec3 A = Cs;\n"
"#elif PS_BLEND_A == 1\n"
" vec3 A = Cd;\n"
"#else\n"
" vec3 A = vec3(0.0f);\n"
"#endif\n"
"\n"
"#elif PS_BLEND == 2\n"
" // 2 => 0001: (Cs - Cs)*As + Cd ==> Cd\n"
" c.rgb = Cd;\n"
"#if PS_BLEND_B == 0\n"
" vec3 B = Cs;\n"
"#elif PS_BLEND_B == 1\n"
" vec3 B = Cd;\n"
"#else\n"
" vec3 B = vec3(0.0f);\n"
"#endif\n"
"\n"
"#elif PS_BLEND == 3\n"
" // 3 => 0002: (Cs - Cs)*As + 0 ==> 0\n"
" c.rgb = vec3(0.0);\n"
"#if PS_BLEND_C == 0\n"
" float C = As;\n"
"#elif PS_BLEND_C == 1\n"
" float C = Ad;\n"
"#else\n"
" float C = Af;\n"
"#endif\n"
"\n"
"#elif PS_BLEND == 4\n"
" // 4 => *0100: (Cs - Cd)*As + Cs ==> Cs*(As + 1) - Cd*As\n"
" c.rgb = Cs * (As + 1.0f) - Cd * As;\n"
"\n"
"#elif PS_BLEND == 5\n"
" // 5 => *0110: (Cs - Cd)*Ad + Cs ==> Cs*(Ad + 1) - Cd*Ad\n"
" c.rgb = Cs * (Ad + 1.0f) - Cd * Ad;\n"
"\n"
"#elif PS_BLEND == 6\n"
" // 6 => *0120: (Cs - Cd)*F + Cs ==> Cs*(F + 1) - Cd*F\n"
" c.rgb = Cs * (Af + 1.0f) - Cd * Af;\n"
"\n"
"#elif PS_BLEND == 7\n"
" // 7 => *0200: (Cs - 0)*As + Cs ==> Cs*(As + 1)\n"
" c.rgb = Cs * (As + 1.0f);\n"
"\n"
"#elif PS_BLEND == 8\n"
" // 8 => *0210: (Cs - 0)*Ad + Cs ==> Cs*(Ad + 1)\n"
" c.rgb = Cs * (Ad + 1.0f);\n"
"\n"
"#elif PS_BLEND == 9\n"
" // 9 => *0220: (Cs - 0)*F + Cs ==> Cs*(F + 1)\n"
" c.rgb = Cs * (Af + 1.0f);\n"
"\n"
"#elif PS_BLEND == 10\n"
" // 10 => *1001: (Cd - Cs)*As + Cd ==> Cd*(As + 1) - Cs*As\n"
" c.rgb = Cd * (As + 1.0f) - Cs * As;\n"
"\n"
"#elif PS_BLEND == 11\n"
" // 11 => *1011: (Cd - Cs)*Ad + Cd ==> Cd*(Ad + 1) - Cs*Ad\n"
" c.rgb = Cd * (Ad + 1.0f) - Cs * Ad;\n"
"\n"
"#elif PS_BLEND == 12\n"
" // 12 => *1021: (Cd - Cs)*F + Cd ==> Cd*(F + 1) - Cs*F\n"
" c.rgb = Cd * (Af + 1.0f) - Cs * Af;\n"
"\n"
"#elif PS_BLEND == 13\n"
" // 13 => 0101: (Cs - Cd)*As + Cd ==> Cs*As + Cd*(1 - As)\n"
" c.rgb = Cs * As + Cd * (1.0f - As);\n"
"\n"
"#elif PS_BLEND == 14\n"
" // 14 => 0102: (Cs - Cd)*As + 0 ==> Cs*As - Cd*As\n"
" c.rgb = Cs * As - Cd * As;\n"
"\n"
"#elif PS_BLEND == 15\n"
" // 15 => 0111: (Cs - Cd)*Ad + Cd ==> Cs*Ad + Cd*(1 - Ad)\n"
" c.rgb = Cs * Ad + Cd * (1.0f - Ad);\n"
"\n"
"#elif PS_BLEND == 16\n"
" // 16 => 0112: (Cs - Cd)*Ad + 0 ==> Cs*Ad - Cd*Ad\n"
" c.rgb = Cs * Ad - Cd * Ad;\n"
"\n"
"#elif PS_BLEND == 17\n"
" // 17 => 0121: (Cs - Cd)*F + Cd ==> Cs*F + Cd*(1 - F)\n"
" c.rgb = Cs * Af + Cd * (1.0f - Af);\n"
"\n"
"#elif PS_BLEND == 18\n"
" // 18 => 0122: (Cs - Cd)*F + 0 ==> Cs*F - Cd*F\n"
" c.rgb = Cs * Af - Cd * Af;\n"
"\n"
"#elif PS_BLEND == 19\n"
" // 19 => 0201: (Cs - 0)*As + Cd ==> Cs*As + Cd\n"
" c.rgb = Cs * As + Cd;\n"
"\n"
"#elif PS_BLEND == 20\n"
" // 20 => 0202: (Cs - 0)*As + 0 ==> Cs*As\n"
" c.rgb = Cs * As;\n"
"\n"
"#elif PS_BLEND == 21\n"
" // 21 => 0211: (Cs - 0)*Ad + Cd ==> Cs*Ad + Cd\n"
" c.rgb = Cs * Ad + Cd;\n"
"\n"
"#elif PS_BLEND == 22\n"
" // 22 => 0212: (Cs - 0)*Ad + 0 ==> Cs*Ad\n"
" c.rgb = Cs * Ad;\n"
"\n"
"#elif PS_BLEND == 23\n"
" // 23 => 0221: (Cs - 0)*F + Cd ==> Cs*F + Cd\n"
" c.rgb = Cs * Af + Cd;\n"
"\n"
"#elif PS_BLEND == 24\n"
" // 24 => 0222: (Cs - 0)*F + 0 ==> Cs*F\n"
" c.rgb = Cs * Af;\n"
"\n"
"#elif PS_BLEND == 25\n"
" // 25 => 1000: (Cd - Cs)*As + Cs ==> Cd*As + Cs*(1 - As)\n"
" c.rgb = Cd * As + Cs * (1.0f - As);\n"
"\n"
"#elif PS_BLEND == 26\n"
" // 26 => 1002: (Cd - Cs)*As + 0 ==> Cd*As - Cs*As\n"
" c.rgb = Cd * As - Cs * As;\n"
"\n"
"#elif PS_BLEND == 27\n"
" // 27 => 1010: (Cd - Cs)*Ad + Cs ==> Cd*Ad + Cs*(1 - Ad)\n"
" c.rgb = Cd * Ad + Cs * (1.0f - Ad);\n"
"\n"
"#elif PS_BLEND == 28\n"
" // 28 => 1012: (Cd - Cs)*Ad + 0 ==> Cd*Ad - Cs*Ad\n"
" c.rgb = Cd * Ad - Cs * Ad;\n"
"\n"
"#elif PS_BLEND == 29\n"
" // 29 => 1020: (Cd - Cs)*F + Cs ==> Cd*F + Cs*(1 - F)\n"
" c.rgb = Cd * Af + Cs * (1.0f - Af);\n"
"\n"
"#elif PS_BLEND == 30\n"
" // 30 => 1022: (Cd - Cs)*F + 0 ==> Cd*F - Cs*F\n"
" c.rgb = Cd * Af - Cs * Af;\n"
"\n"
"#elif PS_BLEND == 31\n"
" // 31 => 1200: (Cd - 0)*As + Cs ==> Cs + Cd*As\n"
" c.rgb = Cs + Cd * As;\n"
"\n"
"#elif PS_BLEND == 55\n"
" // C_CLR | 55 => #1201: (Cd - 0)*As + Cd ==> Cd*(1 + As)\n"
" c.rgb = Cd * (1.0f + As);\n"
"\n"
"#elif PS_BLEND == 32\n"
" // 32 => 1202: (Cd - 0)*As + 0 ==> Cd*As\n"
" c.rgb = Cd * As;\n"
"\n"
"#elif PS_BLEND == 33\n"
" // 33 => 1210: (Cd - 0)*Ad + Cs ==> Cs + Cd*Ad\n"
" c.rgb = Cs + Cd * Ad;\n"
"\n"
"#elif PS_BLEND == 56\n"
" // C_CLR | 56 => #1211: (Cd - 0)*Ad + Cd ==> Cd*(1 + Ad)\n"
" c.rgb = Cd * (1.0f + Ad);\n"
"\n"
"#elif PS_BLEND == 34\n"
" // 34 => 1212: (Cd - 0)*Ad + 0 ==> Cd*Ad\n"
" c.rgb = Cd * Ad;\n"
"\n"
"#elif PS_BLEND == 35\n"
" // 35 => 1220: (Cd - 0)*F + Cs ==> Cs + Cd*F\n"
" c.rgb = Cs + Cd * Af;\n"
"\n"
"#elif PS_BLEND == 57\n"
" // C_CLR | 57 => #1221: (Cd - 0)*F + Cd ==> Cd*(1 + F)\n"
" c.rgb = Cd * (1.0f + Af);\n"
"\n"
"#elif PS_BLEND == 36\n"
" // 36 => 1222: (Cd - 0)*F + 0 ==> Cd*F\n"
" c.rgb = Cd * Af;\n"
"\n"
"#elif PS_BLEND == 37\n"
" // 37 => 2000: (0 - Cs)*As + Cs ==> Cs*(1 - As)\n"
" c.rgb = Cs * (1.0f - As);\n"
"\n"
"#elif PS_BLEND == 38\n"
" // 38 => 2001: (0 - Cs)*As + Cd ==> Cd - Cs*As\n"
" c.rgb = Cd - Cs * As;\n"
"\n"
"#elif PS_BLEND == 39\n"
" // 39 => 2002: (0 - Cs)*As + 0 ==> 0 - Cs*As\n"
" c.rgb = - Cs * As;\n"
"\n"
"#elif PS_BLEND == 40\n"
" // 40 => 2010: (0 - Cs)*Ad + Cs ==> Cs*(1 - Ad)\n"
" c.rgb = Cs * (1.0f - Ad);\n"
"\n"
"#elif PS_BLEND == 41\n"
" // 41 => 2011: (0 - Cs)*Ad + Cd ==> Cd - Cs*Ad\n"
" c.rgb = Cd - Cs * Ad;\n"
"\n"
"#elif PS_BLEND == 42\n"
" // 42 => 2012: (0 - Cs)*Ad + 0 ==> 0 - Cs*Ad\n"
" c.rgb = - Cs * Ad;\n"
"\n"
"#elif PS_BLEND == 43\n"
" // 43 => 2020: (0 - Cs)*F + Cs ==> Cs*(1 - F)\n"
" c.rgb = Cs * (1.0f - Af);\n"
"\n"
"#elif PS_BLEND == 44\n"
" // 44 => 2021: (0 - Cs)*F + Cd ==> Cd - Cs*F\n"
" c.rgb = Cd - Cs * Af;\n"
"\n"
"#elif PS_BLEND == 45\n"
" // 45 => 2022: (0 - Cs)*F + 0 ==> 0 - Cs*F\n"
" c.rgb = - Cs * Af;\n"
"\n"
"#elif PS_BLEND == 46\n"
" // 46 => 2100: (0 - Cd)*As + Cs ==> Cs - Cd*As\n"
" c.rgb = Cs - Cd * As;\n"
"\n"
"#elif PS_BLEND == 47\n"
" // 47 => 2101: (0 - Cd)*As + Cd ==> Cd*(1 - As)\n"
" c.rgb = Cd * (1.0f - As);\n"
"\n"
"#elif PS_BLEND == 48\n"
" // 48 => 2102: (0 - Cd)*As + 0 ==> 0 - Cd*As\n"
" c.rgb = - Cd * As;\n"
"\n"
"#elif PS_BLEND == 49\n"
" // 49 => 2110: (0 - Cd)*Ad + Cs ==> Cs - Cd*Ad\n"
" c.rgb = Cs - Cd * Ad;\n"
"\n"
"#elif PS_BLEND == 50\n"
" // 50 => 2111: (0 - Cd)*Ad + Cd ==> Cd*(1 - Ad)\n"
" c.rgb = Cd * (1.0f - Ad);\n"
"\n"
"#elif PS_BLEND == 51\n"
" // 51 => 2112: (0 - Cd)*Ad + 0 ==> 0 - Cd*Ad\n"
" c.rgb = - Cd * Ad;\n"
"\n"
"#elif PS_BLEND == 52\n"
" // 52 => 2120: (0 - Cd)*F + Cs ==> Cs - Cd*F\n"
" c.rgb = Cs - Cd * Af;\n"
"\n"
"#elif PS_BLEND == 53\n"
" // 53 => 2121: (0 - Cd)*F + Cd ==> Cd*(1 - F)\n"
" c.rgb = Cd * (1.0f - Af);\n"
"\n"
"#elif PS_BLEND == 54\n"
" // 54 => 2122: (0 - Cd)*F + 0 ==> 0 - Cd*F\n"
" c.rgb = - Cd * Af;\n"
"#if PS_BLEND_D == 0\n"
" vec3 D = Cs;\n"
"#elif PS_BLEND_D == 1\n"
" vec3 D = Cd;\n"
"#else\n"
" vec3 D = vec3(0.0f);\n"
"#endif\n"
"\n"
"#if PS_BLEND_A == PS_BLEND_B\n"
" c.rgb = D;\n"
"#else\n"
" c.rgb = ((A - B) * C) + D;\n"
"#endif\n"
"\n"
" // FIXME dithering\n"
@ -1569,8 +1379,8 @@ static const char* tfx_fs_all_glsl =
"\n"
" // Don't compile => unable to find compatible overloaded function \"mod(vec3)\"\n"
" //c.rgb = mod((c.rgb * 255.0f) + 256.5f) / 255.0f;\n"
"}\n"
"#endif\n"
"}\n"
"\n"
"void ps_main()\n"
"{\n"
@ -1651,7 +1461,7 @@ static const char* tfx_fs_all_glsl =
"#endif\n"
"\n"
" // Must be done before alpha correction\n"
" float alpha = c.a * 255.0f / 128.0f;\n"
" float alpha_blend = c.a * 255.0f / 128.0f;\n"
"\n"
" // Correct the ALPHA value based on the output format\n"
" // FIXME add support of alpha mask to replace properly PS_AOUT\n"
@ -1679,14 +1489,12 @@ static const char* tfx_fs_all_glsl =
" }\n"
"#endif\n"
"\n"
"#if PS_BLEND > 0\n"
" ps_blend(c, alpha);\n"
"#endif\n"
" ps_blend(c, alpha_blend);\n"
"\n"
" ps_fbmask(c);\n"
"\n"
" SV_Target0 = c;\n"
" SV_Target1 = vec4(alpha, alpha, alpha, alpha);\n"
" SV_Target1 = vec4(alpha_blend);\n"
"}\n"
"\n"
"#endif\n"