glsl: format white space + comment

This commit is contained in:
Gregory Hainaut 2015-04-25 12:46:59 +02:00
parent 757726bb91
commit 15ae9996bb
2 changed files with 386 additions and 390 deletions

View File

@ -45,13 +45,13 @@
in SHADER in SHADER
{ {
vec4 t; vec4 t;
vec4 c; vec4 c;
flat vec4 fc; flat vec4 fc;
#if PS_SPRITE == 1 #if PS_SPRITE == 1
flat vec4 flat_T; flat vec4 flat_T;
flat vec2 flat_P; flat vec2 flat_P;
vec2 alpha; vec2 alpha;
#endif #endif
} PSin; } PSin;
@ -80,30 +80,26 @@ layout(binding = 3) uniform sampler2D RtSampler; // note 2 already use by the im
#if PS_DATE > 0 #if PS_DATE > 0
// FIXME how to declare memory access // FIXME how to declare memory access
layout(r32i, binding = 2) coherent uniform iimage2D img_prim_min; layout(r32i, binding = 2) coherent uniform iimage2D img_prim_min;
layout(early_fragment_tests) in;
// origin_upper_left
layout(pixel_center_integer) in vec4 gl_FragCoord;
#endif #endif
#else #else
// use basic stencil // use basic stencil
#endif #endif
#ifndef DISABLE_GL42_image
#if PS_DATE > 0
// origin_upper_left
layout(pixel_center_integer) in vec4 gl_FragCoord;
//in int gl_PrimitiveID;
#endif
#endif
layout(std140, binding = 21) uniform cb21 layout(std140, binding = 21) uniform cb21
{ {
vec3 FogColor; vec3 FogColor;
float AREF; float AREF;
vec4 WH; vec4 WH;
vec2 MinF; vec2 MinF;
vec2 TA; vec2 TA;
uvec4 MskFix; uvec4 MskFix;
vec4 HalfTexel; vec4 HalfTexel;
vec4 MinMax; vec4 MinMax;
vec4 TC_OffsetHack; vec4 TC_OffsetHack;
}; };
#ifdef SUBROUTINE_GL40 #ifdef SUBROUTINE_GL40
@ -121,242 +117,242 @@ 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 #endif
return texture(TextureSampler, uv); return texture(TextureSampler, uv);
} }
vec4 sample_p(float u) vec4 sample_p(float u)
{ {
//FIXME do we need a 1D sampler. Big impact on opengl to find 1 dim //FIXME do we need a 1D sampler. Big impact on opengl to find 1 dim
// So for the moment cheat with 0.0f dunno if it work // So for the moment cheat with 0.0f dunno if it work
return texture(PaletteSampler, vec2(u, 0.0f)); return texture(PaletteSampler, vec2(u, 0.0f));
} }
vec4 wrapuv(vec4 uv) 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 #elif PS_WMS == 3
uv_out = vec4((ivec4(uv * WH.xyxy) & ivec4(MskFix.xyxy)) | ivec4(MskFix.zwzw)) / WH.xyxy; uv_out = vec4((ivec4(uv * WH.xyxy) & ivec4(MskFix.xyxy)) | ivec4(MskFix.zwzw)) / WH.xyxy;
#endif #endif
#else // PS_WMS != PS_WMT #else // PS_WMS != PS_WMT
#if PS_WMS == 2 #if PS_WMS == 2
uv_out.xz = clamp(uv.xz, MinMax.xx, MinMax.zz); uv_out.xz = clamp(uv.xz, MinMax.xx, MinMax.zz);
#elif PS_WMS == 3 #elif PS_WMS == 3
uv_out.xz = vec2((ivec2(uv.xz * WH.xx) & ivec2(MskFix.xx)) | ivec2(MskFix.zz)) / WH.xx; uv_out.xz = vec2((ivec2(uv.xz * WH.xx) & ivec2(MskFix.xx)) | ivec2(MskFix.zz)) / WH.xx;
#endif #endif
#if PS_WMT == 2 #if PS_WMT == 2
uv_out.yw = clamp(uv.yw, MinMax.yy, MinMax.ww); uv_out.yw = clamp(uv.yw, MinMax.yy, MinMax.ww);
#elif PS_WMT == 3 #elif PS_WMT == 3
uv_out.yw = vec2((ivec2(uv.yw * WH.yy) & ivec2(MskFix.yy)) | ivec2(MskFix.ww)) / WH.yy; uv_out.yw = vec2((ivec2(uv.yw * WH.yy) & ivec2(MskFix.yy)) | ivec2(MskFix.ww)) / WH.yy;
#endif #endif
#endif #endif
return uv_out; return uv_out;
} }
vec2 clampuv(vec2 uv) 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 #elif PS_WMS == 2
uv_out.x = clamp(uv.x, MinF.x, MinMax.z); uv_out.x = clamp(uv.x, MinF.x, MinMax.z);
#elif PS_WMT == 2 #elif PS_WMT == 2
uv_out.y = clamp(uv.y, MinF.y, MinMax.w); uv_out.y = clamp(uv.y, MinF.y, MinMax.w);
#endif #endif
return uv_out; return uv_out;
} }
mat4 sample_4c(vec4 uv) mat4 sample_4c(vec4 uv)
{ {
mat4 c; mat4 c;
c[0] = sample_c(uv.xy); c[0] = sample_c(uv.xy);
c[1] = sample_c(uv.zy); c[1] = sample_c(uv.zy);
c[2] = sample_c(uv.xw); c[2] = sample_c(uv.xw);
c[3] = sample_c(uv.zw); c[3] = sample_c(uv.zw);
return c; return c;
} }
vec4 sample_4a(vec4 uv) vec4 sample_4a(vec4 uv)
{ {
vec4 c; vec4 c;
// Dx used the alpha channel. // Dx used the alpha channel.
// Opengl is only 8 bits on red channel. // Opengl is only 8 bits on red channel.
c.x = sample_c(uv.xy).r; c.x = sample_c(uv.xy).r;
c.y = sample_c(uv.zy).r; c.y = sample_c(uv.zy).r;
c.z = sample_c(uv.xw).r; c.z = sample_c(uv.xw).r;
c.w = sample_c(uv.zw).r; c.w = sample_c(uv.zw).r;
return c * 255.0/256.0 + 0.5/256.0; return c * 255.0/256.0 + 0.5/256.0;
} }
mat4 sample_4p(vec4 u) mat4 sample_4p(vec4 u)
{ {
mat4 c; mat4 c;
c[0] = sample_p(u.x); c[0] = sample_p(u.x);
c[1] = sample_p(u.y); c[1] = sample_p(u.y);
c[2] = sample_p(u.z); c[2] = sample_p(u.z);
c[3] = sample_p(u.w); c[3] = sample_p(u.w);
return c; return c;
} }
vec4 sample_color(vec2 st, float q) vec4 sample_color(vec2 st, float q)
{ {
#if (PS_FST == 0) #if (PS_FST == 0)
st /= q; st /= q;
#endif #endif
#if (PS_TCOFFSETHACK == 1) #if (PS_TCOFFSETHACK == 1)
st += TC_OffsetHack.xy; st += TC_OffsetHack.xy;
#endif #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)
{ {
uv = st.xyxy + HalfTexel; uv = st.xyxy + HalfTexel;
dd = fract(uv.xy * WH.zw); dd = fract(uv.xy * WH.zw);
} }
else else
{ {
uv = st.xyxy; uv = st.xyxy;
} }
uv = wrapuv(uv); uv = wrapuv(uv);
if((PS_FMT & FMT_PAL) != 0) if((PS_FMT & FMT_PAL) != 0)
{ {
c = sample_4p(sample_4a(uv)); c = sample_4p(sample_4a(uv));
} }
else else
{ {
c = sample_4c(uv); c = sample_4c(uv);
} }
#ifdef TEX_COORD_DEBUG #ifdef TEX_COORD_DEBUG
c[0].rg = uv.xy; c[0].rg = uv.xy;
c[1].rg = uv.xy; c[1].rg = uv.xy;
c[2].rg = uv.xy; c[2].rg = uv.xy;
c[3].rg = uv.xy; c[3].rg = uv.xy;
#endif #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) #if ((PS_FMT & ~FMT_PAL) == FMT_24)
c[i].a = ( (PS_AEM == 0) || any(bvec3(c[i].rgb)) ) ? TA.x : 0.0f; c[i].a = ( (PS_AEM == 0) || any(bvec3(c[i].rgb)) ) ? TA.x : 0.0f;
#elif ((PS_FMT & ~FMT_PAL) == FMT_16) #elif ((PS_FMT & ~FMT_PAL) == FMT_16)
c[i].a = c[i].a >= 0.5 ? TA.y : ( (PS_AEM == 0) || any(bvec3(c[i].rgb)) ) ? TA.x : 0.0f; c[i].a = c[i].a >= 0.5 ? TA.y : ( (PS_AEM == 0) || any(bvec3(c[i].rgb)) ) ? TA.x : 0.0f;
#endif #endif
} }
#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 #else
t = c[0]; t = c[0];
#endif #endif
return t; return t;
} }
#ifndef SUBROUTINE_GL40 #ifndef SUBROUTINE_GL40
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; c_out = c * t * 255.0f / 128.0f;
else else
c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f; c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f;
#elif (PS_TFX == 1) #elif (PS_TFX == 1)
if(PS_TCC != 0) if(PS_TCC != 0)
c_out = t; c_out = t;
else else
c_out.rgb = t.rgb; c_out.rgb = t.rgb;
#elif (PS_TFX == 2) #elif (PS_TFX == 2)
c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a; 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) #elif (PS_TFX == 3)
c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a; 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 #endif
return c_out; return c_out;
} }
#endif #endif
#ifndef SUBROUTINE_GL40 #ifndef SUBROUTINE_GL40
void atst(vec4 c) 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; discard;
#elif (PS_ATST == 1) // always #elif (PS_ATST == 1) // always
// nothing to do // nothing to do
#elif (PS_ATST == 2) && (PS_SPRITEHACK == 0) // l #elif (PS_ATST == 2) && (PS_SPRITEHACK == 0) // l
if ((AREF - a - 0.5f) < 0.0f) if ((AREF - a - 0.5f) < 0.0f)
discard; discard;
#elif (PS_ATST == 3 ) // le #elif (PS_ATST == 3 ) // le
if ((AREF - a + 0.5f) < 0.0f) if ((AREF - a + 0.5f) < 0.0f)
discard; discard;
#elif (PS_ATST == 4) // e #elif (PS_ATST == 4) // e
if ((0.5f - abs(a - AREF)) < 0.0f) if ((0.5f - abs(a - AREF)) < 0.0f)
discard; discard;
#elif (PS_ATST == 5) // ge #elif (PS_ATST == 5) // ge
if ((a-AREF + 0.5f) < 0.0f) if ((a-AREF + 0.5f) < 0.0f)
discard; discard;
#elif (PS_ATST == 6) // g #elif (PS_ATST == 6) // g
if ((a-AREF - 0.5f) < 0.0f) if ((a-AREF - 0.5f) < 0.0f)
discard; discard;
#elif (PS_ATST == 7) // ne #elif (PS_ATST == 7) // ne
if ((abs(a - AREF) - 0.5f) < 0.0f) if ((abs(a - AREF) - 0.5f) < 0.0f)
discard; discard;
#endif #endif
} }
#endif #endif
@ -366,12 +362,12 @@ void atst(vec4 c)
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) #elif (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 #endif
@ -379,59 +375,59 @@ void colclip(inout vec4 c)
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 #endif
} }
vec4 ps_color() vec4 ps_color()
{ {
#if PS_SPRITE == 1 #if PS_SPRITE == 1
// Reinterpolate manually the texture coordinate. // Reinterpolate manually the texture coordinate.
// trunc => native resolution. Maybe we can add an option to choose a value between // trunc => native resolution. Maybe we can add an option to choose a value between
// trunc and current. // trunc and current.
vec2 factor = vec2(trunc(PSin.alpha.x), floor(PSin.alpha.y)); vec2 factor = vec2(trunc(PSin.alpha.x), floor(PSin.alpha.y));
//vec2 factor = trunc(PSin.alpha); //vec2 factor = trunc(PSin.alpha);
factor *= PSin.flat_P; factor *= PSin.flat_P;
vec2 txy; vec2 txy;
txy.x = mix(PSin.flat_T.x, PSin.flat_T.y, factor.x); txy.x = mix(PSin.flat_T.x, PSin.flat_T.y, factor.x);
txy.y = mix(PSin.flat_T.z, PSin.flat_T.w, factor.y); txy.y = mix(PSin.flat_T.z, PSin.flat_T.w, factor.y);
#else #else
vec2 txy = PSin_t.xy; vec2 txy = PSin_t.xy;
#endif #endif
vec4 t = sample_color(txy, PSin_t.w); vec4 t = sample_color(txy, PSin_t.w);
vec4 zero = vec4(0.0f, 0.0f, 0.0f, 0.0f); vec4 zero = vec4(0.0f, 0.0f, 0.0f, 0.0f);
vec4 one = vec4(1.0f, 1.0f, 1.0f, 1.0f); vec4 one = vec4(1.0f, 1.0f, 1.0f, 1.0f);
#ifdef TEX_COORD_DEBUG #ifdef TEX_COORD_DEBUG
vec4 c = clamp(t, zero, one); vec4 c = clamp(t, zero, one);
#else #else
#if PS_IIP == 1 #if PS_IIP == 1
vec4 c = clamp(tfx(t, PSin_c), zero, one); vec4 c = clamp(tfx(t, PSin_c), zero, one);
#else #else
vec4 c = clamp(tfx(t, PSin_fc), zero, one); vec4 c = clamp(tfx(t, PSin_fc), zero, one);
#endif #endif
#endif #endif
atst(c); atst(c);
fog(c, PSin_t.z); fog(c, PSin_t.z);
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 #endif
return c; return c;
} }
#if pGL_ES #if pGL_ES
void ps_main() void ps_main()
{ {
vec4 c = ps_color(); vec4 c = ps_color();
c.a *= 2.0; c.a *= 2.0;
SV_Target0 = c; SV_Target0 = c;
} }
#endif #endif
@ -439,30 +435,32 @@ void ps_main()
void ps_main() void ps_main()
{ {
#if (PS_DATE & 3) == 1 && !defined(DISABLE_GL42_image) #if (PS_DATE & 3) == 1 && !defined(DISABLE_GL42_image)
// DATM == 0 // DATM == 0
// Pixel with alpha equal to 1 will failed // Pixel with alpha equal to 1 will failed
float rt_a = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0).a; float rt_a = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0).a;
if ((127.5f / 255.0f) < rt_a) // < 0x80 pass (== 0x80 should not pass) if ((127.5f / 255.0f) < rt_a) { // < 0x80 pass (== 0x80 should not pass)
discard; discard;
}
#elif (PS_DATE & 3) == 2 && !defined(DISABLE_GL42_image) #elif (PS_DATE & 3) == 2 && !defined(DISABLE_GL42_image)
// DATM == 1 // DATM == 1
// Pixel with alpha equal to 0 will failed // Pixel with alpha equal to 0 will failed
float rt_a = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0).a; float rt_a = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0).a;
if(rt_a < (127.5f / 255.0f)) // >= 0x80 pass if(rt_a < (127.5f / 255.0f)) { // >= 0x80 pass
discard; discard;
}
#endif #endif
#if PS_DATE == 3 && !defined(DISABLE_GL42_image) #if PS_DATE == 3 && !defined(DISABLE_GL42_image)
int stencil_ceil = imageLoad(img_prim_min, ivec2(gl_FragCoord.xy)); int stencil_ceil = imageLoad(img_prim_min, ivec2(gl_FragCoord.xy));
// Note gl_PrimitiveID == stencil_ceil will be the primitive that will update // Note gl_PrimitiveID == stencil_ceil will be the primitive that will update
// the bad alpha value so we must keep it. // the bad alpha value so we must keep it.
if (gl_PrimitiveID > stencil_ceil) { if (gl_PrimitiveID > stencil_ceil) {
discard; discard;
} }
#endif #endif
vec4 c = ps_color(); vec4 c = ps_color();
#if (APITRACE_DEBUG & 1) == 1 #if (APITRACE_DEBUG & 1) == 1
c.r = 1.0f; c.r = 1.0f;
#endif #endif
@ -476,39 +474,39 @@ void ps_main()
c.a = 0.5f; c.a = 0.5f;
#endif #endif
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) #elif (PS_FBA != 0)
if(c.a < 0.5) c.a += 0.5; if(c.a < 0.5) c.a += 0.5;
#endif #endif
// 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)
// DATM == 0 // DATM == 0
// Pixel with alpha equal to 1 will failed // Pixel with alpha equal to 1 will failed (128-255)
if (c.a > 127.5f / 255.0f) { if (c.a > 127.5f / 255.0f) {
imageAtomicMin(img_prim_min, ivec2(gl_FragCoord.xy), gl_PrimitiveID); imageAtomicMin(img_prim_min, ivec2(gl_FragCoord.xy), gl_PrimitiveID);
} }
#elif PS_DATE == 2 && !defined(DISABLE_GL42_image) #elif PS_DATE == 2 && !defined(DISABLE_GL42_image)
// DATM == 1 // DATM == 1
// Pixel with alpha equal to 0 will failed // Pixel with alpha equal to 0 will failed (0-127)
if (c.a < 127.5f / 255.0f) { if (c.a < 127.5f / 255.0f) {
imageAtomicMin(img_prim_min, ivec2(gl_FragCoord.xy), gl_PrimitiveID); imageAtomicMin(img_prim_min, ivec2(gl_FragCoord.xy), gl_PrimitiveID);
} }
#endif #endif
#if (PS_DATE == 2 || PS_DATE == 1) && !defined(DISABLE_GL42_image) #if (PS_DATE == 2 || PS_DATE == 1) && !defined(DISABLE_GL42_image)
// Don't write anything on the framebuffer // Don't write anything on the framebuffer
// Note: you can't use discard because it will also drop // Note: you can't use discard because it will also drop
// image operation // image operation
#else #else
SV_Target0 = c; SV_Target0 = c;
SV_Target1 = vec4(alpha, alpha, alpha, alpha); SV_Target1 = vec4(alpha, alpha, alpha, alpha);
#endif #endif
} }

View File

@ -794,13 +794,13 @@ static const char* tfx_fs_all_glsl =
"\n" "\n"
"in SHADER\n" "in SHADER\n"
"{\n" "{\n"
" vec4 t;\n" " vec4 t;\n"
" vec4 c;\n" " vec4 c;\n"
" flat vec4 fc;\n" " flat vec4 fc;\n"
"#if PS_SPRITE == 1\n" "#if PS_SPRITE == 1\n"
" flat vec4 flat_T;\n" " flat vec4 flat_T;\n"
" flat vec2 flat_P;\n" " flat vec2 flat_P;\n"
" vec2 alpha;\n" " vec2 alpha;\n"
"#endif\n" "#endif\n"
"} PSin;\n" "} PSin;\n"
"\n" "\n"
@ -829,30 +829,26 @@ static const char* tfx_fs_all_glsl =
"#if PS_DATE > 0\n" "#if PS_DATE > 0\n"
"// FIXME how to declare memory access\n" "// FIXME how to declare memory access\n"
"layout(r32i, binding = 2) coherent uniform iimage2D img_prim_min;\n" "layout(r32i, binding = 2) coherent uniform iimage2D img_prim_min;\n"
"layout(early_fragment_tests) in;\n"
"// origin_upper_left\n"
"layout(pixel_center_integer) in vec4 gl_FragCoord;\n"
"#endif\n" "#endif\n"
"#else\n" "#else\n"
"// use basic stencil\n" "// use basic stencil\n"
"#endif\n" "#endif\n"
"\n" "\n"
"#ifndef DISABLE_GL42_image\n"
"#if PS_DATE > 0\n"
"// origin_upper_left\n"
"layout(pixel_center_integer) in vec4 gl_FragCoord;\n"
"//in int gl_PrimitiveID;\n"
"#endif\n"
"#endif\n"
"\n" "\n"
"layout(std140, binding = 21) uniform cb21\n" "layout(std140, binding = 21) uniform cb21\n"
"{\n" "{\n"
" vec3 FogColor;\n" " vec3 FogColor;\n"
" float AREF;\n" " float AREF;\n"
" vec4 WH;\n" " vec4 WH;\n"
" vec2 MinF;\n" " vec2 MinF;\n"
" vec2 TA;\n" " vec2 TA;\n"
" uvec4 MskFix;\n" " uvec4 MskFix;\n"
" vec4 HalfTexel;\n" " vec4 HalfTexel;\n"
" vec4 MinMax;\n" " vec4 MinMax;\n"
" vec4 TC_OffsetHack;\n" " vec4 TC_OffsetHack;\n"
"};\n" "};\n"
"\n" "\n"
"#ifdef SUBROUTINE_GL40\n" "#ifdef SUBROUTINE_GL40\n"
@ -870,242 +866,242 @@ static const char* tfx_fs_all_glsl =
"\n" "\n"
"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"
" // 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" "#endif\n"
"\n" "\n"
" return texture(TextureSampler, uv);\n" " return texture(TextureSampler, uv);\n"
"}\n" "}\n"
"\n" "\n"
"vec4 sample_p(float u)\n" "vec4 sample_p(float u)\n"
"{\n" "{\n"
" //FIXME do we need a 1D sampler. Big impact on opengl to find 1 dim\n" " //FIXME do we need a 1D sampler. Big impact on opengl to find 1 dim\n"
" // So for the moment cheat with 0.0f dunno if it work\n" " // So for the moment cheat with 0.0f dunno if it work\n"
" return texture(PaletteSampler, vec2(u, 0.0f));\n" " return texture(PaletteSampler, vec2(u, 0.0f));\n"
"}\n" "}\n"
"\n" "\n"
"vec4 wrapuv(vec4 uv)\n" "vec4 wrapuv(vec4 uv)\n"
"{\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"
" uv_out = clamp(uv, MinMax.xyxy, MinMax.zwzw);\n" " uv_out = clamp(uv, MinMax.xyxy, MinMax.zwzw);\n"
"#elif PS_WMS == 3\n" "#elif PS_WMS == 3\n"
" uv_out = vec4((ivec4(uv * WH.xyxy) & ivec4(MskFix.xyxy)) | ivec4(MskFix.zwzw)) / WH.xyxy;\n" " uv_out = vec4((ivec4(uv * WH.xyxy) & ivec4(MskFix.xyxy)) | ivec4(MskFix.zwzw)) / WH.xyxy;\n"
"#endif\n" "#endif\n"
"\n" "\n"
"#else // PS_WMS != PS_WMT\n" "#else // PS_WMS != PS_WMT\n"
"\n" "\n"
"#if PS_WMS == 2\n" "#if PS_WMS == 2\n"
" uv_out.xz = clamp(uv.xz, MinMax.xx, MinMax.zz);\n" " uv_out.xz = clamp(uv.xz, MinMax.xx, MinMax.zz);\n"
"\n" "\n"
"#elif PS_WMS == 3\n" "#elif PS_WMS == 3\n"
" uv_out.xz = vec2((ivec2(uv.xz * WH.xx) & ivec2(MskFix.xx)) | ivec2(MskFix.zz)) / WH.xx;\n" " uv_out.xz = vec2((ivec2(uv.xz * WH.xx) & ivec2(MskFix.xx)) | ivec2(MskFix.zz)) / WH.xx;\n"
"\n" "\n"
"#endif\n" "#endif\n"
"\n" "\n"
"#if PS_WMT == 2\n" "#if PS_WMT == 2\n"
" uv_out.yw = clamp(uv.yw, MinMax.yy, MinMax.ww);\n" " uv_out.yw = clamp(uv.yw, MinMax.yy, MinMax.ww);\n"
"\n" "\n"
"#elif PS_WMT == 3\n" "#elif PS_WMT == 3\n"
"\n" "\n"
" uv_out.yw = vec2((ivec2(uv.yw * WH.yy) & ivec2(MskFix.yy)) | ivec2(MskFix.ww)) / WH.yy;\n" " uv_out.yw = vec2((ivec2(uv.yw * WH.yy) & ivec2(MskFix.yy)) | ivec2(MskFix.ww)) / WH.yy;\n"
"#endif\n" "#endif\n"
"\n" "\n"
"#endif\n" "#endif\n"
"\n" "\n"
" return uv_out;\n" " return uv_out;\n"
"}\n" "}\n"
"\n" "\n"
"vec2 clampuv(vec2 uv)\n" "vec2 clampuv(vec2 uv)\n"
"{\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"
" uv_out = clamp(uv, MinF, MinMax.zw);\n" " uv_out = clamp(uv, MinF, MinMax.zw);\n"
"#elif PS_WMS == 2\n" "#elif PS_WMS == 2\n"
" uv_out.x = clamp(uv.x, MinF.x, MinMax.z);\n" " uv_out.x = clamp(uv.x, MinF.x, MinMax.z);\n"
"#elif PS_WMT == 2\n" "#elif PS_WMT == 2\n"
" uv_out.y = clamp(uv.y, MinF.y, MinMax.w);\n" " uv_out.y = clamp(uv.y, MinF.y, MinMax.w);\n"
"#endif\n" "#endif\n"
"\n" "\n"
" return uv_out;\n" " return uv_out;\n"
"}\n" "}\n"
"\n" "\n"
"mat4 sample_4c(vec4 uv)\n" "mat4 sample_4c(vec4 uv)\n"
"{\n" "{\n"
" mat4 c;\n" " mat4 c;\n"
"\n" "\n"
" c[0] = sample_c(uv.xy);\n" " c[0] = sample_c(uv.xy);\n"
" c[1] = sample_c(uv.zy);\n" " c[1] = sample_c(uv.zy);\n"
" c[2] = sample_c(uv.xw);\n" " c[2] = sample_c(uv.xw);\n"
" c[3] = sample_c(uv.zw);\n" " c[3] = sample_c(uv.zw);\n"
"\n" "\n"
" return c;\n" " return c;\n"
"}\n" "}\n"
"\n" "\n"
"vec4 sample_4a(vec4 uv)\n" "vec4 sample_4a(vec4 uv)\n"
"{\n" "{\n"
" vec4 c;\n" " vec4 c;\n"
"\n" "\n"
" // Dx used the alpha channel.\n" " // Dx used the alpha channel.\n"
" // Opengl is only 8 bits on red channel.\n" " // Opengl is only 8 bits on red channel.\n"
" c.x = sample_c(uv.xy).r;\n" " c.x = sample_c(uv.xy).r;\n"
" c.y = sample_c(uv.zy).r;\n" " c.y = sample_c(uv.zy).r;\n"
" c.z = sample_c(uv.xw).r;\n" " c.z = sample_c(uv.xw).r;\n"
" c.w = sample_c(uv.zw).r;\n" " c.w = sample_c(uv.zw).r;\n"
"\n" "\n"
" return c * 255.0/256.0 + 0.5/256.0;\n" " return c * 255.0/256.0 + 0.5/256.0;\n"
"}\n" "}\n"
"\n" "\n"
"mat4 sample_4p(vec4 u)\n" "mat4 sample_4p(vec4 u)\n"
"{\n" "{\n"
" mat4 c;\n" " mat4 c;\n"
"\n" "\n"
" c[0] = sample_p(u.x);\n" " c[0] = sample_p(u.x);\n"
" c[1] = sample_p(u.y);\n" " c[1] = sample_p(u.y);\n"
" c[2] = sample_p(u.z);\n" " c[2] = sample_p(u.z);\n"
" c[3] = sample_p(u.w);\n" " c[3] = sample_p(u.w);\n"
"\n" "\n"
" return c;\n" " return c;\n"
"}\n" "}\n"
"\n" "\n"
"vec4 sample_color(vec2 st, float q)\n" "vec4 sample_color(vec2 st, float q)\n"
"{\n" "{\n"
"#if (PS_FST == 0)\n" "#if (PS_FST == 0)\n"
" st /= q;\n" " st /= q;\n"
"#endif\n" "#endif\n"
"\n" "\n"
"#if (PS_TCOFFSETHACK == 1)\n" "#if (PS_TCOFFSETHACK == 1)\n"
" st += TC_OffsetHack.xy;\n" " st += TC_OffsetHack.xy;\n"
"#endif\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"
" 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"
" vec4 uv;\n" " vec4 uv;\n"
"\n" "\n"
" if(PS_LTF != 0)\n" " if(PS_LTF != 0)\n"
" {\n" " {\n"
" uv = st.xyxy + HalfTexel;\n" " uv = st.xyxy + HalfTexel;\n"
" dd = fract(uv.xy * WH.zw);\n" " dd = fract(uv.xy * WH.zw);\n"
" }\n" " }\n"
" else\n" " else\n"
" {\n" " {\n"
" uv = st.xyxy;\n" " uv = st.xyxy;\n"
" }\n" " }\n"
"\n" "\n"
" uv = wrapuv(uv);\n" " uv = wrapuv(uv);\n"
"\n" "\n"
" if((PS_FMT & FMT_PAL) != 0)\n" " if((PS_FMT & FMT_PAL) != 0)\n"
" {\n" " {\n"
" c = sample_4p(sample_4a(uv));\n" " c = sample_4p(sample_4a(uv));\n"
" }\n" " }\n"
" else\n" " else\n"
" {\n" " {\n"
" c = sample_4c(uv);\n" " c = sample_4c(uv);\n"
" }\n" " }\n"
"#ifdef TEX_COORD_DEBUG\n" "#ifdef TEX_COORD_DEBUG\n"
" c[0].rg = uv.xy;\n" " c[0].rg = uv.xy;\n"
" c[1].rg = uv.xy;\n" " c[1].rg = uv.xy;\n"
" 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" "#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" "#if ((PS_FMT & ~FMT_PAL) == FMT_24)\n"
" c[i].a = ( (PS_AEM == 0) || any(bvec3(c[i].rgb)) ) ? TA.x : 0.0f;\n" " c[i].a = ( (PS_AEM == 0) || any(bvec3(c[i].rgb)) ) ? TA.x : 0.0f;\n"
"#elif ((PS_FMT & ~FMT_PAL) == FMT_16)\n" "#elif ((PS_FMT & ~FMT_PAL) == FMT_16)\n"
" c[i].a = c[i].a >= 0.5 ? TA.y : ( (PS_AEM == 0) || any(bvec3(c[i].rgb)) ) ? TA.x : 0.0f;\n" " c[i].a = c[i].a >= 0.5 ? TA.y : ( (PS_AEM == 0) || any(bvec3(c[i].rgb)) ) ? TA.x : 0.0f;\n"
"#endif\n" "#endif\n"
" }\n" " }\n"
"\n" "\n"
"#if(PS_LTF != 0)\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" " t = mix(mix(c[0], c[1], dd.x), mix(c[2], c[3], dd.x), dd.y);\n"
"#else\n" "#else\n"
" t = c[0];\n" " t = c[0];\n"
"#endif\n" "#endif\n"
"\n" "\n"
" return t;\n" " return t;\n"
"}\n" "}\n"
"\n" "\n"
"#ifndef SUBROUTINE_GL40\n" "#ifndef SUBROUTINE_GL40\n"
"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"
" if(PS_TCC != 0) \n" " if(PS_TCC != 0)\n"
" c_out = c * t * 255.0f / 128.0f;\n" " c_out = c * t * 255.0f / 128.0f;\n"
" else\n" " else\n"
" c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f;\n" " c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f;\n"
"#elif (PS_TFX == 1)\n" "#elif (PS_TFX == 1)\n"
" if(PS_TCC != 0) \n" " if(PS_TCC != 0)\n"
" c_out = t;\n" " c_out = t;\n"
" else\n" " else\n"
" c_out.rgb = t.rgb;\n" " c_out.rgb = t.rgb;\n"
"#elif (PS_TFX == 2)\n" "#elif (PS_TFX == 2)\n"
" c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a;\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"
" c_out.a += t.a;\n" " c_out.a += t.a;\n"
"#elif (PS_TFX == 3)\n" "#elif (PS_TFX == 3)\n"
" c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a;\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"
" c_out.a = t.a;\n" " c_out.a = t.a;\n"
"#endif\n" "#endif\n"
"\n" "\n"
" return c_out;\n" " return c_out;\n"
"}\n" "}\n"
"#endif\n" "#endif\n"
"\n" "\n"
"#ifndef SUBROUTINE_GL40\n" "#ifndef SUBROUTINE_GL40\n"
"void atst(vec4 c)\n" "void atst(vec4 c)\n"
"{\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"
" discard;\n" " discard;\n"
"#elif (PS_ATST == 1) // always\n" "#elif (PS_ATST == 1) // always\n"
" // nothing to do\n" " // nothing to do\n"
"#elif (PS_ATST == 2) && (PS_SPRITEHACK == 0) // l\n" "#elif (PS_ATST == 2) && (PS_SPRITEHACK == 0) // l\n"
" if ((AREF - a - 0.5f) < 0.0f)\n" " if ((AREF - a - 0.5f) < 0.0f)\n"
" discard;\n" " discard;\n"
"#elif (PS_ATST == 3 ) // le\n" "#elif (PS_ATST == 3 ) // le\n"
" if ((AREF - a + 0.5f) < 0.0f)\n" " if ((AREF - a + 0.5f) < 0.0f)\n"
" discard;\n" " discard;\n"
"#elif (PS_ATST == 4) // e\n" "#elif (PS_ATST == 4) // e\n"
" if ((0.5f - abs(a - AREF)) < 0.0f)\n" " if ((0.5f - abs(a - AREF)) < 0.0f)\n"
" discard;\n" " discard;\n"
"#elif (PS_ATST == 5) // ge\n" "#elif (PS_ATST == 5) // ge\n"
" if ((a-AREF + 0.5f) < 0.0f)\n" " if ((a-AREF + 0.5f) < 0.0f)\n"
" discard;\n" " discard;\n"
"#elif (PS_ATST == 6) // g\n" "#elif (PS_ATST == 6) // g\n"
" if ((a-AREF - 0.5f) < 0.0f)\n" " if ((a-AREF - 0.5f) < 0.0f)\n"
" discard;\n" " discard;\n"
"#elif (PS_ATST == 7) // ne\n" "#elif (PS_ATST == 7) // ne\n"
" if ((abs(a - AREF) - 0.5f) < 0.0f)\n" " if ((abs(a - AREF) - 0.5f) < 0.0f)\n"
" discard;\n" " discard;\n"
"#endif\n" "#endif\n"
"}\n" "}\n"
"#endif\n" "#endif\n"
@ -1115,12 +1111,12 @@ static const char* tfx_fs_all_glsl =
"void colclip(inout vec4 c)\n" "void colclip(inout vec4 c)\n"
"{\n" "{\n"
"#if (PS_COLCLIP == 2)\n" "#if (PS_COLCLIP == 2)\n"
" c.rgb = 256.0f/255.0f - c.rgb;\n" " c.rgb = 256.0f/255.0f - c.rgb;\n"
"#elif (PS_COLCLIP > 0)\n" "#elif (PS_COLCLIP > 0)\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"
"#endif\n" "#endif\n"
"}\n" "}\n"
"#endif\n" "#endif\n"
@ -1128,59 +1124,59 @@ static const char* tfx_fs_all_glsl =
"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"
" c.rgb = mix(FogColor, c.rgb, f);\n" " c.rgb = mix(FogColor, c.rgb, f);\n"
"#endif\n" "#endif\n"
"}\n" "}\n"
"\n" "\n"
"vec4 ps_color()\n" "vec4 ps_color()\n"
"{\n" "{\n"
"#if PS_SPRITE == 1\n" "#if PS_SPRITE == 1\n"
" // Reinterpolate manually the texture coordinate.\n" " // Reinterpolate manually the texture coordinate.\n"
" // trunc => native resolution. Maybe we can add an option to choose a value between\n" " // trunc => native resolution. Maybe we can add an option to choose a value between\n"
" // trunc and current.\n" " // trunc and current.\n"
" vec2 factor = vec2(trunc(PSin.alpha.x), floor(PSin.alpha.y));\n" " vec2 factor = vec2(trunc(PSin.alpha.x), floor(PSin.alpha.y));\n"
" //vec2 factor = trunc(PSin.alpha);\n" " //vec2 factor = trunc(PSin.alpha);\n"
" factor *= PSin.flat_P;\n" " factor *= PSin.flat_P;\n"
" vec2 txy;\n" " vec2 txy;\n"
" txy.x = mix(PSin.flat_T.x, PSin.flat_T.y, factor.x);\n" " txy.x = mix(PSin.flat_T.x, PSin.flat_T.y, factor.x);\n"
" txy.y = mix(PSin.flat_T.z, PSin.flat_T.w, factor.y);\n" " txy.y = mix(PSin.flat_T.z, PSin.flat_T.w, factor.y);\n"
"\n" "\n"
"#else\n" "#else\n"
" vec2 txy = PSin_t.xy;\n" " vec2 txy = PSin_t.xy;\n"
"#endif\n" "#endif\n"
" vec4 t = sample_color(txy, PSin_t.w);\n" " vec4 t = sample_color(txy, PSin_t.w);\n"
"\n" "\n"
" vec4 zero = vec4(0.0f, 0.0f, 0.0f, 0.0f);\n" " vec4 zero = vec4(0.0f, 0.0f, 0.0f, 0.0f);\n"
" vec4 one = vec4(1.0f, 1.0f, 1.0f, 1.0f);\n" " vec4 one = vec4(1.0f, 1.0f, 1.0f, 1.0f);\n"
"#ifdef TEX_COORD_DEBUG\n" "#ifdef TEX_COORD_DEBUG\n"
" vec4 c = clamp(t, zero, one);\n" " vec4 c = clamp(t, zero, one);\n"
"#else\n" "#else\n"
"#if PS_IIP == 1\n" "#if PS_IIP == 1\n"
" vec4 c = clamp(tfx(t, PSin_c), zero, one);\n" " vec4 c = clamp(tfx(t, PSin_c), zero, one);\n"
"#else\n" "#else\n"
" vec4 c = clamp(tfx(t, PSin_fc), zero, one);\n" " vec4 c = clamp(tfx(t, PSin_fc), zero, one);\n"
"#endif\n" "#endif\n"
"#endif\n" "#endif\n"
"\n" "\n"
" atst(c);\n" " atst(c);\n"
"\n" "\n"
" fog(c, PSin_t.z);\n" " fog(c, PSin_t.z);\n"
"\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"
" c.rgb = vec3(1.0f, 1.0f, 1.0f); \n" " c.rgb = vec3(1.0f, 1.0f, 1.0f);\n"
"#endif\n" "#endif\n"
"\n" "\n"
" return c;\n" " return c;\n"
"}\n" "}\n"
"\n" "\n"
"#if pGL_ES\n" "#if pGL_ES\n"
"void ps_main()\n" "void ps_main()\n"
"{\n" "{\n"
" vec4 c = ps_color();\n" " vec4 c = ps_color();\n"
" c.a *= 2.0;\n" " c.a *= 2.0;\n"
" SV_Target0 = c;\n" " SV_Target0 = c;\n"
"}\n" "}\n"
"#endif\n" "#endif\n"
"\n" "\n"
@ -1188,30 +1184,32 @@ static const char* tfx_fs_all_glsl =
"void ps_main()\n" "void ps_main()\n"
"{\n" "{\n"
"#if (PS_DATE & 3) == 1 && !defined(DISABLE_GL42_image)\n" "#if (PS_DATE & 3) == 1 && !defined(DISABLE_GL42_image)\n"
" // DATM == 0\n" " // DATM == 0\n"
" // Pixel with alpha equal to 1 will failed\n" " // Pixel with alpha equal to 1 will failed\n"
" float rt_a = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0).a;\n" " float rt_a = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0).a;\n"
" if ((127.5f / 255.0f) < rt_a) // < 0x80 pass (== 0x80 should not pass)\n" " if ((127.5f / 255.0f) < rt_a) { // < 0x80 pass (== 0x80 should not pass)\n"
" discard;\n" " discard;\n"
" }\n"
"#elif (PS_DATE & 3) == 2 && !defined(DISABLE_GL42_image)\n" "#elif (PS_DATE & 3) == 2 && !defined(DISABLE_GL42_image)\n"
" // DATM == 1\n" " // DATM == 1\n"
" // Pixel with alpha equal to 0 will failed\n" " // Pixel with alpha equal to 0 will failed\n"
" float rt_a = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0).a;\n" " float rt_a = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0).a;\n"
" if(rt_a < (127.5f / 255.0f)) // >= 0x80 pass\n" " if(rt_a < (127.5f / 255.0f)) { // >= 0x80 pass\n"
" discard;\n" " discard;\n"
" }\n"
"#endif\n" "#endif\n"
"\n" "\n"
"#if PS_DATE == 3 && !defined(DISABLE_GL42_image)\n" "#if PS_DATE == 3 && !defined(DISABLE_GL42_image)\n"
" int stencil_ceil = imageLoad(img_prim_min, ivec2(gl_FragCoord.xy));\n" " int stencil_ceil = imageLoad(img_prim_min, ivec2(gl_FragCoord.xy));\n"
" // Note gl_PrimitiveID == stencil_ceil will be the primitive that will update\n" " // Note gl_PrimitiveID == stencil_ceil will be the primitive that will update\n"
" // the bad alpha value so we must keep it.\n" " // the bad alpha value so we must keep it.\n"
"\n" "\n"
" if (gl_PrimitiveID > stencil_ceil) {\n" " if (gl_PrimitiveID > stencil_ceil) {\n"
" discard;\n" " discard;\n"
" }\n" " }\n"
"#endif\n" "#endif\n"
"\n" "\n"
" vec4 c = ps_color();\n" " vec4 c = ps_color();\n"
"#if (APITRACE_DEBUG & 1) == 1\n" "#if (APITRACE_DEBUG & 1) == 1\n"
" c.r = 1.0f;\n" " c.r = 1.0f;\n"
"#endif\n" "#endif\n"
@ -1225,39 +1223,39 @@ static const char* tfx_fs_all_glsl =
" c.a = 0.5f;\n" " c.a = 0.5f;\n"
"#endif\n" "#endif\n"
"\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"
" 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"
"#elif (PS_FBA != 0)\n" "#elif (PS_FBA != 0)\n"
" if(c.a < 0.5) c.a += 0.5;\n" " if(c.a < 0.5) c.a += 0.5;\n"
"#endif\n" "#endif\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"
" // DATM == 0\n" " // DATM == 0\n"
" // Pixel with alpha equal to 1 will failed\n" " // Pixel with alpha equal to 1 will failed (128-255)\n"
" if (c.a > 127.5f / 255.0f) {\n" " if (c.a > 127.5f / 255.0f) {\n"
" imageAtomicMin(img_prim_min, ivec2(gl_FragCoord.xy), gl_PrimitiveID);\n" " imageAtomicMin(img_prim_min, ivec2(gl_FragCoord.xy), gl_PrimitiveID);\n"
" }\n" " }\n"
"#elif PS_DATE == 2 && !defined(DISABLE_GL42_image)\n" "#elif PS_DATE == 2 && !defined(DISABLE_GL42_image)\n"
" // DATM == 1\n" " // DATM == 1\n"
" // Pixel with alpha equal to 0 will failed\n" " // Pixel with alpha equal to 0 will failed (0-127)\n"
" if (c.a < 127.5f / 255.0f) {\n" " if (c.a < 127.5f / 255.0f) {\n"
" imageAtomicMin(img_prim_min, ivec2(gl_FragCoord.xy), gl_PrimitiveID);\n" " imageAtomicMin(img_prim_min, ivec2(gl_FragCoord.xy), gl_PrimitiveID);\n"
" }\n" " }\n"
"#endif\n" "#endif\n"
"\n" "\n"
"\n" "\n"
"#if (PS_DATE == 2 || PS_DATE == 1) && !defined(DISABLE_GL42_image)\n" "#if (PS_DATE == 2 || PS_DATE == 1) && !defined(DISABLE_GL42_image)\n"
" // Don't write anything on the framebuffer\n" " // Don't write anything on the framebuffer\n"
" // Note: you can't use discard because it will also drop\n" " // Note: you can't use discard because it will also drop\n"
" // image operation\n" " // image operation\n"
"#else\n" "#else\n"
" SV_Target0 = c;\n" " SV_Target0 = c;\n"
" SV_Target1 = vec4(alpha, alpha, alpha, alpha);\n" " SV_Target1 = vec4(alpha, alpha, alpha, alpha);\n"
"#endif\n" "#endif\n"
"\n" "\n"
"}\n" "}\n"