2015-04-17 18:18:07 +00:00
|
|
|
//#version 420 // Keep it for text editor detection
|
|
|
|
|
|
|
|
// note lerp => mix
|
|
|
|
|
|
|
|
#define FMT_32 0
|
|
|
|
#define FMT_24 1
|
|
|
|
#define FMT_16 2
|
|
|
|
#define FMT_PAL 4 /* flag bit */
|
|
|
|
|
|
|
|
// APITRACE_DEBUG allows to force pixel output to easily detect
|
|
|
|
// the fragment computed by primitive
|
|
|
|
#define APITRACE_DEBUG 0
|
|
|
|
// TEX_COORD_DEBUG output the uv coordinate as color. It is useful
|
|
|
|
// to detect bad sampling due to upscaling
|
|
|
|
//#define TEX_COORD_DEBUG
|
|
|
|
|
|
|
|
// Not sure we have same issue on opengl. Doesn't work anyway on ATI card
|
|
|
|
// And I say this as an ATI user.
|
|
|
|
#define ATI_SUCKS 0
|
|
|
|
|
|
|
|
#ifdef FRAGMENT_SHADER
|
|
|
|
|
|
|
|
in SHADER
|
|
|
|
{
|
2015-04-25 10:46:59 +00:00
|
|
|
vec4 t;
|
|
|
|
vec4 c;
|
|
|
|
flat vec4 fc;
|
2015-04-17 18:18:07 +00:00
|
|
|
} PSin;
|
|
|
|
|
|
|
|
#define PSin_t (PSin.t)
|
|
|
|
#define PSin_c (PSin.c)
|
|
|
|
#define PSin_fc (PSin.fc)
|
|
|
|
|
|
|
|
// Same buffer but 2 colors for dual source blending
|
|
|
|
layout(location = 0, index = 0) out vec4 SV_Target0;
|
|
|
|
layout(location = 0, index = 1) out vec4 SV_Target1;
|
|
|
|
|
|
|
|
#ifdef ENABLE_BINDLESS_TEX
|
|
|
|
layout(bindless_sampler, location = 0) uniform sampler2D TextureSampler;
|
|
|
|
layout(bindless_sampler, location = 1) uniform sampler2D PaletteSampler;
|
|
|
|
#else
|
|
|
|
layout(binding = 0) uniform sampler2D TextureSampler;
|
|
|
|
layout(binding = 1) uniform sampler2D PaletteSampler;
|
2015-04-24 18:13:38 +00:00
|
|
|
layout(binding = 3) uniform sampler2D RtSampler; // note 2 already use by the image below
|
2015-04-17 18:18:07 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef DISABLE_GL42_image
|
|
|
|
#if PS_DATE > 0
|
|
|
|
// FIXME how to declare memory access
|
|
|
|
layout(r32i, binding = 2) coherent uniform iimage2D img_prim_min;
|
2015-04-25 10:46:59 +00:00
|
|
|
layout(early_fragment_tests) in;
|
2015-05-01 18:04:23 +00:00
|
|
|
// I don't remember why I set this parameter but it is surely useless
|
|
|
|
//layout(pixel_center_integer) in vec4 gl_FragCoord;
|
2015-04-17 18:18:07 +00:00
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
// use basic stencil
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
layout(std140, binding = 21) uniform cb21
|
|
|
|
{
|
2015-04-25 10:46:59 +00:00
|
|
|
vec3 FogColor;
|
|
|
|
float AREF;
|
|
|
|
vec4 WH;
|
|
|
|
vec2 MinF;
|
|
|
|
vec2 TA;
|
|
|
|
uvec4 MskFix;
|
2015-05-08 18:23:38 +00:00
|
|
|
vec4 Af;
|
2015-04-25 10:46:59 +00:00
|
|
|
vec4 HalfTexel;
|
|
|
|
vec4 MinMax;
|
|
|
|
vec4 TC_OffsetHack;
|
2015-04-17 18:18:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef SUBROUTINE_GL40
|
|
|
|
// Function pointer type + the functionn pointer variable
|
|
|
|
subroutine void AlphaTestType(vec4 c);
|
|
|
|
layout(location = 0) subroutine uniform AlphaTestType atst;
|
|
|
|
|
|
|
|
subroutine vec4 TfxType(vec4 t, vec4 c);
|
|
|
|
layout(location = 2) subroutine uniform TfxType tfx;
|
|
|
|
|
|
|
|
subroutine void ColClipType(inout vec4 c);
|
|
|
|
layout(location = 1) subroutine uniform ColClipType colclip;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
vec4 sample_c(vec2 uv)
|
|
|
|
{
|
2015-04-25 10:46:59 +00:00
|
|
|
// FIXME: check the issue on openGL
|
2015-04-24 15:51:29 +00:00
|
|
|
#if (ATI_SUCKS == 1) && (PS_POINT_SAMPLER == 1)
|
2015-04-25 10:46:59 +00:00
|
|
|
// 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;
|
2015-04-24 15:51:29 +00:00
|
|
|
#endif
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
return texture(TextureSampler, uv);
|
2015-04-17 18:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vec4 sample_p(float u)
|
|
|
|
{
|
2015-04-25 10:46:59 +00:00
|
|
|
//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
|
|
|
|
return texture(PaletteSampler, vec2(u, 0.0f));
|
2015-04-17 18:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vec4 wrapuv(vec4 uv)
|
|
|
|
{
|
2015-04-25 10:46:59 +00:00
|
|
|
vec4 uv_out = uv;
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-24 15:51:29 +00:00
|
|
|
#if PS_WMS == PS_WMT
|
|
|
|
|
|
|
|
#if PS_WMS == 2
|
2015-04-25 10:46:59 +00:00
|
|
|
uv_out = clamp(uv, MinMax.xyxy, MinMax.zwzw);
|
2015-04-24 15:51:29 +00:00
|
|
|
#elif PS_WMS == 3
|
2015-04-25 10:46:59 +00:00
|
|
|
uv_out = vec4((ivec4(uv * WH.xyxy) & ivec4(MskFix.xyxy)) | ivec4(MskFix.zwzw)) / WH.xyxy;
|
2015-04-24 15:51:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#else // PS_WMS != PS_WMT
|
|
|
|
|
|
|
|
#if PS_WMS == 2
|
2015-04-25 10:46:59 +00:00
|
|
|
uv_out.xz = clamp(uv.xz, MinMax.xx, MinMax.zz);
|
2015-04-24 15:51:29 +00:00
|
|
|
|
|
|
|
#elif PS_WMS == 3
|
2015-04-25 10:46:59 +00:00
|
|
|
uv_out.xz = vec2((ivec2(uv.xz * WH.xx) & ivec2(MskFix.xx)) | ivec2(MskFix.zz)) / WH.xx;
|
2015-04-24 15:51:29 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if PS_WMT == 2
|
2015-04-25 10:46:59 +00:00
|
|
|
uv_out.yw = clamp(uv.yw, MinMax.yy, MinMax.ww);
|
2015-04-24 15:51:29 +00:00
|
|
|
|
|
|
|
#elif PS_WMT == 3
|
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
uv_out.yw = vec2((ivec2(uv.yw * WH.yy) & ivec2(MskFix.yy)) | ivec2(MskFix.ww)) / WH.yy;
|
2015-04-24 15:51:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
return uv_out;
|
2015-04-17 18:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vec2 clampuv(vec2 uv)
|
|
|
|
{
|
2015-04-25 10:46:59 +00:00
|
|
|
vec2 uv_out = uv;
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
#if (PS_WMS == 2) && (PS_WMT == 2)
|
|
|
|
uv_out = clamp(uv, MinF, MinMax.zw);
|
2015-04-24 15:51:29 +00:00
|
|
|
#elif PS_WMS == 2
|
2015-04-25 10:46:59 +00:00
|
|
|
uv_out.x = clamp(uv.x, MinF.x, MinMax.z);
|
2015-04-24 15:51:29 +00:00
|
|
|
#elif PS_WMT == 2
|
2015-04-25 10:46:59 +00:00
|
|
|
uv_out.y = clamp(uv.y, MinF.y, MinMax.w);
|
2015-04-24 15:51:29 +00:00
|
|
|
#endif
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
return uv_out;
|
2015-04-17 18:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mat4 sample_4c(vec4 uv)
|
|
|
|
{
|
2015-04-25 10:46:59 +00:00
|
|
|
mat4 c;
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
c[0] = sample_c(uv.xy);
|
|
|
|
c[1] = sample_c(uv.zy);
|
|
|
|
c[2] = sample_c(uv.xw);
|
|
|
|
c[3] = sample_c(uv.zw);
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
return c;
|
2015-04-17 18:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vec4 sample_4a(vec4 uv)
|
|
|
|
{
|
2015-04-25 10:46:59 +00:00
|
|
|
vec4 c;
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
// Dx used the alpha channel.
|
|
|
|
// Opengl is only 8 bits on red channel.
|
|
|
|
c.x = sample_c(uv.xy).r;
|
|
|
|
c.y = sample_c(uv.zy).r;
|
|
|
|
c.z = sample_c(uv.xw).r;
|
|
|
|
c.w = sample_c(uv.zw).r;
|
2015-04-17 18:18:07 +00:00
|
|
|
|
|
|
|
return c * 255.0/256.0 + 0.5/256.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mat4 sample_4p(vec4 u)
|
|
|
|
{
|
2015-04-25 10:46:59 +00:00
|
|
|
mat4 c;
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
c[0] = sample_p(u.x);
|
|
|
|
c[1] = sample_p(u.y);
|
|
|
|
c[2] = sample_p(u.z);
|
|
|
|
c[3] = sample_p(u.w);
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
return c;
|
2015-04-17 18:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vec4 sample_color(vec2 st, float q)
|
|
|
|
{
|
2015-04-24 15:51:29 +00:00
|
|
|
#if (PS_FST == 0)
|
2015-04-25 10:46:59 +00:00
|
|
|
st /= q;
|
2015-04-24 15:51:29 +00:00
|
|
|
#endif
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-24 15:51:29 +00:00
|
|
|
#if (PS_TCOFFSETHACK == 1)
|
2015-04-25 10:46:59 +00:00
|
|
|
st += TC_OffsetHack.xy;
|
2015-04-24 15:51:29 +00:00
|
|
|
#endif
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
vec4 t;
|
|
|
|
mat4 c;
|
|
|
|
vec2 dd;
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-24 15:51:29 +00:00
|
|
|
#if (PS_LTF == 0 && PS_FMT <= FMT_16 && PS_WMS < 3 && PS_WMT < 3)
|
2015-04-25 10:46:59 +00:00
|
|
|
c[0] = sample_c(clampuv(st));
|
2015-04-17 18:18:07 +00:00
|
|
|
#ifdef TEX_COORD_DEBUG
|
2015-04-25 10:46:59 +00:00
|
|
|
c[0].rg = clampuv(st).xy;
|
2015-04-17 18:18:07 +00:00
|
|
|
#endif
|
2015-04-24 15:51:29 +00:00
|
|
|
|
|
|
|
#else
|
2015-04-25 10:46:59 +00:00
|
|
|
vec4 uv;
|
|
|
|
|
|
|
|
if(PS_LTF != 0)
|
|
|
|
{
|
|
|
|
uv = st.xyxy + HalfTexel;
|
|
|
|
dd = fract(uv.xy * WH.zw);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uv = st.xyxy;
|
|
|
|
}
|
|
|
|
|
|
|
|
uv = wrapuv(uv);
|
|
|
|
|
|
|
|
if((PS_FMT & FMT_PAL) != 0)
|
|
|
|
{
|
|
|
|
c = sample_4p(sample_4a(uv));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
c = sample_4c(uv);
|
|
|
|
}
|
2015-04-17 18:18:07 +00:00
|
|
|
#ifdef TEX_COORD_DEBUG
|
2015-04-25 10:46:59 +00:00
|
|
|
c[0].rg = uv.xy;
|
|
|
|
c[1].rg = uv.xy;
|
|
|
|
c[2].rg = uv.xy;
|
|
|
|
c[3].rg = uv.xy;
|
2015-04-17 18:18:07 +00:00
|
|
|
#endif
|
2015-04-24 15:51:29 +00:00
|
|
|
|
|
|
|
#endif
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
// PERF: see the impact of the exansion before/after the interpolation
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
2015-04-24 15:51:29 +00:00
|
|
|
#if ((PS_FMT & ~FMT_PAL) == FMT_24)
|
2015-04-25 10:46:59 +00:00
|
|
|
c[i].a = ( (PS_AEM == 0) || any(bvec3(c[i].rgb)) ) ? TA.x : 0.0f;
|
2015-04-24 15:51:29 +00:00
|
|
|
#elif ((PS_FMT & ~FMT_PAL) == FMT_16)
|
2015-04-25 10:46:59 +00:00
|
|
|
c[i].a = c[i].a >= 0.5 ? TA.y : ( (PS_AEM == 0) || any(bvec3(c[i].rgb)) ) ? TA.x : 0.0f;
|
2015-04-24 15:51:29 +00:00
|
|
|
#endif
|
2015-04-25 10:46:59 +00:00
|
|
|
}
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-24 15:51:29 +00:00
|
|
|
#if(PS_LTF != 0)
|
2015-04-25 10:46:59 +00:00
|
|
|
t = mix(mix(c[0], c[1], dd.x), mix(c[2], c[3], dd.x), dd.y);
|
2015-04-24 15:51:29 +00:00
|
|
|
#else
|
2015-04-25 10:46:59 +00:00
|
|
|
t = c[0];
|
2015-04-24 15:51:29 +00:00
|
|
|
#endif
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
return t;
|
2015-04-17 18:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef SUBROUTINE_GL40
|
|
|
|
vec4 tfx(vec4 t, vec4 c)
|
|
|
|
{
|
2015-04-25 10:46:59 +00:00
|
|
|
vec4 c_out = c;
|
2015-04-24 15:51:29 +00:00
|
|
|
#if (PS_TFX == 0)
|
2015-04-25 10:46:59 +00:00
|
|
|
if(PS_TCC != 0)
|
|
|
|
c_out = c * t * 255.0f / 128.0f;
|
|
|
|
else
|
|
|
|
c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f;
|
2015-04-24 15:51:29 +00:00
|
|
|
#elif (PS_TFX == 1)
|
2015-04-25 10:46:59 +00:00
|
|
|
if(PS_TCC != 0)
|
|
|
|
c_out = t;
|
|
|
|
else
|
|
|
|
c_out.rgb = t.rgb;
|
2015-04-24 15:51:29 +00:00
|
|
|
#elif (PS_TFX == 2)
|
2015-04-25 10:46:59 +00:00
|
|
|
c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a;
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
if(PS_TCC != 0)
|
|
|
|
c_out.a += t.a;
|
2015-04-24 15:51:29 +00:00
|
|
|
#elif (PS_TFX == 3)
|
2015-04-25 10:46:59 +00:00
|
|
|
c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a;
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
if(PS_TCC != 0)
|
|
|
|
c_out.a = t.a;
|
2015-04-24 15:51:29 +00:00
|
|
|
#endif
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
return c_out;
|
2015-04-17 18:18:07 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SUBROUTINE_GL40
|
|
|
|
void atst(vec4 c)
|
|
|
|
{
|
2015-04-25 10:46:59 +00:00
|
|
|
float a = trunc(c.a * 255.0 + 0.01);
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-24 15:51:29 +00:00
|
|
|
#if (PS_ATST == 0) // never
|
2015-04-25 10:46:59 +00:00
|
|
|
discard;
|
2015-04-24 15:51:29 +00:00
|
|
|
#elif (PS_ATST == 1) // always
|
2015-04-25 10:46:59 +00:00
|
|
|
// nothing to do
|
2015-05-08 08:57:21 +00:00
|
|
|
#elif (PS_ATST == 2) // l
|
2015-04-25 10:46:59 +00:00
|
|
|
if ((AREF - a - 0.5f) < 0.0f)
|
|
|
|
discard;
|
2015-04-24 15:51:29 +00:00
|
|
|
#elif (PS_ATST == 3 ) // le
|
2015-04-25 10:46:59 +00:00
|
|
|
if ((AREF - a + 0.5f) < 0.0f)
|
|
|
|
discard;
|
2015-04-24 15:51:29 +00:00
|
|
|
#elif (PS_ATST == 4) // e
|
2015-04-25 10:46:59 +00:00
|
|
|
if ((0.5f - abs(a - AREF)) < 0.0f)
|
|
|
|
discard;
|
2015-04-24 15:51:29 +00:00
|
|
|
#elif (PS_ATST == 5) // ge
|
2015-04-25 10:46:59 +00:00
|
|
|
if ((a-AREF + 0.5f) < 0.0f)
|
|
|
|
discard;
|
2015-04-24 15:51:29 +00:00
|
|
|
#elif (PS_ATST == 6) // g
|
2015-04-25 10:46:59 +00:00
|
|
|
if ((a-AREF - 0.5f) < 0.0f)
|
|
|
|
discard;
|
2015-04-24 15:51:29 +00:00
|
|
|
#elif (PS_ATST == 7) // ne
|
2015-04-25 10:46:59 +00:00
|
|
|
if ((abs(a - AREF) - 0.5f) < 0.0f)
|
|
|
|
discard;
|
2015-04-24 15:51:29 +00:00
|
|
|
#endif
|
2015-04-17 18:18:07 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SUBROUTINE_GL40
|
|
|
|
void colclip(inout vec4 c)
|
|
|
|
{
|
2015-04-24 15:51:29 +00:00
|
|
|
#if (PS_COLCLIP == 2)
|
2015-04-25 10:46:59 +00:00
|
|
|
c.rgb = 256.0f/255.0f - c.rgb;
|
2015-04-30 21:08:05 +00:00
|
|
|
#endif
|
|
|
|
#if (PS_COLCLIP > 0)
|
|
|
|
bvec3 factor = lessThan(c.rgb, vec3(128.0f/255.0f));
|
2015-04-25 10:46:59 +00:00
|
|
|
c.rgb *= vec3(factor);
|
2015-04-24 15:51:29 +00:00
|
|
|
#endif
|
2015-04-17 18:18:07 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void fog(inout vec4 c, float f)
|
|
|
|
{
|
2015-04-24 15:51:29 +00:00
|
|
|
#if PS_FOG != 0
|
2015-04-25 10:46:59 +00:00
|
|
|
c.rgb = mix(FogColor, c.rgb, f);
|
2015-04-24 15:51:29 +00:00
|
|
|
#endif
|
2015-04-17 18:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vec4 ps_color()
|
|
|
|
{
|
2015-05-06 06:44:27 +00:00
|
|
|
vec4 t = sample_color(PSin_t.xy, PSin_t.w);
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
vec4 zero = vec4(0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
vec4 one = vec4(1.0f, 1.0f, 1.0f, 1.0f);
|
2015-04-17 18:18:07 +00:00
|
|
|
#ifdef TEX_COORD_DEBUG
|
2015-04-25 10:46:59 +00:00
|
|
|
vec4 c = clamp(t, zero, one);
|
2015-04-17 18:18:07 +00:00
|
|
|
#else
|
|
|
|
#if PS_IIP == 1
|
2015-04-25 10:46:59 +00:00
|
|
|
vec4 c = clamp(tfx(t, PSin_c), zero, one);
|
2015-04-17 18:18:07 +00:00
|
|
|
#else
|
2015-04-25 10:46:59 +00:00
|
|
|
vec4 c = clamp(tfx(t, PSin_fc), zero, one);
|
2015-04-17 18:18:07 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
atst(c);
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
fog(c, PSin_t.z);
|
2015-04-17 18:18:07 +00:00
|
|
|
|
|
|
|
colclip(c);
|
|
|
|
|
2015-04-24 15:51:29 +00:00
|
|
|
#if (PS_CLR1 != 0) // needed for Cd * (As/Ad/F + 1) blending modes
|
2015-04-25 10:46:59 +00:00
|
|
|
c.rgb = vec3(1.0f, 1.0f, 1.0f);
|
2015-04-24 15:51:29 +00:00
|
|
|
#endif
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
return c;
|
2015-04-17 18:18:07 +00:00
|
|
|
}
|
|
|
|
|
2015-05-08 18:27:13 +00:00
|
|
|
void ps_blend(inout vec4 c, in float As)
|
|
|
|
{
|
|
|
|
vec4 rt = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0);
|
|
|
|
// FIXME Ad or Ad * 2?
|
|
|
|
float Ad = rt.a;
|
|
|
|
|
|
|
|
#if PS_BLEND == 1
|
|
|
|
// {4, D3DBLENDOP_SUBTRACT, D3DBLEND_SRCALPHA, D3DBLEND_SRCALPHA}, //*0100: (Cs - Cd)*As + Cs ==> Cs*(As + 1) - Cd*As
|
|
|
|
c.rgb = c.rgb * (As + 1.0f) - rt.rgb * As;
|
|
|
|
#elif PS_BLEND == 2
|
|
|
|
// {5, D3DBLENDOP_SUBTRACT, D3DBLEND_DESTALPHA, D3DBLEND_DESTALPHA}, //*0110: (Cs - Cd)*Ad + Cs ==> Cs*(Ad + 1) - Cd*Ad
|
|
|
|
c.rgb = c.rgb * (Ad + 1.0f) - rt.rgb * Ad;
|
|
|
|
#elif PS_BLEND == 3
|
|
|
|
// {6, D3DBLENDOP_SUBTRACT, D3DBLEND_BLENDFACTOR, D3DBLEND_BLENDFACTOR}, //*0120: (Cs - Cd)*F + Cs ==> Cs*(F + 1) - Cd*F
|
|
|
|
c.rgb = c.rgb * (Af.x + 1.0f) - rt.rgb * Af.x;
|
|
|
|
#elif PS_BLEND == 4
|
|
|
|
// {7, D3DBLENDOP_ADD, D3DBLEND_SRCALPHA, D3DBLEND_ZERO}, //*0200: (Cs - 0)*As + Cs ==> Cs*(As + 1)
|
|
|
|
c.rgb = c.rgb * (As + 1.0f); // FIXME Not bogus
|
|
|
|
#elif PS_BLEND == 5
|
|
|
|
// {8, D3DBLENDOP_ADD, D3DBLEND_DESTALPHA, D3DBLEND_ZERO}, //*0210: (Cs - 0)*Ad + Cs ==> Cs*(Ad + 1)
|
|
|
|
c.rgb = c.rgb * (Ad + 1.0f);
|
|
|
|
#elif PS_BLEND == 6
|
|
|
|
// {9, D3DBLENDOP_ADD, D3DBLEND_BLENDFACTOR, D3DBLEND_ZERO}, //*0220: (Cs - 0)*F + Cs ==> Cs*(F + 1)
|
|
|
|
c.rgb = c.rgb * (Af.x + 1.0f); // FIXME Not bogus
|
|
|
|
#elif PS_BLEND == 7
|
|
|
|
// {10,D3DBLENDOP_REVSUBTRACT, D3DBLEND_SRCALPHA, D3DBLEND_SRCALPHA}, //*1001: (Cd - Cs)*As + Cd ==> Cd*(As + 1) - Cs*As
|
|
|
|
c.rgb = rt.rgb * (As + 1.0f) - c.rgb * As;
|
|
|
|
#elif PS_BLEND == 8
|
|
|
|
// {11,D3DBLENDOP_REVSUBTRACT, D3DBLEND_DESTALPHA, D3DBLEND_DESTALPHA}, //*1011: (Cd - Cs)*Ad + Cd ==> Cd*(Ad + 1) - Cs*Ad
|
|
|
|
c.rgb = rt.rgb * (Ad + 1.0f) - c.rgb * Ad;
|
|
|
|
#elif PS_BLEND == 9
|
|
|
|
// {12,D3DBLENDOP_REVSUBTRACT, D3DBLEND_BLENDFACTOR, D3DBLEND_BLENDFACTOR},//*1021: (Cd - Cs)*F + Cd ==> Cd*(F + 1) - Cs*F
|
|
|
|
c.rgb = rt.rgb * (Af.x + 1.0f) - c.rgb * Af.x;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-04-17 18:18:07 +00:00
|
|
|
void ps_main()
|
|
|
|
{
|
2015-04-24 18:53:59 +00:00
|
|
|
#if (PS_DATE & 3) == 1 && !defined(DISABLE_GL42_image)
|
2015-04-25 10:46:59 +00:00
|
|
|
// DATM == 0
|
|
|
|
// Pixel with alpha equal to 1 will failed
|
2015-04-24 18:13:38 +00:00
|
|
|
float rt_a = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0).a;
|
2015-04-25 10:46:59 +00:00
|
|
|
if ((127.5f / 255.0f) < rt_a) { // < 0x80 pass (== 0x80 should not pass)
|
2015-05-09 17:54:01 +00:00
|
|
|
#if PS_DATE >= 5
|
|
|
|
discard;
|
|
|
|
#else
|
2015-05-02 14:56:18 +00:00
|
|
|
imageStore(img_prim_min, ivec2(gl_FragCoord.xy), ivec4(-1));
|
|
|
|
return;
|
2015-05-09 17:54:01 +00:00
|
|
|
#endif
|
2015-04-25 10:46:59 +00:00
|
|
|
}
|
2015-04-24 18:53:59 +00:00
|
|
|
#elif (PS_DATE & 3) == 2 && !defined(DISABLE_GL42_image)
|
2015-04-25 10:46:59 +00:00
|
|
|
// DATM == 1
|
|
|
|
// Pixel with alpha equal to 0 will failed
|
2015-04-24 18:13:38 +00:00
|
|
|
float rt_a = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0).a;
|
2015-04-25 10:46:59 +00:00
|
|
|
if(rt_a < (127.5f / 255.0f)) { // >= 0x80 pass
|
2015-05-09 17:54:01 +00:00
|
|
|
#if PS_DATE >= 5
|
|
|
|
discard;
|
|
|
|
#else
|
2015-05-02 14:56:18 +00:00
|
|
|
imageStore(img_prim_min, ivec2(gl_FragCoord.xy), ivec4(-1));
|
|
|
|
return;
|
2015-05-09 17:54:01 +00:00
|
|
|
#endif
|
2015-04-25 10:46:59 +00:00
|
|
|
}
|
2015-04-24 18:13:38 +00:00
|
|
|
#endif
|
|
|
|
|
2015-04-17 18:18:07 +00:00
|
|
|
#if PS_DATE == 3 && !defined(DISABLE_GL42_image)
|
2015-04-25 10:46:59 +00:00
|
|
|
int stencil_ceil = imageLoad(img_prim_min, ivec2(gl_FragCoord.xy));
|
|
|
|
// Note gl_PrimitiveID == stencil_ceil will be the primitive that will update
|
|
|
|
// the bad alpha value so we must keep it.
|
2015-04-17 18:18:07 +00:00
|
|
|
|
|
|
|
if (gl_PrimitiveID > stencil_ceil) {
|
|
|
|
discard;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
vec4 c = ps_color();
|
2015-04-17 18:18:07 +00:00
|
|
|
#if (APITRACE_DEBUG & 1) == 1
|
|
|
|
c.r = 1.0f;
|
|
|
|
#endif
|
|
|
|
#if (APITRACE_DEBUG & 2) == 2
|
|
|
|
c.g = 1.0f;
|
|
|
|
#endif
|
|
|
|
#if (APITRACE_DEBUG & 4) == 4
|
|
|
|
c.b = 1.0f;
|
|
|
|
#endif
|
|
|
|
#if (APITRACE_DEBUG & 8) == 8
|
|
|
|
c.a = 0.5f;
|
|
|
|
#endif
|
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
float alpha = c.a * 2.0;
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-24 15:51:29 +00:00
|
|
|
#if (PS_AOUT != 0) // 16 bit output
|
2015-04-25 10:46:59 +00:00
|
|
|
float a = 128.0f / 255.0; // alpha output will be 0x80
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
c.a = (PS_FBA != 0) ? a : step(0.5, c.a) * a;
|
2015-04-24 15:51:29 +00:00
|
|
|
#elif (PS_FBA != 0)
|
2015-04-25 10:46:59 +00:00
|
|
|
if(c.a < 0.5) c.a += 0.5;
|
2015-04-24 15:51:29 +00:00
|
|
|
#endif
|
2015-04-17 18:18:07 +00:00
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
// Get first primitive that will write a failling alpha value
|
2015-04-17 18:18:07 +00:00
|
|
|
#if PS_DATE == 1 && !defined(DISABLE_GL42_image)
|
2015-04-25 10:46:59 +00:00
|
|
|
// DATM == 0
|
|
|
|
// Pixel with alpha equal to 1 will failed (128-255)
|
|
|
|
if (c.a > 127.5f / 255.0f) {
|
|
|
|
imageAtomicMin(img_prim_min, ivec2(gl_FragCoord.xy), gl_PrimitiveID);
|
2015-05-02 14:56:18 +00:00
|
|
|
return;
|
2015-04-25 10:46:59 +00:00
|
|
|
}
|
2015-04-17 18:18:07 +00:00
|
|
|
#elif PS_DATE == 2 && !defined(DISABLE_GL42_image)
|
2015-04-25 10:46:59 +00:00
|
|
|
// DATM == 1
|
|
|
|
// Pixel with alpha equal to 0 will failed (0-127)
|
|
|
|
if (c.a < 127.5f / 255.0f) {
|
|
|
|
imageAtomicMin(img_prim_min, ivec2(gl_FragCoord.xy), gl_PrimitiveID);
|
2015-05-02 14:56:18 +00:00
|
|
|
return;
|
2015-04-25 10:46:59 +00:00
|
|
|
}
|
2015-04-17 18:18:07 +00:00
|
|
|
#endif
|
|
|
|
|
2015-05-08 18:27:13 +00:00
|
|
|
#if PS_BLEND > 0
|
|
|
|
ps_blend(c, alpha);
|
|
|
|
#endif
|
|
|
|
|
2015-04-25 10:46:59 +00:00
|
|
|
SV_Target0 = c;
|
|
|
|
SV_Target1 = vec4(alpha, alpha, alpha, alpha);
|
2015-04-17 18:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|