glsl: replace runtime condition by preprocessor condition

It might be an easier work for the compiler

I didn't replace all occurences to keep readability
This commit is contained in:
Gregory Hainaut 2015-04-24 17:51:29 +02:00
parent 4bb8d15228
commit 56836561f4
2 changed files with 242 additions and 356 deletions

View File

@ -121,15 +121,14 @@ layout(location = 1) subroutine uniform ColClipType colclip;
vec4 sample_c(vec2 uv)
{
// FIXME: check the issue on openGL
if (ATI_SUCKS == 1 && PS_POINT_SAMPLER == 1)
{
// Weird issue with ATI cards (happens on at least HD 4xxx and 5xxx),
// it looks like they add 127/128 of a texel to sampling coordinates
// occasionally causing point sampling to erroneously round up.
// I'm manually adjusting coordinates to the centre of texels here,
// though the centre is just paranoia, the top left corner works fine.
uv = (trunc(uv * WH.zw) + vec2(0.5, 0.5)) / WH.zw;
}
#if (ATI_SUCKS == 1) && (PS_POINT_SAMPLER == 1)
// Weird issue with ATI cards (happens on at least HD 4xxx and 5xxx),
// it looks like they add 127/128 of a texel to sampling coordinates
// occasionally causing point sampling to erroneously round up.
// I'm manually adjusting coordinates to the centre of texels here,
// though the centre is just paranoia, the top left corner works fine.
uv = (trunc(uv * WH.zw) + vec2(0.5, 0.5)) / WH.zw;
#endif
return texture(TextureSampler, uv);
}
@ -145,36 +144,33 @@ vec4 wrapuv(vec4 uv)
{
vec4 uv_out = uv;
if(PS_WMS == PS_WMT)
{
if(PS_WMS == 2)
{
uv_out = clamp(uv, MinMax.xyxy, MinMax.zwzw);
}
else if(PS_WMS == 3)
{
uv_out = vec4((ivec4(uv * WH.xyxy) & ivec4(MskFix.xyxy)) | ivec4(MskFix.zwzw)) / WH.xyxy;
}
}
else
{
if(PS_WMS == 2)
{
uv_out.xz = clamp(uv.xz, MinMax.xx, MinMax.zz);
}
else if(PS_WMS == 3)
{
uv_out.xz = vec2((ivec2(uv.xz * WH.xx) & ivec2(MskFix.xx)) | ivec2(MskFix.zz)) / WH.xx;
}
if(PS_WMT == 2)
{
uv_out.yw = clamp(uv.yw, MinMax.yy, MinMax.ww);
}
else if(PS_WMT == 3)
{
uv_out.yw = vec2((ivec2(uv.yw * WH.yy) & ivec2(MskFix.yy)) | ivec2(MskFix.ww)) / WH.yy;
}
}
#if PS_WMS == PS_WMT
#if PS_WMS == 2
uv_out = clamp(uv, MinMax.xyxy, MinMax.zwzw);
#elif PS_WMS == 3
uv_out = vec4((ivec4(uv * WH.xyxy) & ivec4(MskFix.xyxy)) | ivec4(MskFix.zwzw)) / WH.xyxy;
#endif
#else // PS_WMS != PS_WMT
#if PS_WMS == 2
uv_out.xz = clamp(uv.xz, MinMax.xx, MinMax.zz);
#elif PS_WMS == 3
uv_out.xz = vec2((ivec2(uv.xz * WH.xx) & ivec2(MskFix.xx)) | ivec2(MskFix.zz)) / WH.xx;
#endif
#if PS_WMT == 2
uv_out.yw = clamp(uv.yw, MinMax.yy, MinMax.ww);
#elif PS_WMT == 3
uv_out.yw = vec2((ivec2(uv.yw * WH.yy) & ivec2(MskFix.yy)) | ivec2(MskFix.ww)) / WH.yy;
#endif
#endif
return uv_out;
}
@ -183,18 +179,13 @@ vec2 clampuv(vec2 uv)
{
vec2 uv_out = uv;
if(PS_WMS == 2 && PS_WMT == 2)
{
uv_out = clamp(uv, MinF, MinMax.zw);
}
else if(PS_WMS == 2)
{
uv_out.x = clamp(uv.x, MinF.x, MinMax.z);
}
else if(PS_WMT == 2)
{
uv_out.y = clamp(uv.y, MinF.y, MinMax.w);
}
#if (PS_WMS == 2) && (PS_WMT == 2)
uv_out = clamp(uv, MinF, MinMax.zw);
#elif PS_WMS == 2
uv_out.x = clamp(uv.x, MinF.x, MinMax.z);
#elif PS_WMT == 2
uv_out.y = clamp(uv.y, MinF.y, MinMax.w);
#endif
return uv_out;
}
@ -239,23 +230,25 @@ mat4 sample_4p(vec4 u)
vec4 sample_color(vec2 st, float q)
{
if(PS_FST == 0) st /= q;
#if (PS_FST == 0)
st /= q;
#endif
if(PS_TCOFFSETHACK == 1) st += TC_OffsetHack.xy;
#if (PS_TCOFFSETHACK == 1)
st += TC_OffsetHack.xy;
#endif
vec4 t;
mat4 c;
vec2 dd;
if (PS_LTF == 0 && PS_FMT <= FMT_16 && PS_WMS < 3 && PS_WMT < 3)
{
#if (PS_LTF == 0 && PS_FMT <= FMT_16 && PS_WMS < 3 && PS_WMT < 3)
c[0] = sample_c(clampuv(st));
#ifdef TEX_COORD_DEBUG
c[0].rg = clampuv(st).xy;
#endif
}
else
{
#else
vec4 uv;
if(PS_LTF != 0)
@ -284,33 +277,26 @@ vec4 sample_color(vec2 st, float q)
c[2].rg = uv.xy;
c[3].rg = uv.xy;
#endif
}
#endif
// PERF: see the impact of the exansion before/after the interpolation
for (int i = 0; i < 4; i++)
{
if((PS_FMT & ~FMT_PAL) == FMT_24)
{
// FIXME GLSL any only support bvec so try to mix it with notEqual
bvec3 rgb_check = notEqual( c[i].rgb, vec3(0.0f, 0.0f, 0.0f) );
c[i].a = ( (PS_AEM == 0) || any(rgb_check) ) ? TA.x : 0.0f;
}
else if((PS_FMT & ~FMT_PAL) == FMT_16)
{
// FIXME GLSL any only support bvec so try to mix it with notEqual
bvec3 rgb_check = notEqual( c[i].rgb, vec3(0.0f, 0.0f, 0.0f) );
c[i].a = c[i].a >= 0.5 ? TA.y : ( (PS_AEM == 0) || any(rgb_check) ) ? TA.x : 0.0f;
}
// FIXME GLSL any only support bvec so try to mix it with notEqual
bvec3 rgb_check = notEqual( c[i].rgb, vec3(0.0f, 0.0f, 0.0f) );
#if ((PS_FMT & ~FMT_PAL) == FMT_24)
c[i].a = ( (PS_AEM == 0) || any(rgb_check) ) ? TA.x : 0.0f;
#elif ((PS_FMT & ~FMT_PAL) == FMT_16)
c[i].a = c[i].a >= 0.5 ? TA.y : ( (PS_AEM == 0) || any(rgb_check) ) ? TA.x : 0.0f;
#endif
}
if(PS_LTF != 0)
{
t = mix(mix(c[0], c[1], dd.x), mix(c[2], c[3], dd.x), dd.y);
}
else
{
t = c[0];
}
#if(PS_LTF != 0)
t = mix(mix(c[0], c[1], dd.x), mix(c[2], c[3], dd.x), dd.y);
#else
t = c[0];
#endif
return t;
}
@ -319,46 +305,27 @@ vec4 sample_color(vec2 st, float q)
vec4 tfx(vec4 t, vec4 c)
{
vec4 c_out = c;
if(PS_TFX == 0)
{
if(PS_TCC != 0)
{
c_out = c * t * 255.0f / 128.0f;
}
else
{
c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f;
}
}
else if(PS_TFX == 1)
{
if(PS_TCC != 0)
{
c_out = t;
}
else
{
c_out.rgb = t.rgb;
}
}
else if(PS_TFX == 2)
{
c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a;
#if (PS_TFX == 0)
if(PS_TCC != 0)
c_out = c * t * 255.0f / 128.0f;
else
c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f;
#elif (PS_TFX == 1)
if(PS_TCC != 0)
c_out = t;
else
c_out.rgb = t.rgb;
#elif (PS_TFX == 2)
c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a;
if(PS_TCC != 0)
{
c_out.a += t.a;
}
}
else if(PS_TFX == 3)
{
c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a;
if(PS_TCC != 0)
c_out.a += t.a;
#elif (PS_TFX == 3)
c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a;
if(PS_TCC != 0)
{
c_out.a = t.a;
}
}
if(PS_TCC != 0)
c_out.a = t.a;
#endif
return c_out;
}
@ -369,45 +336,29 @@ void atst(vec4 c)
{
float a = trunc(c.a * 255.0 + 0.01);
if(PS_ATST == 0) // never
{
#if (PS_ATST == 0) // never
discard;
#elif (PS_ATST == 1) // always
// nothing to do
#elif (PS_ATST == 2) && (PS_SPRITEHACK == 0) // l
if ((AREF - a - 0.5f) < 0.0f)
discard;
}
else if(PS_ATST == 1) // always
{
// nothing to do
}
else if(PS_ATST == 2 ) // l
{
if (PS_SPRITEHACK == 0)
if ((AREF - a - 0.5f) < 0.0f)
discard;
}
else if(PS_ATST == 3 ) // le
{
if ((AREF - a + 0.5f) < 0.0f)
discard;
}
else if(PS_ATST == 4) // e
{
if ((0.5f - abs(a - AREF)) < 0.0f)
discard;
}
else if(PS_ATST == 5) // ge
{
if ((a-AREF + 0.5f) < 0.0f)
discard;
}
else if(PS_ATST == 6) // g
{
if ((a-AREF - 0.5f) < 0.0f)
discard;
}
else if(PS_ATST == 7) // ne
{
if ((abs(a - AREF) - 0.5f) < 0.0f)
discard;
}
#elif (PS_ATST == 3 ) // le
if ((AREF - a + 0.5f) < 0.0f)
discard;
#elif (PS_ATST == 4) // e
if ((0.5f - abs(a - AREF)) < 0.0f)
discard;
#elif (PS_ATST == 5) // ge
if ((a-AREF + 0.5f) < 0.0f)
discard;
#elif (PS_ATST == 6) // g
if ((a-AREF - 0.5f) < 0.0f)
discard;
#elif (PS_ATST == 7) // ne
if ((abs(a - AREF) - 0.5f) < 0.0f)
discard;
#endif
}
#endif
@ -415,26 +366,22 @@ void atst(vec4 c)
#ifndef SUBROUTINE_GL40
void colclip(inout vec4 c)
{
if (PS_COLCLIP == 2)
{
#if (PS_COLCLIP == 2)
c.rgb = 256.0f/255.0f - c.rgb;
}
if (PS_COLCLIP > 0)
{
#elif (PS_COLCLIP > 0)
// FIXME !!!!
//c.rgb *= c.rgb < 128./255;
bvec3 factor = bvec3(128.0f/255.0f, 128.0f/255.0f, 128.0f/255.0f);
c.rgb *= vec3(factor);
}
#endif
}
#endif
void fog(inout vec4 c, float f)
{
if(PS_FOG != 0)
{
c.rgb = mix(FogColor, c.rgb, f);
}
#if PS_FOG != 0
c.rgb = mix(FogColor, c.rgb, f);
#endif
}
vec4 ps_color()
@ -473,10 +420,9 @@ vec4 ps_color()
colclip(c);
if(PS_CLR1 != 0) // needed for Cd * (As/Ad/F + 1) blending modes
{
c.rgb = vec3(1.0f, 1.0f, 1.0f);
}
#if (PS_CLR1 != 0) // needed for Cd * (As/Ad/F + 1) blending modes
c.rgb = vec3(1.0f, 1.0f, 1.0f);
#endif
return c;
}
@ -519,16 +465,13 @@ void ps_main()
float alpha = c.a * 2.0;
if(PS_AOUT != 0) // 16 bit output
{
float a = 128.0f / 255.0; // alpha output will be 0x80
#if (PS_AOUT != 0) // 16 bit output
float a = 128.0f / 255.0; // alpha output will be 0x80
c.a = (PS_FBA != 0) ? a : step(0.5, c.a) * a;
}
else if(PS_FBA != 0)
{
if(c.a < 0.5) c.a += 0.5;
}
c.a = (PS_FBA != 0) ? a : step(0.5, c.a) * a;
#elif (PS_FBA != 0)
if(c.a < 0.5) c.a += 0.5;
#endif
// Get first primitive that will write a failling alpha value
#if PS_DATE == 1 && !defined(DISABLE_GL42_image)

View File

@ -872,15 +872,14 @@ static const char* tfx_fs_all_glsl =
"vec4 sample_c(vec2 uv)\n"
"{\n"
" // FIXME: check the issue on openGL\n"
" if (ATI_SUCKS == 1 && PS_POINT_SAMPLER == 1)\n"
" {\n"
" // Weird issue with ATI cards (happens on at least HD 4xxx and 5xxx),\n"
" // it looks like they add 127/128 of a texel to sampling coordinates\n"
" // occasionally causing point sampling to erroneously round up.\n"
" // I'm manually adjusting coordinates to the centre of texels here,\n"
" // though the centre is just paranoia, the top left corner works fine.\n"
" uv = (trunc(uv * WH.zw) + vec2(0.5, 0.5)) / WH.zw;\n"
" }\n"
"#if (ATI_SUCKS == 1) && (PS_POINT_SAMPLER == 1)\n"
" // Weird issue with ATI cards (happens on at least HD 4xxx and 5xxx),\n"
" // it looks like they add 127/128 of a texel to sampling coordinates\n"
" // occasionally causing point sampling to erroneously round up.\n"
" // I'm manually adjusting coordinates to the centre of texels here,\n"
" // though the centre is just paranoia, the top left corner works fine.\n"
" uv = (trunc(uv * WH.zw) + vec2(0.5, 0.5)) / WH.zw;\n"
"#endif\n"
"\n"
" return texture(TextureSampler, uv);\n"
"}\n"
@ -896,36 +895,33 @@ static const char* tfx_fs_all_glsl =
"{\n"
" vec4 uv_out = uv;\n"
"\n"
" if(PS_WMS == PS_WMT)\n"
" {\n"
" if(PS_WMS == 2)\n"
" {\n"
" uv_out = clamp(uv, MinMax.xyxy, MinMax.zwzw);\n"
" }\n"
" else if(PS_WMS == 3)\n"
" {\n"
" uv_out = vec4((ivec4(uv * WH.xyxy) & ivec4(MskFix.xyxy)) | ivec4(MskFix.zwzw)) / WH.xyxy;\n"
" }\n"
" }\n"
" else\n"
" {\n"
" if(PS_WMS == 2)\n"
" {\n"
" uv_out.xz = clamp(uv.xz, MinMax.xx, MinMax.zz);\n"
" }\n"
" else if(PS_WMS == 3)\n"
" {\n"
" uv_out.xz = vec2((ivec2(uv.xz * WH.xx) & ivec2(MskFix.xx)) | ivec2(MskFix.zz)) / WH.xx;\n"
" }\n"
" if(PS_WMT == 2)\n"
" {\n"
" uv_out.yw = clamp(uv.yw, MinMax.yy, MinMax.ww);\n"
" }\n"
" else if(PS_WMT == 3)\n"
" {\n"
" uv_out.yw = vec2((ivec2(uv.yw * WH.yy) & ivec2(MskFix.yy)) | ivec2(MskFix.ww)) / WH.yy;\n"
" }\n"
" }\n"
"#if PS_WMS == PS_WMT\n"
"\n"
"#if PS_WMS == 2\n"
" uv_out = clamp(uv, MinMax.xyxy, MinMax.zwzw);\n"
"#elif PS_WMS == 3\n"
" uv_out = vec4((ivec4(uv * WH.xyxy) & ivec4(MskFix.xyxy)) | ivec4(MskFix.zwzw)) / WH.xyxy;\n"
"#endif\n"
"\n"
"#else // PS_WMS != PS_WMT\n"
"\n"
"#if PS_WMS == 2\n"
" uv_out.xz = clamp(uv.xz, MinMax.xx, MinMax.zz);\n"
"\n"
"#elif PS_WMS == 3\n"
" uv_out.xz = vec2((ivec2(uv.xz * WH.xx) & ivec2(MskFix.xx)) | ivec2(MskFix.zz)) / WH.xx;\n"
"\n"
"#endif\n"
"\n"
"#if PS_WMT == 2\n"
" uv_out.yw = clamp(uv.yw, MinMax.yy, MinMax.ww);\n"
"\n"
"#elif PS_WMT == 3\n"
"\n"
" uv_out.yw = vec2((ivec2(uv.yw * WH.yy) & ivec2(MskFix.yy)) | ivec2(MskFix.ww)) / WH.yy;\n"
"#endif\n"
"\n"
"#endif\n"
"\n"
" return uv_out;\n"
"}\n"
@ -934,18 +930,13 @@ static const char* tfx_fs_all_glsl =
"{\n"
" vec2 uv_out = uv;\n"
"\n"
" if(PS_WMS == 2 && PS_WMT == 2) \n"
" {\n"
" uv_out = clamp(uv, MinF, MinMax.zw);\n"
" }\n"
" else if(PS_WMS == 2)\n"
" {\n"
" uv_out.x = clamp(uv.x, MinF.x, MinMax.z);\n"
" }\n"
" else if(PS_WMT == 2)\n"
" {\n"
" uv_out.y = clamp(uv.y, MinF.y, MinMax.w);\n"
" }\n"
"#if (PS_WMS == 2) && (PS_WMT == 2) \n"
" uv_out = clamp(uv, MinF, MinMax.zw);\n"
"#elif PS_WMS == 2\n"
" uv_out.x = clamp(uv.x, MinF.x, MinMax.z);\n"
"#elif PS_WMT == 2\n"
" uv_out.y = clamp(uv.y, MinF.y, MinMax.w);\n"
"#endif\n"
"\n"
" return uv_out;\n"
"}\n"
@ -990,23 +981,25 @@ static const char* tfx_fs_all_glsl =
"\n"
"vec4 sample_color(vec2 st, float q)\n"
"{\n"
" if(PS_FST == 0) st /= q;\n"
"#if (PS_FST == 0)\n"
" st /= q;\n"
"#endif\n"
"\n"
" if(PS_TCOFFSETHACK == 1) st += TC_OffsetHack.xy;\n"
"#if (PS_TCOFFSETHACK == 1)\n"
" st += TC_OffsetHack.xy;\n"
"#endif\n"
"\n"
" vec4 t;\n"
" mat4 c;\n"
" vec2 dd;\n"
"\n"
" if (PS_LTF == 0 && PS_FMT <= FMT_16 && PS_WMS < 3 && PS_WMT < 3)\n"
" {\n"
"#if (PS_LTF == 0 && PS_FMT <= FMT_16 && PS_WMS < 3 && PS_WMT < 3)\n"
" c[0] = sample_c(clampuv(st));\n"
"#ifdef TEX_COORD_DEBUG\n"
" c[0].rg = clampuv(st).xy;\n"
"#endif\n"
" }\n"
" else\n"
" {\n"
"\n"
"#else\n"
" vec4 uv;\n"
"\n"
" if(PS_LTF != 0)\n"
@ -1035,33 +1028,26 @@ static const char* tfx_fs_all_glsl =
" c[2].rg = uv.xy;\n"
" c[3].rg = uv.xy;\n"
"#endif\n"
" }\n"
"\n"
"#endif\n"
"\n"
" // PERF: see the impact of the exansion before/after the interpolation\n"
" for (int i = 0; i < 4; i++)\n"
" {\n"
" if((PS_FMT & ~FMT_PAL) == FMT_24)\n"
" {\n"
" // FIXME GLSL any only support bvec so try to mix it with notEqual\n"
" bvec3 rgb_check = notEqual( c[i].rgb, vec3(0.0f, 0.0f, 0.0f) );\n"
" c[i].a = ( (PS_AEM == 0) || any(rgb_check) ) ? TA.x : 0.0f;\n"
" }\n"
" else if((PS_FMT & ~FMT_PAL) == FMT_16)\n"
" {\n"
" // FIXME GLSL any only support bvec so try to mix it with notEqual\n"
" bvec3 rgb_check = notEqual( c[i].rgb, vec3(0.0f, 0.0f, 0.0f) );\n"
" c[i].a = c[i].a >= 0.5 ? TA.y : ( (PS_AEM == 0) || any(rgb_check) ) ? TA.x : 0.0f;\n"
" }\n"
" // FIXME GLSL any only support bvec so try to mix it with notEqual\n"
" bvec3 rgb_check = notEqual( c[i].rgb, vec3(0.0f, 0.0f, 0.0f) );\n"
"#if ((PS_FMT & ~FMT_PAL) == FMT_24)\n"
" c[i].a = ( (PS_AEM == 0) || any(rgb_check) ) ? TA.x : 0.0f;\n"
"#elif ((PS_FMT & ~FMT_PAL) == FMT_16)\n"
" c[i].a = c[i].a >= 0.5 ? TA.y : ( (PS_AEM == 0) || any(rgb_check) ) ? TA.x : 0.0f;\n"
"#endif\n"
" }\n"
"\n"
" if(PS_LTF != 0)\n"
" {\n"
" t = mix(mix(c[0], c[1], dd.x), mix(c[2], c[3], dd.x), dd.y);\n"
" }\n"
" else\n"
" {\n"
" t = c[0];\n"
" }\n"
"#if(PS_LTF != 0)\n"
" t = mix(mix(c[0], c[1], dd.x), mix(c[2], c[3], dd.x), dd.y);\n"
"#else\n"
" t = c[0];\n"
"#endif\n"
"\n"
" return t;\n"
"}\n"
@ -1070,46 +1056,27 @@ static const char* tfx_fs_all_glsl =
"vec4 tfx(vec4 t, vec4 c)\n"
"{\n"
" vec4 c_out = c;\n"
" if(PS_TFX == 0)\n"
" {\n"
" if(PS_TCC != 0) \n"
" {\n"
" c_out = c * t * 255.0f / 128.0f;\n"
" }\n"
" else\n"
" {\n"
" c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f;\n"
" }\n"
" }\n"
" else if(PS_TFX == 1)\n"
" {\n"
" if(PS_TCC != 0) \n"
" {\n"
" c_out = t;\n"
" }\n"
" else\n"
" {\n"
" c_out.rgb = t.rgb;\n"
" }\n"
" }\n"
" else if(PS_TFX == 2)\n"
" {\n"
" c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a;\n"
"#if (PS_TFX == 0)\n"
" if(PS_TCC != 0) \n"
" c_out = c * t * 255.0f / 128.0f;\n"
" else\n"
" c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f;\n"
"#elif (PS_TFX == 1)\n"
" if(PS_TCC != 0) \n"
" c_out = t;\n"
" else\n"
" c_out.rgb = t.rgb;\n"
"#elif (PS_TFX == 2)\n"
" c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a;\n"
"\n"
" if(PS_TCC != 0) \n"
" {\n"
" c_out.a += t.a;\n"
" }\n"
" }\n"
" else if(PS_TFX == 3)\n"
" {\n"
" c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a;\n"
" if(PS_TCC != 0) \n"
" c_out.a += t.a;\n"
"#elif (PS_TFX == 3)\n"
" c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a;\n"
"\n"
" if(PS_TCC != 0) \n"
" {\n"
" c_out.a = t.a;\n"
" }\n"
" }\n"
" if(PS_TCC != 0) \n"
" c_out.a = t.a;\n"
"#endif\n"
"\n"
" return c_out;\n"
"}\n"
@ -1120,45 +1087,29 @@ static const char* tfx_fs_all_glsl =
"{\n"
" float a = trunc(c.a * 255.0 + 0.01);\n"
"\n"
" if(PS_ATST == 0) // never\n"
" {\n"
"#if (PS_ATST == 0) // never\n"
" discard;\n"
"#elif (PS_ATST == 1) // always\n"
" // nothing to do\n"
"#elif (PS_ATST == 2) && (PS_SPRITEHACK == 0) // l\n"
" if ((AREF - a - 0.5f) < 0.0f)\n"
" discard;\n"
" }\n"
" else if(PS_ATST == 1) // always\n"
" {\n"
" // nothing to do\n"
" }\n"
" else if(PS_ATST == 2 ) // l\n"
" {\n"
" if (PS_SPRITEHACK == 0)\n"
" if ((AREF - a - 0.5f) < 0.0f)\n"
" discard;\n"
" }\n"
" else if(PS_ATST == 3 ) // le\n"
" {\n"
" if ((AREF - a + 0.5f) < 0.0f)\n"
" discard;\n"
" }\n"
" else if(PS_ATST == 4) // e\n"
" {\n"
" if ((0.5f - abs(a - AREF)) < 0.0f)\n"
" discard;\n"
" }\n"
" else if(PS_ATST == 5) // ge\n"
" {\n"
" if ((a-AREF + 0.5f) < 0.0f)\n"
" discard;\n"
" }\n"
" else if(PS_ATST == 6) // g\n"
" {\n"
" if ((a-AREF - 0.5f) < 0.0f)\n"
" discard;\n"
" }\n"
" else if(PS_ATST == 7) // ne\n"
" {\n"
" if ((abs(a - AREF) - 0.5f) < 0.0f)\n"
" discard;\n"
" }\n"
"#elif (PS_ATST == 3 ) // le\n"
" if ((AREF - a + 0.5f) < 0.0f)\n"
" discard;\n"
"#elif (PS_ATST == 4) // e\n"
" if ((0.5f - abs(a - AREF)) < 0.0f)\n"
" discard;\n"
"#elif (PS_ATST == 5) // ge\n"
" if ((a-AREF + 0.5f) < 0.0f)\n"
" discard;\n"
"#elif (PS_ATST == 6) // g\n"
" if ((a-AREF - 0.5f) < 0.0f)\n"
" discard;\n"
"#elif (PS_ATST == 7) // ne\n"
" if ((abs(a - AREF) - 0.5f) < 0.0f)\n"
" discard;\n"
"#endif\n"
"}\n"
"#endif\n"
"\n"
@ -1166,26 +1117,22 @@ static const char* tfx_fs_all_glsl =
"#ifndef SUBROUTINE_GL40\n"
"void colclip(inout vec4 c)\n"
"{\n"
" if (PS_COLCLIP == 2)\n"
" {\n"
"#if (PS_COLCLIP == 2)\n"
" c.rgb = 256.0f/255.0f - c.rgb;\n"
" }\n"
" if (PS_COLCLIP > 0)\n"
" {\n"
"#elif (PS_COLCLIP > 0)\n"
" // FIXME !!!!\n"
" //c.rgb *= c.rgb < 128./255;\n"
" bvec3 factor = bvec3(128.0f/255.0f, 128.0f/255.0f, 128.0f/255.0f);\n"
" c.rgb *= vec3(factor);\n"
" }\n"
"#endif\n"
"}\n"
"#endif\n"
"\n"
"void fog(inout vec4 c, float f)\n"
"{\n"
" if(PS_FOG != 0)\n"
" {\n"
" c.rgb = mix(FogColor, c.rgb, f);\n"
" }\n"
"#if PS_FOG != 0\n"
" c.rgb = mix(FogColor, c.rgb, f);\n"
"#endif\n"
"}\n"
"\n"
"vec4 ps_color()\n"
@ -1224,10 +1171,9 @@ static const char* tfx_fs_all_glsl =
"\n"
" colclip(c);\n"
"\n"
" if(PS_CLR1 != 0) // needed for Cd * (As/Ad/F + 1) blending modes\n"
" {\n"
" c.rgb = vec3(1.0f, 1.0f, 1.0f); \n"
" }\n"
"#if (PS_CLR1 != 0) // needed for Cd * (As/Ad/F + 1) blending modes\n"
" c.rgb = vec3(1.0f, 1.0f, 1.0f); \n"
"#endif\n"
"\n"
" return c;\n"
"}\n"
@ -1270,16 +1216,13 @@ static const char* tfx_fs_all_glsl =
"\n"
" float alpha = c.a * 2.0;\n"
"\n"
" if(PS_AOUT != 0) // 16 bit output\n"
" {\n"
" float a = 128.0f / 255.0; // alpha output will be 0x80\n"
"#if (PS_AOUT != 0) // 16 bit output\n"
" float a = 128.0f / 255.0; // alpha output will be 0x80\n"
"\n"
" c.a = (PS_FBA != 0) ? a : step(0.5, c.a) * a;\n"
" }\n"
" else if(PS_FBA != 0)\n"
" {\n"
" if(c.a < 0.5) c.a += 0.5;\n"
" }\n"
" c.a = (PS_FBA != 0) ? a : step(0.5, c.a) * a;\n"
"#elif (PS_FBA != 0)\n"
" if(c.a < 0.5) c.a += 0.5;\n"
"#endif\n"
"\n"
" // Get first primitive that will write a failling alpha value\n"
"#if PS_DATE == 1 && !defined(DISABLE_GL42_image)\n"