pcsx2/plugins/GSdx/res/convert.fx

256 lines
3.8 KiB
HLSL

#ifdef SHADER_MODEL // make safe to include in resource file to enforce dependency
#if SHADER_MODEL >= 0x400
struct VS_INPUT
{
float4 p : POSITION;
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
{
float4 p : POSITION;
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;
}
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;
}
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);
}
#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;
clip(sample_c(input.t).a - 128.0f / 255); // >= 0x80 pass
output.c = 0;
return output;
}
PS_OUTPUT ps_main3(PS_INPUT input)
{
PS_OUTPUT output;
clip(127.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 = fmod(sample_c(input.t) * 255 + 0.5f, 256) / 255;
return output;
}
PS_OUTPUT ps_main5(PS_INPUT input) // triangular
{
PS_OUTPUT output;
uint4 p = (uint4)input.p;
// 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);
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);
return output;
}
#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;
}
PS_OUTPUT ps_main5(PS_INPUT input) // triangular
{
PS_OUTPUT output;
int4 p = (int4)input.p;
// 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);
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);
return output;
}
#endif
#endif