pcsx2/bin/resources/shaders/dx11/present.fx

149 lines
2.5 KiB
HLSL

#ifdef SHADER_MODEL // make safe to include in resource file to enforce dependency
#ifndef PS_SCALE_FACTOR
#define PS_SCALE_FACTOR 1
#endif
struct VS_INPUT
{
float4 p : POSITION;
float2 t : TEXCOORD0;
float4 c : COLOR;
};
struct VS_OUTPUT
{
float4 p : SV_Position;
float2 t : TEXCOORD0;
float4 c : COLOR;
};
cbuffer cb0 : register(b0)
{
float4 u_source_rect;
float4 u_target_rect;
float2 u_source_size;
float2 u_target_size;
float2 u_target_resolution;
float2 u_rcp_target_resolution; // 1 / u_target_resolution
float2 u_source_resolution;
float2 u_rcp_source_resolution; // 1 / u_source_resolution
float u_time;
float3 cb0_pad0;
};
Texture2D Texture;
SamplerState TextureSampler;
float4 sample_c(float2 uv)
{
return Texture.Sample(TextureSampler, uv);
}
struct PS_INPUT
{
float4 p : SV_Position;
float2 t : TEXCOORD0;
float4 c : COLOR;
};
struct PS_OUTPUT
{
float4 c : SV_Target0;
};
VS_OUTPUT vs_main(VS_INPUT input)
{
VS_OUTPUT output;
output.p = input.p;
output.t = input.t;
output.c = input.c;
return output;
}
PS_OUTPUT ps_copy(PS_INPUT input)
{
PS_OUTPUT output;
output.c = sample_c(input.t);
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);
}
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);
}
PS_OUTPUT ps_filter_scanlines(PS_INPUT input)
{
PS_OUTPUT output;
uint4 p = (uint4)input.p;
output.c = ps_scanlines(input, p.y % 2);
return output;
}
PS_OUTPUT ps_filter_diagonal(PS_INPUT input)
{
PS_OUTPUT output;
uint4 p = (uint4)input.p;
output.c = ps_crt(input, (p.x + (p.y % 3)) % 3);
return output;
}
PS_OUTPUT ps_filter_triangular(PS_INPUT input)
{
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;
}
static const float PI = 3.14159265359f;
PS_OUTPUT ps_filter_complex(PS_INPUT input) // triangular
{
PS_OUTPUT output;
float2 texdim, halfpixel;
Texture.GetDimensions(texdim.x, texdim.y);
if (ddy(input.t.y) * input.t.y > 0.5)
output.c = sample_c(input.t);
else
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));
return output;
}
#endif