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