2010-03-15 19:13:51 +00:00
|
|
|
#ifdef SHADER_MODEL // make safe to include in resource file to enforce dependency
|
2009-07-06 16:35:06 +00:00
|
|
|
#define FMT_32 0
|
|
|
|
#define FMT_24 1
|
|
|
|
#define FMT_16 2
|
|
|
|
#define FMT_8H 3
|
|
|
|
#define FMT_4HL 4
|
|
|
|
#define FMT_4HH 5
|
|
|
|
#define FMT_8 6
|
|
|
|
|
2009-06-19 20:24:18 +00:00
|
|
|
#if SHADER_MODEL >= 0x400
|
|
|
|
|
|
|
|
#ifndef VS_BPPZ
|
|
|
|
#define VS_BPPZ 0
|
|
|
|
#define VS_TME 1
|
|
|
|
#define VS_FST 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef GS_IIP
|
|
|
|
#define GS_IIP 0
|
|
|
|
#define GS_PRIM 3
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PS_FST
|
|
|
|
#define PS_FST 0
|
2009-07-06 16:35:06 +00:00
|
|
|
#define PS_WMS 0
|
|
|
|
#define PS_WMT 0
|
|
|
|
#define PS_FMT FMT_8
|
2009-06-19 20:24:18 +00:00
|
|
|
#define PS_AEM 0
|
|
|
|
#define PS_TFX 0
|
|
|
|
#define PS_TCC 1
|
2009-07-26 15:30:25 +00:00
|
|
|
#define PS_ATST 1
|
2009-06-19 20:24:18 +00:00
|
|
|
#define PS_FOG 0
|
|
|
|
#define PS_CLR1 0
|
|
|
|
#define PS_FBA 0
|
|
|
|
#define PS_AOUT 0
|
2009-07-22 03:55:28 +00:00
|
|
|
#define PS_LTF 1
|
2010-03-12 19:01:05 +00:00
|
|
|
#define PS_COLCLIP 0
|
2010-05-14 14:05:39 +00:00
|
|
|
#define PS_DATE 0
|
2009-06-19 20:24:18 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
struct VS_INPUT
|
|
|
|
{
|
|
|
|
uint2 p : POSITION0;
|
|
|
|
uint z : POSITION1;
|
|
|
|
float2 t : TEXCOORD0;
|
|
|
|
float q : TEXCOORD1;
|
|
|
|
float4 c : COLOR0;
|
|
|
|
float4 f : COLOR1;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VS_OUTPUT
|
|
|
|
{
|
|
|
|
float4 p : SV_Position;
|
|
|
|
float4 t : TEXCOORD0;
|
2010-05-14 14:05:39 +00:00
|
|
|
#if VS_RTCOPY
|
|
|
|
float4 tp : TEXCOORD1;
|
|
|
|
#endif
|
2009-06-19 20:24:18 +00:00
|
|
|
float4 c : COLOR0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PS_INPUT
|
|
|
|
{
|
|
|
|
float4 p : SV_Position;
|
|
|
|
float4 t : TEXCOORD0;
|
2010-05-14 14:05:39 +00:00
|
|
|
#if PS_DATE > 0
|
|
|
|
float4 tp : TEXCOORD1;
|
|
|
|
#endif
|
2009-06-19 20:24:18 +00:00
|
|
|
float4 c : COLOR0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PS_OUTPUT
|
|
|
|
{
|
|
|
|
float4 c0 : SV_Target0;
|
|
|
|
float4 c1 : SV_Target1;
|
|
|
|
};
|
|
|
|
|
2009-07-06 16:35:06 +00:00
|
|
|
Texture2D<float4> Texture : register(t0);
|
|
|
|
Texture2D<float4> Palette : register(t1);
|
2010-05-14 14:05:39 +00:00
|
|
|
Texture2D<float4> RTCopy : register(t2);
|
2009-07-06 16:35:06 +00:00
|
|
|
SamplerState TextureSampler : register(s0);
|
|
|
|
SamplerState PaletteSampler : register(s1);
|
2010-05-14 14:05:39 +00:00
|
|
|
SamplerState RTCopySampler : register(s2);
|
2009-06-19 20:24:18 +00:00
|
|
|
|
|
|
|
cbuffer cb0
|
|
|
|
{
|
|
|
|
float4 VertexScale;
|
|
|
|
float4 VertexOffset;
|
|
|
|
float2 TextureScale;
|
|
|
|
};
|
|
|
|
|
|
|
|
cbuffer cb1
|
|
|
|
{
|
|
|
|
float3 FogColor;
|
|
|
|
float AREF;
|
|
|
|
float4 HalfTexel;
|
2009-06-27 03:32:33 +00:00
|
|
|
float4 WH;
|
2009-06-19 20:24:18 +00:00
|
|
|
float4 MinMax;
|
2009-06-27 03:32:33 +00:00
|
|
|
float2 MinF;
|
|
|
|
float2 TA;
|
2009-06-19 20:24:18 +00:00
|
|
|
uint4 MskFix;
|
|
|
|
};
|
|
|
|
|
2009-07-06 16:35:06 +00:00
|
|
|
float4 sample_c(float2 uv)
|
|
|
|
{
|
|
|
|
return Texture.Sample(TextureSampler, uv);
|
|
|
|
}
|
|
|
|
|
|
|
|
float4 sample_p(float u)
|
|
|
|
{
|
|
|
|
return Palette.Sample(PaletteSampler, u);
|
|
|
|
}
|
|
|
|
|
2010-05-14 14:05:39 +00:00
|
|
|
float4 sample_rt(float2 uv)
|
|
|
|
{
|
|
|
|
return RTCopy.Sample(RTCopySampler, uv);
|
|
|
|
}
|
|
|
|
|
2009-06-19 20:24:18 +00:00
|
|
|
#elif SHADER_MODEL <= 0x300
|
|
|
|
|
|
|
|
#ifndef VS_BPPZ
|
|
|
|
#define VS_BPPZ 0
|
|
|
|
#define VS_TME 1
|
|
|
|
#define VS_FST 1
|
|
|
|
#define VS_LOGZ 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PS_FST
|
|
|
|
#define PS_FST 0
|
2009-07-06 16:35:06 +00:00
|
|
|
#define PS_WMS 0
|
|
|
|
#define PS_WMT 0
|
|
|
|
#define PS_FMT FMT_8
|
2009-06-19 20:24:18 +00:00
|
|
|
#define PS_AEM 0
|
|
|
|
#define PS_TFX 0
|
2009-07-06 16:35:06 +00:00
|
|
|
#define PS_TCC 0
|
2009-06-19 20:24:18 +00:00
|
|
|
#define PS_ATST 4
|
|
|
|
#define PS_FOG 0
|
|
|
|
#define PS_CLR1 0
|
|
|
|
#define PS_RT 0
|
|
|
|
#define PS_LTF 0
|
2010-03-12 19:01:05 +00:00
|
|
|
#define PS_COLCLIP 0
|
2010-05-14 14:05:39 +00:00
|
|
|
#define PS_DATE 0
|
2009-06-19 20:24:18 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
struct VS_INPUT
|
|
|
|
{
|
|
|
|
float4 p : POSITION0;
|
|
|
|
float2 t : TEXCOORD0;
|
|
|
|
float4 c : COLOR0;
|
|
|
|
float4 f : COLOR1;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VS_OUTPUT
|
|
|
|
{
|
|
|
|
float4 p : POSITION;
|
|
|
|
float4 t : TEXCOORD0;
|
2010-05-14 14:05:39 +00:00
|
|
|
#if VS_RTCOPY
|
|
|
|
float4 tp : TEXCOORD1;
|
|
|
|
#endif
|
2009-06-19 20:24:18 +00:00
|
|
|
float4 c : COLOR0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PS_INPUT
|
|
|
|
{
|
|
|
|
float4 t : TEXCOORD0;
|
2010-05-14 14:05:39 +00:00
|
|
|
#if PS_DATE > 0
|
|
|
|
float4 tp : TEXCOORD1;
|
|
|
|
#endif
|
2009-06-19 20:24:18 +00:00
|
|
|
float4 c : COLOR0;
|
|
|
|
};
|
|
|
|
|
|
|
|
sampler Texture : register(s0);
|
2009-07-06 16:35:06 +00:00
|
|
|
sampler Palette : register(s1);
|
2010-05-14 14:05:39 +00:00
|
|
|
sampler RTCopy : register(s2);
|
|
|
|
sampler1D UMSKFIX : register(s3);
|
|
|
|
sampler1D VMSKFIX : register(s4);
|
2009-06-19 20:24:18 +00:00
|
|
|
|
|
|
|
float4 vs_params[3];
|
|
|
|
|
|
|
|
#define VertexScale vs_params[0]
|
|
|
|
#define VertexOffset vs_params[1]
|
|
|
|
#define TextureScale vs_params[2].xy
|
|
|
|
|
2010-03-12 19:01:05 +00:00
|
|
|
float4 ps_params[7];
|
2009-06-19 20:24:18 +00:00
|
|
|
|
|
|
|
#define FogColor ps_params[0].bgr
|
|
|
|
#define AREF ps_params[0].a
|
|
|
|
#define HalfTexel ps_params[1]
|
2009-06-27 03:32:33 +00:00
|
|
|
#define WH ps_params[2]
|
2009-06-19 20:24:18 +00:00
|
|
|
#define MinMax ps_params[3]
|
2009-06-27 03:32:33 +00:00
|
|
|
#define MinF ps_params[4].xy
|
2009-07-06 16:35:06 +00:00
|
|
|
#define TA ps_params[4].zw
|
|
|
|
|
|
|
|
float4 sample_c(float2 uv)
|
|
|
|
{
|
|
|
|
return tex2D(Texture, uv);
|
|
|
|
}
|
|
|
|
|
|
|
|
float4 sample_p(float u)
|
|
|
|
{
|
|
|
|
return tex2D(Palette, u);
|
|
|
|
}
|
2009-06-19 20:24:18 +00:00
|
|
|
|
2010-05-14 14:05:39 +00:00
|
|
|
float4 sample_rt(float2 uv)
|
|
|
|
{
|
|
|
|
return tex2D(RTCopy, uv);
|
|
|
|
}
|
|
|
|
|
2009-06-19 20:24:18 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
float4 wrapuv(float4 uv)
|
|
|
|
{
|
|
|
|
if(PS_WMS == PS_WMT)
|
|
|
|
{
|
2009-07-22 03:55:28 +00:00
|
|
|
/*
|
2009-06-19 20:24:18 +00:00
|
|
|
if(PS_WMS == 0)
|
|
|
|
{
|
|
|
|
uv = frac(uv);
|
|
|
|
}
|
|
|
|
else if(PS_WMS == 1)
|
|
|
|
{
|
|
|
|
uv = saturate(uv);
|
|
|
|
}
|
2009-07-22 03:55:28 +00:00
|
|
|
else
|
|
|
|
*/
|
|
|
|
if(PS_WMS == 2)
|
2009-06-19 20:24:18 +00:00
|
|
|
{
|
|
|
|
uv = clamp(uv, MinMax.xyxy, MinMax.zwzw);
|
|
|
|
}
|
|
|
|
else if(PS_WMS == 3)
|
|
|
|
{
|
|
|
|
#if SHADER_MODEL >= 0x400
|
|
|
|
uv = (float4)(((int4)(uv * WH.xyxy) & MskFix.xyxy) | MskFix.zwzw) / WH.xyxy;
|
|
|
|
#elif SHADER_MODEL <= 0x300
|
|
|
|
uv.x = tex1D(UMSKFIX, uv.x);
|
|
|
|
uv.y = tex1D(VMSKFIX, uv.y);
|
|
|
|
uv.z = tex1D(UMSKFIX, uv.z);
|
|
|
|
uv.w = tex1D(VMSKFIX, uv.w);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-22 03:55:28 +00:00
|
|
|
/*
|
2009-06-19 20:24:18 +00:00
|
|
|
if(PS_WMS == 0)
|
|
|
|
{
|
|
|
|
uv.xz = frac(uv.xz);
|
|
|
|
}
|
|
|
|
else if(PS_WMS == 1)
|
|
|
|
{
|
|
|
|
uv.xz = saturate(uv.xz);
|
|
|
|
}
|
2009-07-22 03:55:28 +00:00
|
|
|
else
|
|
|
|
*/
|
|
|
|
if(PS_WMS == 2)
|
2009-06-19 20:24:18 +00:00
|
|
|
{
|
|
|
|
uv.xz = clamp(uv.xz, MinMax.xx, MinMax.zz);
|
|
|
|
}
|
|
|
|
else if(PS_WMS == 3)
|
|
|
|
{
|
|
|
|
#if SHADER_MODEL >= 0x400
|
2009-07-05 12:58:59 +00:00
|
|
|
uv.xz = (float2)(((int2)(uv.xz * WH.xx) & MskFix.xx) | MskFix.zz) / WH.xx;
|
2009-06-19 20:24:18 +00:00
|
|
|
#elif SHADER_MODEL <= 0x300
|
|
|
|
uv.x = tex1D(UMSKFIX, uv.x);
|
|
|
|
uv.z = tex1D(UMSKFIX, uv.z);
|
|
|
|
#endif
|
|
|
|
}
|
2009-07-22 03:55:28 +00:00
|
|
|
/*
|
2009-06-19 20:24:18 +00:00
|
|
|
if(PS_WMT == 0)
|
|
|
|
{
|
|
|
|
uv.yw = frac(uv.yw);
|
|
|
|
}
|
|
|
|
else if(PS_WMT == 1)
|
|
|
|
{
|
|
|
|
uv.yw = saturate(uv.yw);
|
|
|
|
}
|
2009-07-22 03:55:28 +00:00
|
|
|
else
|
|
|
|
*/
|
|
|
|
if(PS_WMT == 2)
|
2009-06-19 20:24:18 +00:00
|
|
|
{
|
|
|
|
uv.yw = clamp(uv.yw, MinMax.yy, MinMax.ww);
|
|
|
|
}
|
|
|
|
else if(PS_WMT == 3)
|
|
|
|
{
|
|
|
|
#if SHADER_MODEL >= 0x400
|
2009-07-05 12:58:59 +00:00
|
|
|
uv.yw = (float2)(((int2)(uv.yw * WH.yy) & MskFix.yy) | MskFix.ww) / WH.yy;
|
2009-06-19 20:24:18 +00:00
|
|
|
#elif SHADER_MODEL <= 0x300
|
|
|
|
uv.y = tex1D(VMSKFIX, uv.y);
|
|
|
|
uv.w = tex1D(VMSKFIX, uv.w);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return uv;
|
|
|
|
}
|
|
|
|
|
|
|
|
float2 clampuv(float2 uv)
|
|
|
|
{
|
|
|
|
if(PS_WMS == 2 && PS_WMT == 2)
|
|
|
|
{
|
2009-06-27 03:32:33 +00:00
|
|
|
uv = clamp(uv, MinF, MinMax.zw);
|
2009-06-19 20:24:18 +00:00
|
|
|
}
|
|
|
|
else if(PS_WMS == 2)
|
|
|
|
{
|
2009-06-27 03:32:33 +00:00
|
|
|
uv.x = clamp(uv.x, MinF.x, MinMax.z);
|
2009-06-19 20:24:18 +00:00
|
|
|
}
|
|
|
|
else if(PS_WMT == 2)
|
|
|
|
{
|
2009-06-27 03:32:33 +00:00
|
|
|
uv.y = clamp(uv.y, MinF.y, MinMax.w);
|
2009-06-19 20:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return uv;
|
|
|
|
}
|
|
|
|
|
2009-07-06 16:35:06 +00:00
|
|
|
float4x4 sample_4c(float4 uv)
|
|
|
|
{
|
|
|
|
float4x4 c;
|
|
|
|
|
|
|
|
c[0] = sample_c(uv.xy);
|
|
|
|
c[1] = sample_c(uv.zy);
|
|
|
|
c[2] = sample_c(uv.xw);
|
|
|
|
c[3] = sample_c(uv.zw);
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2009-07-26 15:30:25 +00:00
|
|
|
float4 sample_4a(float4 uv)
|
2009-07-06 16:35:06 +00:00
|
|
|
{
|
|
|
|
float4 c;
|
2009-07-26 15:30:25 +00:00
|
|
|
|
2009-07-06 16:35:06 +00:00
|
|
|
c.x = sample_c(uv.xy).a;
|
|
|
|
c.y = sample_c(uv.zy).a;
|
|
|
|
c.z = sample_c(uv.xw).a;
|
|
|
|
c.w = sample_c(uv.zw).a;
|
2009-07-26 15:30:25 +00:00
|
|
|
|
2009-07-06 16:35:06 +00:00
|
|
|
#if SHADER_MODEL <= 0x300
|
2009-07-12 13:46:05 +00:00
|
|
|
if(PS_RT) c *= 128.0f / 255;
|
2009-07-06 16:35:06 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
float4x4 sample_4p(float4 u)
|
|
|
|
{
|
|
|
|
float4x4 c;
|
2009-07-07 10:57:04 +00:00
|
|
|
|
2009-07-06 16:35:06 +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);
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2009-07-07 10:57:04 +00:00
|
|
|
float4 sample(float2 st, float q)
|
2009-07-06 16:35:06 +00:00
|
|
|
{
|
|
|
|
if(!PS_FST)
|
|
|
|
{
|
2009-07-07 10:57:04 +00:00
|
|
|
st /= q;
|
2009-07-06 16:35:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float4 t;
|
|
|
|
/*
|
|
|
|
if(PS_FMT <= FMT_16 && PS_WMS < 2 && PS_WMT < 2)
|
|
|
|
{
|
2009-07-07 10:57:04 +00:00
|
|
|
t = sample_c(st);
|
2009-07-06 16:35:06 +00:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
if(PS_FMT <= FMT_16 && PS_WMS < 3 && PS_WMT < 3)
|
|
|
|
{
|
2009-07-07 10:57:04 +00:00
|
|
|
t = sample_c(clampuv(st));
|
2009-07-06 16:35:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-07 10:57:04 +00:00
|
|
|
float4 uv;
|
|
|
|
float2 dd;
|
|
|
|
|
|
|
|
if(PS_LTF)
|
|
|
|
{
|
|
|
|
uv = st.xyxy + HalfTexel;
|
|
|
|
dd = frac(uv.xy * WH.zw);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uv = st.xyxy;
|
|
|
|
}
|
|
|
|
|
|
|
|
uv = wrapuv(uv);
|
2009-07-06 16:35:06 +00:00
|
|
|
|
|
|
|
float4x4 c;
|
|
|
|
|
|
|
|
if(PS_FMT == FMT_8H)
|
|
|
|
{
|
2009-07-26 15:30:25 +00:00
|
|
|
c = sample_4p(sample_4a(uv));
|
2009-07-06 16:35:06 +00:00
|
|
|
}
|
|
|
|
else if(PS_FMT == FMT_4HL)
|
|
|
|
{
|
2009-07-26 15:30:25 +00:00
|
|
|
c = sample_4p(fmod(sample_4a(uv), 1.0f / 16));
|
2009-07-06 16:35:06 +00:00
|
|
|
}
|
|
|
|
else if(PS_FMT == FMT_4HH)
|
|
|
|
{
|
2009-07-26 15:30:25 +00:00
|
|
|
c = sample_4p(fmod(sample_4a(uv) * 16, 1.0f / 16));
|
2009-07-06 16:35:06 +00:00
|
|
|
}
|
|
|
|
else if(PS_FMT == FMT_8)
|
|
|
|
{
|
2009-07-26 15:30:25 +00:00
|
|
|
c = sample_4p(sample_4a(uv));
|
2009-07-06 16:35:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
c = sample_4c(uv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(PS_LTF)
|
|
|
|
{
|
|
|
|
t = lerp(lerp(c[0], c[1], dd.x), lerp(c[2], c[3], dd.x), dd.y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
t = c[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(PS_FMT == FMT_32)
|
|
|
|
{
|
|
|
|
#if SHADER_MODEL <= 0x300
|
2009-07-12 13:46:05 +00:00
|
|
|
if(PS_RT) t.a *= 128.0f / 255;
|
2009-07-06 16:35:06 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if(PS_FMT == FMT_24)
|
|
|
|
{
|
|
|
|
t.a = !PS_AEM || any(t.rgb) ? TA.x : 0;
|
|
|
|
}
|
|
|
|
else if(PS_FMT == FMT_16)
|
|
|
|
{
|
|
|
|
// a bit incompatible with up-scaling because the 1 bit alpha is interpolated
|
|
|
|
|
|
|
|
t.a = t.a >= 0.5 ? TA.y : !PS_AEM || any(t.rgb) ? TA.x : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2009-06-19 20:24:18 +00:00
|
|
|
float4 tfx(float4 t, float4 c)
|
|
|
|
{
|
|
|
|
if(PS_TFX == 0)
|
|
|
|
{
|
2009-07-06 16:35:06 +00:00
|
|
|
if(PS_TCC)
|
2009-06-19 20:24:18 +00:00
|
|
|
{
|
2009-07-06 16:35:06 +00:00
|
|
|
c = c * t * 255.0f / 128;
|
2009-06-19 20:24:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-06 16:35:06 +00:00
|
|
|
c.rgb = c.rgb * t.rgb * 255.0f / 128;
|
2009-06-19 20:24:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(PS_TFX == 1)
|
|
|
|
{
|
2009-07-06 16:35:06 +00:00
|
|
|
if(PS_TCC)
|
2009-06-19 20:24:18 +00:00
|
|
|
{
|
2009-07-06 16:35:06 +00:00
|
|
|
c = t;
|
2009-06-19 20:24:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-06 16:35:06 +00:00
|
|
|
c.rgb = t.rgb;
|
2009-06-19 20:24:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(PS_TFX == 2)
|
|
|
|
{
|
|
|
|
c.rgb = c.rgb * t.rgb * 255.0f / 128 + c.a;
|
|
|
|
|
2009-07-06 16:35:06 +00:00
|
|
|
if(PS_TCC)
|
2009-06-19 20:24:18 +00:00
|
|
|
{
|
|
|
|
c.a += t.a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(PS_TFX == 3)
|
|
|
|
{
|
|
|
|
c.rgb = c.rgb * t.rgb * 255.0f / 128 + c.a;
|
|
|
|
|
2009-07-06 16:35:06 +00:00
|
|
|
if(PS_TCC)
|
2009-06-19 20:24:18 +00:00
|
|
|
{
|
|
|
|
c.a = t.a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return saturate(c);
|
|
|
|
}
|
|
|
|
|
2010-05-14 14:05:39 +00:00
|
|
|
void datst(PS_INPUT input)
|
|
|
|
{
|
|
|
|
#if PS_DATE > 0
|
|
|
|
float alpha = sample_rt(input.tp.xy).a;
|
|
|
|
#if SHADER_MODEL >= 0x400
|
|
|
|
float alpha0x80 = 128. / 255;
|
|
|
|
#else
|
|
|
|
float alpha0x80 = 1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (PS_DATE == 1 && alpha >= alpha0x80)
|
|
|
|
discard;
|
|
|
|
else if (PS_DATE == 2 && alpha < alpha0x80)
|
|
|
|
discard;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-06-19 20:24:18 +00:00
|
|
|
void atst(float4 c)
|
|
|
|
{
|
2009-07-26 15:30:25 +00:00
|
|
|
float a = trunc(c.a * 255);
|
|
|
|
|
|
|
|
if(PS_ATST == 0) // never
|
2009-06-19 20:24:18 +00:00
|
|
|
{
|
2009-07-26 15:30:25 +00:00
|
|
|
discard;
|
|
|
|
}
|
|
|
|
else if(PS_ATST == 1) // always
|
|
|
|
{
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
else if(PS_ATST == 2 || PS_ATST == 3) // l, le
|
|
|
|
{
|
|
|
|
clip(AREF - a);
|
|
|
|
}
|
|
|
|
else if(PS_ATST == 4) // e
|
|
|
|
{
|
|
|
|
clip(0.5f - abs(a - AREF));
|
|
|
|
}
|
|
|
|
else if(PS_ATST == 5 || PS_ATST == 6) // ge, g
|
|
|
|
{
|
|
|
|
clip(a - AREF);
|
|
|
|
}
|
|
|
|
else if(PS_ATST == 7) // ne
|
|
|
|
{
|
|
|
|
clip(abs(a - AREF) - 0.5f);
|
2009-06-19 20:24:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
float4 fog(float4 c, float f)
|
|
|
|
{
|
2009-07-06 16:35:06 +00:00
|
|
|
if(PS_FOG)
|
2009-06-19 20:24:18 +00:00
|
|
|
{
|
|
|
|
c.rgb = lerp(FogColor, c.rgb, f);
|
|
|
|
}
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2009-07-06 16:35:06 +00:00
|
|
|
float4 ps_color(PS_INPUT input)
|
|
|
|
{
|
2010-05-14 14:05:39 +00:00
|
|
|
datst(input);
|
|
|
|
|
2009-07-06 16:35:06 +00:00
|
|
|
float4 t = sample(input.t.xy, input.t.w);
|
|
|
|
|
|
|
|
float4 c = tfx(t, input.c);
|
2010-05-14 14:05:39 +00:00
|
|
|
|
2009-07-06 16:35:06 +00:00
|
|
|
atst(c);
|
|
|
|
|
|
|
|
c = fog(c, input.t.z);
|
|
|
|
|
2010-03-12 19:01:05 +00:00
|
|
|
if (PS_COLCLIP == 2)
|
|
|
|
{
|
|
|
|
c.rgb = 256./255. - c.rgb;
|
|
|
|
}
|
|
|
|
if (PS_COLCLIP > 0)
|
|
|
|
{
|
|
|
|
c.rgb *= c.rgb < 128./255;
|
|
|
|
}
|
|
|
|
|
2009-07-06 16:35:06 +00:00
|
|
|
if(PS_CLR1) // needed for Cd * (As/Ad/F + 1) blending modes
|
|
|
|
{
|
|
|
|
c.rgb = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2009-06-19 20:24:18 +00:00
|
|
|
#if SHADER_MODEL >= 0x400
|
|
|
|
|
|
|
|
VS_OUTPUT vs_main(VS_INPUT input)
|
|
|
|
{
|
|
|
|
if(VS_BPPZ == 1) // 24
|
|
|
|
{
|
|
|
|
input.z = input.z & 0xffffff;
|
|
|
|
}
|
|
|
|
else if(VS_BPPZ == 2) // 16
|
|
|
|
{
|
|
|
|
input.z = input.z & 0xffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
VS_OUTPUT output;
|
|
|
|
|
|
|
|
// pos -= 0.05 (1/320 pixel) helps avoiding rounding problems (integral part of pos is usually 5 digits, 0.05 is about as low as we can go)
|
|
|
|
// example: ceil(afterseveralvertextransformations(y = 133)) => 134 => line 133 stays empty
|
|
|
|
// input granularity is 1/16 pixel, anything smaller than that won't step drawing up/left by one pixel
|
|
|
|
// example: 133.0625 (133 + 1/16) should start from line 134, ceil(133.0625 - 0.05) still above 133
|
|
|
|
|
|
|
|
float4 p = float4(input.p, input.z, 0) - float4(0.05f, 0.05f, 0, 0);
|
|
|
|
|
|
|
|
output.p = p * VertexScale - VertexOffset;
|
2010-05-14 14:05:39 +00:00
|
|
|
#if VS_RTCOPY
|
|
|
|
output.tp = (p * VertexScale - VertexOffset) * float4(0.5, -0.5, 0, 0) + 0.5;
|
|
|
|
#endif
|
|
|
|
|
2009-07-06 16:35:06 +00:00
|
|
|
if(VS_TME)
|
2009-06-19 20:24:18 +00:00
|
|
|
{
|
2009-07-06 16:35:06 +00:00
|
|
|
if(VS_FST)
|
2009-06-19 20:24:18 +00:00
|
|
|
{
|
|
|
|
output.t.xy = input.t * TextureScale;
|
|
|
|
output.t.w = 1.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
output.t.xy = input.t;
|
|
|
|
output.t.w = input.q;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
output.t.xy = 0;
|
|
|
|
output.t.w = 1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
output.c = input.c;
|
|
|
|
output.t.z = input.f.a;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if GS_PRIM == 0
|
|
|
|
|
|
|
|
[maxvertexcount(1)]
|
|
|
|
void gs_main(point VS_OUTPUT input[1], inout PointStream<VS_OUTPUT> stream)
|
|
|
|
{
|
|
|
|
stream.Append(input[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif GS_PRIM == 1
|
|
|
|
|
|
|
|
[maxvertexcount(2)]
|
|
|
|
void gs_main(line VS_OUTPUT input[2], inout LineStream<VS_OUTPUT> stream)
|
|
|
|
{
|
|
|
|
#if GS_IIP == 0
|
|
|
|
input[0].c = input[1].c;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
stream.Append(input[0]);
|
|
|
|
stream.Append(input[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif GS_PRIM == 2
|
|
|
|
|
|
|
|
[maxvertexcount(3)]
|
|
|
|
void gs_main(triangle VS_OUTPUT input[3], inout TriangleStream<VS_OUTPUT> stream)
|
|
|
|
{
|
|
|
|
#if GS_IIP == 0
|
|
|
|
input[0].c = input[2].c;
|
|
|
|
input[1].c = input[2].c;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
stream.Append(input[0]);
|
|
|
|
stream.Append(input[1]);
|
|
|
|
stream.Append(input[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif GS_PRIM == 3
|
|
|
|
|
|
|
|
[maxvertexcount(4)]
|
|
|
|
void gs_main(line VS_OUTPUT input[2], inout TriangleStream<VS_OUTPUT> stream)
|
|
|
|
{
|
|
|
|
input[0].p.z = input[1].p.z;
|
|
|
|
input[0].t.zw = input[1].t.zw;
|
|
|
|
|
|
|
|
#if GS_IIP == 0
|
|
|
|
input[0].c = input[1].c;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
VS_OUTPUT lb = input[1];
|
|
|
|
|
|
|
|
lb.p.x = input[0].p.x;
|
|
|
|
lb.t.x = input[0].t.x;
|
|
|
|
|
|
|
|
VS_OUTPUT rt = input[1];
|
|
|
|
|
|
|
|
rt.p.y = input[0].p.y;
|
|
|
|
rt.t.y = input[0].t.y;
|
|
|
|
|
|
|
|
stream.Append(input[0]);
|
|
|
|
stream.Append(lb);
|
|
|
|
stream.Append(rt);
|
|
|
|
stream.Append(input[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
PS_OUTPUT ps_main(PS_INPUT input)
|
|
|
|
{
|
2009-07-06 16:35:06 +00:00
|
|
|
float4 c = ps_color(input);
|
2009-06-19 20:24:18 +00:00
|
|
|
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
|
|
|
output.c1 = c.a * 2; // used for alpha blending
|
|
|
|
|
2009-07-06 16:35:06 +00:00
|
|
|
if(PS_AOUT) // 16 bit output
|
2009-06-19 20:24:18 +00:00
|
|
|
{
|
|
|
|
float a = 128.0f / 255; // alpha output will be 0x80
|
|
|
|
|
2009-07-06 16:35:06 +00:00
|
|
|
c.a = PS_FBA ? a : step(0.5, c.a) * a;
|
2009-06-19 20:24:18 +00:00
|
|
|
}
|
2009-07-06 16:35:06 +00:00
|
|
|
else if(PS_FBA)
|
2009-06-19 20:24:18 +00:00
|
|
|
{
|
|
|
|
if(c.a < 0.5) c.a += 0.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
output.c0 = c;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif SHADER_MODEL <= 0x300
|
|
|
|
|
|
|
|
VS_OUTPUT vs_main(VS_INPUT input)
|
|
|
|
{
|
|
|
|
if(VS_BPPZ == 1) // 24
|
|
|
|
{
|
|
|
|
input.p.z = fmod(input.p.z, 0x1000000);
|
|
|
|
}
|
|
|
|
else if(VS_BPPZ == 2) // 16
|
|
|
|
{
|
|
|
|
input.p.z = fmod(input.p.z, 0x10000);
|
2009-07-07 10:57:04 +00:00
|
|
|
}
|
2009-06-19 20:24:18 +00:00
|
|
|
|
|
|
|
VS_OUTPUT output;
|
|
|
|
|
|
|
|
// pos -= 0.05 (1/320 pixel) helps avoiding rounding problems (integral part of pos is usually 5 digits, 0.05 is about as low as we can go)
|
|
|
|
// example: ceil(afterseveralvertextransformations(y = 133)) => 134 => line 133 stays empty
|
|
|
|
// input granularity is 1/16 pixel, anything smaller than that won't step drawing up/left by one pixel
|
|
|
|
// example: 133.0625 (133 + 1/16) should start from line 134, ceil(133.0625 - 0.05) still above 133
|
2009-07-07 10:57:04 +00:00
|
|
|
|
2009-06-19 20:24:18 +00:00
|
|
|
float4 p = input.p - float4(0.05f, 0.05f, 0, 0);
|
|
|
|
|
|
|
|
output.p = p * VertexScale - VertexOffset;
|
2010-05-14 14:05:39 +00:00
|
|
|
#if VS_RTCOPY
|
|
|
|
output.tp = (p * VertexScale - VertexOffset) * float4(0.5, -0.5, 0, 0) + 0.5;
|
|
|
|
#endif
|
2009-06-19 20:24:18 +00:00
|
|
|
|
2009-07-06 16:35:06 +00:00
|
|
|
if(VS_LOGZ)
|
2009-06-19 20:24:18 +00:00
|
|
|
{
|
|
|
|
output.p.z = log2(1.0f + input.p.z) / 32;
|
|
|
|
}
|
|
|
|
|
2009-07-06 16:35:06 +00:00
|
|
|
if(VS_TME)
|
2009-06-19 20:24:18 +00:00
|
|
|
{
|
2009-07-06 16:35:06 +00:00
|
|
|
if(VS_FST)
|
2009-06-19 20:24:18 +00:00
|
|
|
{
|
|
|
|
output.t.xy = input.t * TextureScale;
|
|
|
|
output.t.w = 1.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
output.t.xy = input.t;
|
|
|
|
output.t.w = input.p.w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
output.t.xy = 0;
|
|
|
|
output.t.w = 1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
output.c = input.c;
|
|
|
|
output.t.z = input.f.a;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
float4 ps_main(PS_INPUT input) : COLOR
|
|
|
|
{
|
2009-07-06 16:35:06 +00:00
|
|
|
float4 c = ps_color(input);
|
2009-06-19 20:24:18 +00:00
|
|
|
|
|
|
|
c.a *= 2;
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2010-03-15 19:13:51 +00:00
|
|
|
#endif
|
|
|
|
#endif
|