2011-02-19 10:57:28 +00:00
|
|
|
#ifdef SHADER_MODEL // make safe to include in resource file to enforce dependency
|
|
|
|
#if SHADER_MODEL >= 0x400
|
|
|
|
|
2018-10-12 06:06:17 +00:00
|
|
|
#ifndef PS_SCALE_FACTOR
|
|
|
|
#define PS_SCALE_FACTOR 1
|
|
|
|
#endif
|
|
|
|
|
2011-02-19 10:57:28 +00:00
|
|
|
struct VS_INPUT
|
|
|
|
{
|
2018-09-10 20:05:48 +00:00
|
|
|
float4 p : POSITION;
|
2011-02-19 10:57:28 +00:00
|
|
|
float2 t : TEXCOORD0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VS_OUTPUT
|
|
|
|
{
|
|
|
|
float4 p : SV_Position;
|
|
|
|
float2 t : TEXCOORD0;
|
|
|
|
};
|
|
|
|
|
|
|
|
Texture2D Texture;
|
|
|
|
SamplerState TextureSampler;
|
|
|
|
|
|
|
|
float4 sample_c(float2 uv)
|
|
|
|
{
|
|
|
|
return Texture.Sample(TextureSampler, uv);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PS_INPUT
|
|
|
|
{
|
|
|
|
float4 p : SV_Position;
|
|
|
|
float2 t : TEXCOORD0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PS_OUTPUT
|
|
|
|
{
|
|
|
|
float4 c : SV_Target0;
|
|
|
|
};
|
|
|
|
|
|
|
|
#elif SHADER_MODEL <= 0x300
|
|
|
|
|
|
|
|
struct VS_INPUT
|
|
|
|
{
|
2018-09-10 20:05:48 +00:00
|
|
|
float4 p : POSITION;
|
2011-02-19 10:57:28 +00:00
|
|
|
float2 t : TEXCOORD0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VS_OUTPUT
|
|
|
|
{
|
|
|
|
float4 p : POSITION;
|
|
|
|
float2 t : TEXCOORD0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PS_INPUT
|
|
|
|
{
|
|
|
|
#if SHADER_MODEL < 0x300
|
|
|
|
float4 p : TEXCOORD1;
|
|
|
|
#else
|
|
|
|
float4 p : VPOS;
|
|
|
|
#endif
|
|
|
|
float2 t : TEXCOORD0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PS_OUTPUT
|
|
|
|
{
|
|
|
|
float4 c : COLOR;
|
|
|
|
};
|
|
|
|
|
|
|
|
sampler Texture : register(s0);
|
|
|
|
|
|
|
|
float4 sample_c(float2 uv)
|
|
|
|
{
|
|
|
|
return tex2D(Texture, uv);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
VS_OUTPUT vs_main(VS_INPUT input)
|
|
|
|
{
|
|
|
|
VS_OUTPUT output;
|
|
|
|
|
|
|
|
output.p = input.p;
|
|
|
|
output.t = input.t;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_OUTPUT ps_main0(PS_INPUT input)
|
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
|
|
|
output.c = sample_c(input.t);
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2011-07-25 11:16:01 +00:00
|
|
|
PS_OUTPUT ps_main7(PS_INPUT input)
|
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
|
|
|
float4 c = sample_c(input.t);
|
|
|
|
|
|
|
|
c.a = dot(c.rgb, float3(0.299, 0.587, 0.114));
|
|
|
|
|
|
|
|
output.c = c;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2011-02-19 10:57:28 +00:00
|
|
|
float4 ps_crt(PS_INPUT input, int i)
|
|
|
|
{
|
|
|
|
float4 mask[4] =
|
|
|
|
{
|
|
|
|
float4(1, 0, 0, 0),
|
|
|
|
float4(0, 1, 0, 0),
|
|
|
|
float4(0, 0, 1, 0),
|
|
|
|
float4(1, 1, 1, 0)
|
|
|
|
};
|
|
|
|
|
|
|
|
return sample_c(input.t) * saturate(mask[i] + 0.5f);
|
|
|
|
}
|
|
|
|
|
2013-12-22 15:36:47 +00:00
|
|
|
float4 ps_scanlines(PS_INPUT input, int i)
|
|
|
|
{
|
|
|
|
float4 mask[2] =
|
|
|
|
{
|
|
|
|
float4(1, 1, 1, 0),
|
|
|
|
float4(0, 0, 0, 0)
|
|
|
|
};
|
|
|
|
|
|
|
|
return sample_c(input.t) * saturate(mask[i] + 0.5f);
|
|
|
|
}
|
|
|
|
|
2011-02-19 10:57:28 +00:00
|
|
|
#if SHADER_MODEL >= 0x400
|
|
|
|
|
|
|
|
uint ps_main1(PS_INPUT input) : SV_Target0
|
|
|
|
{
|
|
|
|
float4 c = sample_c(input.t);
|
|
|
|
|
|
|
|
c.a *= 256.0f / 127; // hm, 0.5 won't give us 1.0 if we just multiply with 2
|
|
|
|
|
|
|
|
uint4 i = c * float4(0x001f, 0x03e0, 0x7c00, 0x8000);
|
|
|
|
|
|
|
|
return (i.x & 0x001f) | (i.y & 0x03e0) | (i.z & 0x7c00) | (i.w & 0x8000);
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_OUTPUT ps_main2(PS_INPUT input)
|
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
2012-08-06 17:38:28 +00:00
|
|
|
clip(sample_c(input.t).a - 127.5f / 255); // >= 0x80 pass
|
2011-02-19 10:57:28 +00:00
|
|
|
|
|
|
|
output.c = 0;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_OUTPUT ps_main3(PS_INPUT input)
|
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
2012-08-06 17:38:28 +00:00
|
|
|
clip(127.5f / 255 - sample_c(input.t).a); // < 0x80 pass (== 0x80 should not pass)
|
2011-02-19 10:57:28 +00:00
|
|
|
|
|
|
|
output.c = 0;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_OUTPUT ps_main4(PS_INPUT input)
|
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
|
|
|
output.c = fmod(sample_c(input.t) * 255 + 0.5f, 256) / 255;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2014-01-11 23:17:07 +00:00
|
|
|
PS_OUTPUT ps_main5(PS_INPUT input) // scanlines
|
2011-02-19 10:57:28 +00:00
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
|
|
|
uint4 p = (uint4)input.p;
|
|
|
|
|
2014-01-11 23:17:07 +00:00
|
|
|
output.c = ps_scanlines(input, p.y % 2);
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_OUTPUT ps_main6(PS_INPUT input) // diagonal
|
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
|
|
|
uint4 p = (uint4)input.p;
|
|
|
|
|
|
|
|
output.c = ps_crt(input, (p.x + (p.y % 3)) % 3);
|
2011-02-19 10:57:28 +00:00
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2014-01-11 23:17:07 +00:00
|
|
|
PS_OUTPUT ps_main8(PS_INPUT input) // triangular
|
2011-02-19 10:57:28 +00:00
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
2013-12-22 15:36:47 +00:00
|
|
|
|
2011-02-19 10:57:28 +00:00
|
|
|
uint4 p = (uint4)input.p;
|
|
|
|
|
2014-01-11 23:17:07 +00:00
|
|
|
// output.c = ps_crt(input, ((p.x + (p.y & 1) * 3) >> 1) % 3);
|
|
|
|
output.c = ps_crt(input, ((p.x + ((p.y >> 1) & 1) * 3) >> 1) % 3);
|
2011-02-19 10:57:28 +00:00
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2014-01-12 19:47:49 +00:00
|
|
|
static const float PI = 3.14159265359f;
|
|
|
|
PS_OUTPUT ps_main9(PS_INPUT input) // triangular
|
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
|
|
|
float2 texdim, halfpixel;
|
|
|
|
Texture.GetDimensions(texdim.x, texdim.y);
|
|
|
|
if (ddy(input.t.y) * texdim.y > 0.5)
|
|
|
|
output.c = sample_c(input.t);
|
|
|
|
else
|
2014-01-13 18:23:53 +00:00
|
|
|
output.c = (0.9 - 0.4 * cos(2 * PI * input.t.y * texdim.y)) * sample_c(float2(input.t.x, (floor(input.t.y * texdim.y) + 0.5) / texdim.y));
|
2014-01-12 19:47:49 +00:00
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2018-09-10 20:05:48 +00:00
|
|
|
// DUMMY SHADERS START
|
|
|
|
PS_OUTPUT ps_main10(PS_INPUT input)
|
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
|
|
|
output.c = input.p;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_OUTPUT ps_main11(PS_INPUT input)
|
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
|
|
|
output.c = input.p;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_OUTPUT ps_main12(PS_INPUT input)
|
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
|
|
|
output.c = input.p;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_OUTPUT ps_main13(PS_INPUT input)
|
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
|
|
|
output.c = input.p;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_OUTPUT ps_main14(PS_INPUT input)
|
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
|
|
|
output.c = input.p;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_OUTPUT ps_main15(PS_INPUT input)
|
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
|
|
|
output.c = input.p;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_OUTPUT ps_main16(PS_INPUT input)
|
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
|
|
|
output.c = input.p;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
// DUMMY SHADERS END
|
|
|
|
|
|
|
|
PS_OUTPUT ps_main17(PS_INPUT input)
|
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
|
|
|
// Potential speed optimization. There is a high probability that
|
|
|
|
// game only want to extract a single channel (blue). It will allow
|
|
|
|
// to remove most of the conditional operation and yield a +2/3 fps
|
|
|
|
// boost on MGS3
|
|
|
|
//
|
|
|
|
// Hypothesis wrong in Prince of Persia ... Seriously WTF !
|
|
|
|
//#define ONLY_BLUE;
|
|
|
|
|
|
|
|
// Convert a RGBA texture into a 8 bits packed texture
|
|
|
|
// Input column: 8x2 RGBA pixels
|
|
|
|
// 0: 8 RGBA
|
|
|
|
// 1: 8 RGBA
|
|
|
|
// Output column: 16x4 Index pixels
|
|
|
|
// 0: 8 R | 8 B
|
|
|
|
// 1: 8 R | 8 B
|
|
|
|
// 2: 8 G | 8 A
|
|
|
|
// 3: 8 G | 8 A
|
|
|
|
float c;
|
|
|
|
|
|
|
|
uint2 sel = uint2(input.p.xy) % uint2(16u, 16u);
|
|
|
|
int2 tb = ((int2(input.p.xy) & ~int2(15, 3)) >> 1);
|
|
|
|
|
|
|
|
int ty = tb.y | (int(input.p.y) & 1);
|
|
|
|
int txN = tb.x | (int(input.p.x) & 7);
|
|
|
|
int txH = tb.x | ((int(input.p.x) + 4) & 7);
|
|
|
|
|
2018-10-12 06:06:17 +00:00
|
|
|
txN *= PS_SCALE_FACTOR;
|
|
|
|
txH *= PS_SCALE_FACTOR;
|
|
|
|
ty *= PS_SCALE_FACTOR;
|
2018-09-10 20:05:48 +00:00
|
|
|
|
|
|
|
// TODO investigate texture gather
|
|
|
|
float4 cN = Texture.Load(int3(txN, ty, 0));
|
|
|
|
float4 cH = Texture.Load(int3(txH, ty, 0));
|
|
|
|
|
|
|
|
|
|
|
|
if ((sel.y & 4u) == 0u)
|
|
|
|
{
|
|
|
|
#ifdef ONLY_BLUE
|
|
|
|
c = cN.b;
|
|
|
|
#else
|
|
|
|
// Column 0 and 2
|
|
|
|
if ((sel.y & 3u) < 2u)
|
|
|
|
{
|
|
|
|
// First 2 lines of the col
|
|
|
|
if (sel.x < 8u)
|
|
|
|
c = cN.r;
|
|
|
|
else
|
|
|
|
c = cN.b;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (sel.x < 8u)
|
|
|
|
c = cH.g;
|
|
|
|
else
|
|
|
|
c = cH.a;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef ONLY_BLUE
|
|
|
|
c = cH.b;
|
|
|
|
#else
|
|
|
|
// Column 1 and 3
|
|
|
|
if ((sel.y & 3u) < 2u)
|
|
|
|
{
|
|
|
|
// First 2 lines of the col
|
|
|
|
if (sel.x < 8u)
|
|
|
|
c = cH.r;
|
|
|
|
else
|
|
|
|
c = cH.b;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (sel.x < 8u)
|
|
|
|
c = cN.g;
|
|
|
|
else
|
|
|
|
c = cN.a;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
output.c = (float4)(c); // Divide by something here?
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2011-02-19 10:57:28 +00:00
|
|
|
#elif SHADER_MODEL <= 0x300
|
|
|
|
|
|
|
|
PS_OUTPUT ps_main1(PS_INPUT input)
|
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
|
|
|
float4 c = sample_c(input.t);
|
|
|
|
|
|
|
|
c.a *= 128.0f / 255; // *= 0.5f is no good here, need to do this in order to get 0x80 for 1.0f (instead of 0x7f)
|
|
|
|
|
|
|
|
output.c = c;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_OUTPUT ps_main2(PS_INPUT input)
|
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
|
|
|
clip(sample_c(input.t).a - 255.0f / 255); // >= 0x80 pass
|
|
|
|
|
|
|
|
output.c = 0;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_OUTPUT ps_main3(PS_INPUT input)
|
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
|
|
|
clip(254.95f / 255 - sample_c(input.t).a); // < 0x80 pass (== 0x80 should not pass)
|
|
|
|
|
|
|
|
output.c = 0;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_OUTPUT ps_main4(PS_INPUT input)
|
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
|
|
|
output.c = 1;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2014-01-11 23:17:07 +00:00
|
|
|
PS_OUTPUT ps_main5(PS_INPUT input) // scanlines
|
2011-02-19 10:57:28 +00:00
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
|
|
|
int4 p = (int4)input.p;
|
|
|
|
|
2014-01-11 23:17:07 +00:00
|
|
|
output.c = ps_scanlines(input, p.y % 2);
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_OUTPUT ps_main6(PS_INPUT input) // diagonal
|
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
|
|
|
int4 p = (int4)input.p;
|
|
|
|
|
|
|
|
output.c = ps_crt(input, (p.x + (p.y % 3)) % 3);
|
|
|
|
|
2011-02-19 10:57:28 +00:00
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2014-01-11 23:17:07 +00:00
|
|
|
PS_OUTPUT ps_main8(PS_INPUT input) // triangular
|
2011-02-19 10:57:28 +00:00
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
2013-12-22 15:36:47 +00:00
|
|
|
|
2011-02-19 10:57:28 +00:00
|
|
|
int4 p = (int4)input.p;
|
|
|
|
|
2014-01-11 23:17:07 +00:00
|
|
|
// output.c = ps_crt(input, ((p.x + (p.y % 2) * 3) / 2) % 3);
|
|
|
|
output.c = ps_crt(input, ((p.x + ((p.y / 2) % 2) * 3) / 2) % 3);
|
2013-12-22 15:36:47 +00:00
|
|
|
|
2011-02-19 10:57:28 +00:00
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2014-01-12 19:47:49 +00:00
|
|
|
static const float PI = 3.14159265359f;
|
|
|
|
PS_OUTPUT ps_main9(PS_INPUT input) // triangular
|
|
|
|
{
|
|
|
|
PS_OUTPUT output;
|
|
|
|
|
2014-01-13 17:48:43 +00:00
|
|
|
// Needs DX9 conversion
|
|
|
|
/*float2 texdim, halfpixel;
|
2014-01-12 19:47:49 +00:00
|
|
|
Texture.GetDimensions(texdim.x, texdim.y);
|
|
|
|
if (ddy(input.t.y) * texdim.y > 0.5)
|
|
|
|
output.c = sample_c(input.t);
|
|
|
|
else
|
|
|
|
output.c = (0.5 - 0.5 * cos(2 * PI * input.t.y * texdim.y)) * sample_c(float2(input.t.x, (floor(input.t.y * texdim.y) + 0.5) / texdim.y));
|
2014-01-13 17:48:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// replacement shader
|
|
|
|
int4 p = (int4)input.p;
|
|
|
|
output.c = ps_crt(input, ((p.x + ((p.y / 2) % 2) * 3) / 2) % 3);
|
2014-01-12 19:47:49 +00:00
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2011-02-19 10:57:28 +00:00
|
|
|
#endif
|
|
|
|
#endif
|