rendered paste body#if SHADER_MODEL >= 0x400
#define COLOR SV_Target0
Texture2D Texture;
SamplerState Sampler;
float4 sample(float2 t)
{
return Texture.Sample(Sampler, t);
}
#else
sampler Texture : register(s0);
float4 sample(float2 t)
{
return tex2D(Texture, t);
}
#endif
float2 texsize : register(c100);
struct VS_INPUT
{
float4 p : POSITION;
float2 t : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 p : POSITION;
float2 pp : TEXCOORD1;
float2 t : TEXCOORD0;
};
struct PS_INPUT
{
float2 p : TEXCOORD1;
float2 t : TEXCOORD0;
};
VS_OUTPUT vs_main(VS_INPUT input)
{
VS_OUTPUT output;
output.p = input.p;
output.pp = input.p;
output.t = input.t;
return output;
}
float4 ps_main0(PS_INPUT input) : COLOR
{
return sample(input.t);
}
#if SHADER_MODEL >= 0x400
uint ps_main1(PS_INPUT input) : COLOR
{
float4 f = Texture.Sample(Sampler, input.t);
f.a *= 256.0f/127; // hm, 0.5 won't give us 1.0 if we just multiply with 2
uint4 i = f * float4(0x001f, 0x03e0, 0x7c00, 0x8000);
return (i.x & 0x001f) | (i.y & 0x03e0) | (i.z & 0x7c00) | (i.w & 0x8000);
}
#else
float4 ps_main1(PS_INPUT input) : COLOR
{
float4 c = tex2D(Texture, 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)
return c;
}
#endif
float4 ps_main2(PS_INPUT input) : COLOR
{
// huh?
#if SHADER_MODEL >= 0x400
clip(sample(input.t).a - (0.5 - 0.9f/256));
#else
clip(sample(input.t).a - (1.0 - 0.9f/256));
#endif
// wtf?
return 0;
}
// huh and wtf again
float4 ps_main3(PS_INPUT input) : COLOR
{
#if SHADER_MODEL >= 0x400
clip((0.5 - 0.9f/256) - sample(input.t).a);
#else
clip((1.0 - 0.9f/256) - sample(input.t).a);
#endif
return 0;
}
float4 ps_main4(PS_INPUT input) : COLOR
{
#if SHADER_MODEL >= 0x400
float4 c = sample(input.t);
return fmod(c * 255 + 0.5f, 256) / 255;
#else
// looks right to me!
return 1;
#endif
}
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(input.t) * saturate(mask[i] + 0.5f);
}
float4 ps_main5(PS_INPUT input) : COLOR // triangular
{
int2 p = (int2)input.p;
// return ps_crt(input, ((p.x + (p.y & 1) * 3) >> 1) % 3);
return ps_crt(input, ((p.x + ((p.y / 2) % 2) * 3) / 2) % 3);
// return ps_crt(input, ((p.x + (p.y % 2) * 3) / 2) % 3);
//return ps_crt(input, ((p.x + ((p.y >> 1) & 1) * 3) >> 1) % 3);
}
float4 ps_main6(PS_INPUT input) : COLOR // diagonal
{
int2 p = (int2)input.p;
return ps_crt(input, (p.x + (p.y % 3)) % 3);
}
// guest's SaI (SaL according to guest)
float4 ps_main7(PS_INPUT input) : COLOR
{
const float3 texel = float3(1/texsize, 0);
const float3 htexel = 0.5 * texel;
const float3 qtexel = 0.25 * texel;
float3 dt = float3(1.0, 1.0, 1.0);
float3 c11 = tex2D(Texture, input.t);
float3 c01 = tex2D(Texture, input.t - htexel.xz);
float3 c21 = tex2D(Texture, input.t + htexel.xz);
float3 c10 = tex2D(Texture, input.t - htexel.zy);
float3 c12 = tex2D(Texture, input.t + htexel.zy);
float k1 = dot(abs(c01 - c21), dt);
float k2 = dot(abs(c10 - c12), dt);
return float4(saturate(k1 * (c10 + c12) + k2 * (c01 + c21) + 0.001 * c11) / (2.0 * (k1 + k2) + 0.001), 0);
}
// 8 was gigaherz's broken smartflt thing
// hq4x-alike for dosbox
float4 ps_main9 (PS_INPUT input) : COLOR
{
const float3 texel = float3(1/texsize, 0);
const float3 htexel = 0.5 * texel;
const float3 qtexel = 0.25 * texel;
const float3 dt = float3(1.4,1.4,1.4); // I have no fucking idea
const float4 d4 = float4(1,1,1,1);
const float mx = 1.00; // start smoothing wt.
const float k = -1.10; // wt. decrease factor
const float max_w = 0.90; // max filter weigth
const float min_w = 0.05; // min filter weigth
const float lum_add = 0.33; // effects smoothing
float3 c = tex2D(Texture, input.t).xyz;
float3 o1 = tex2D(Texture, input.t - htexel).xyz;
float3 o2 = tex2D(Texture, input.t + htexel * float2( 1, -1)).xyz;
float3 o3 = tex2D(Texture, input.t + htexel).xyz;
float3 o4 = tex2D(Texture, input.t + htexel * float2(-1, 1)).xyz;
float3 i1 = tex2D(Texture, input.t - qtexel).xyz;
float3 i2 = tex2D(Texture, input.t + qtexel * float2( 1, -1)).xyz;
float3 i3 = tex2D(Texture, input.t + qtexel).xyz;
float3 i4 = tex2D(Texture, input.t + qtexel * float2(-1, 1)).xyz;
float3 s1 = tex2D(Texture, input.t - htexel.xz).xyz;
float3 s2 = tex2D(Texture, input.t + htexel.xz).xyz;
float3 s3 = tex2D(Texture, input.t - htexel.zy).xyz;
float3 s4 = tex2D(Texture, input.t + htexel.zy).xyz;
float ko1=dot(abs(o1-c),dt);
float ko2=dot(abs(o2-c),dt);
float ko3=dot(abs(o3-c),dt);
float ko4=dot(abs(o4-c),dt);
float4 w;
w.yw = min(dot(abs(i1-i3),dt),0.6*(ko1+ko3));
w.xz = min(dot(abs(i2-i4),dt),0.6*(ko2+ko4));
if (ko3<ko1) w.x*= ko3/ko1;
if (ko4<ko2) w.y*= ko4/ko2;
if (ko1<ko3) w.z*= ko1/ko3;
if (ko2<ko4) w.w*= ko2/ko4;
c = (w.x*o1+w.y*o2+w.z*o3+w.w*o4+0.001*c)/(dot(w,d4)+0.001);
w.x = k*dot(abs(i1-c)+abs(i3-c),dt)/(0.125*dot(i1+i3,dt)+lum_add);
w.y = k*dot(abs(i2-c)+abs(i4-c),dt)/(0.125*dot(i2+i4,dt)+lum_add);
w.z = k*dot(abs(s1-c)+abs(s2-c),dt)/(0.125*dot(s1+s2,dt)+lum_add);
w.w = k*dot(abs(s3-c)+abs(s4-c),dt)/(0.125*dot(s3+s4,dt)+lum_add);
w.x = clamp(w.x+mx,min_w,max_w);
w.y = clamp(w.y+mx,min_w,max_w);
w.z = clamp(w.z+mx,min_w,max_w);
w.w = clamp(w.w+mx,min_w,max_w);
c = (w.x*(i1+i3)+w.y*(i2+i4)+w.z*(s1+s2)+w.w*(s3+s4)+c)/(2.0*dot(w,d4)+1.0);
return float4(c, 0);
}
float cdist(float3 c1, float3 c2)
{
float3x3 rgb2yuv = {0.299, 0.587, 0.114,
-0.147, -0.289, 0.436,
0.615, -0.515, -0.1};
return length(mul(c1, rgb2yuv) - mul(c2, rgb2yuv));
}
// 10 was a scale2xish thing but it didn't really work very well
// scale2x inspired
float4 ps_main11(PS_INPUT input) : COLOR
{
float3 texel = float3(1 / texsize, 0);
float2 f = frac(input.t * texsize);
if (f.x >= 0.5) {
texel.x = -texel.x;
f.x = 1 - f.x;
}
if (f.y >= 0.5) {
texel.y = -texel.y;
f.y = 1 - f.y;
}
float4 c = tex2D(Texture, input.t);
if (f.x + f.y >= 0.5)
return c;
float4 n = tex2D(Texture, input.t - texel.zy);
float4 w = tex2D(Texture, input.t - texel.xz);
if (cdist(n,c) + cdist(w,c) > 4 * cdist(n, w))
return lerp(w, n, 0.5 + f.x - f.y);
return c;
}
// scale2x inspired
float4 ps_main12(PS_INPUT input) : COLOR
{
float3 texel = float3(1 / texsize, 0);
float2 f = frac(input.t * texsize);
if (f.x >= 0.5) {
texel.x = -texel.x;
f.x = 1 - f.x;
}
if (f.y >= 0.5) {
texel.y = -texel.y;
f.y = 1 - f.y;
}
float4 c = tex2D(Texture, input.t);
float4 n = tex2D(Texture, input.t - texel.zy);
float4 w = tex2D(Texture, input.t - texel.xz);
if (cdist(n,c) + cdist(w,c) > 4 * cdist(n, w))
return lerp(w, n, 0.5 + f.x - f.y);
return c;
}
// 13 was guest's "4xGLSLHqFilter", but 9 is generally superior