2015-05-12 09:18:09 +02:00
|
|
|
// license:BSD-3-Clause
|
2016-02-20 21:58:56 +01:00
|
|
|
// copyright-holders:Ryan Holtz,Themaister,ImJezze
|
2011-05-30 23:10:23 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
2016-02-20 21:58:56 +01:00
|
|
|
// Pre-scale Effect
|
|
|
|
//
|
|
|
|
// Uses the hardware bilinear interpolator to avoid having to sample 4 times manually.
|
|
|
|
//
|
|
|
|
// https://github.com/libretro/common-shaders/blob/master/retro/shaders/sharp-bilinear.cg
|
2015-12-31 16:32:35 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Sampler Definitions
|
2011-05-30 23:10:23 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
texture Diffuse;
|
|
|
|
|
|
|
|
sampler DiffuseSampler = sampler_state
|
|
|
|
{
|
|
|
|
Texture = <Diffuse>;
|
2016-02-20 21:58:56 +01:00
|
|
|
MipFilter = LINEAR;
|
|
|
|
MinFilter = LINEAR;
|
|
|
|
MagFilter = LINEAR;
|
2011-05-30 23:10:23 +02:00
|
|
|
AddressU = CLAMP;
|
|
|
|
AddressV = CLAMP;
|
|
|
|
AddressW = CLAMP;
|
|
|
|
};
|
|
|
|
|
2023-01-28 17:59:25 +01:00
|
|
|
sampler PointSampler = sampler_state
|
|
|
|
{
|
|
|
|
Texture = <Diffuse>;
|
|
|
|
MipFilter = POINT;
|
|
|
|
MinFilter = POINT;
|
|
|
|
MagFilter = POINT;
|
|
|
|
AddressU = CLAMP;
|
|
|
|
AddressV = CLAMP;
|
|
|
|
AddressW = CLAMP;
|
|
|
|
};
|
|
|
|
|
2011-05-30 23:10:23 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Vertex Definitions
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
struct VS_OUTPUT
|
|
|
|
{
|
|
|
|
float4 Position : POSITION;
|
|
|
|
float2 TexCoord : TEXCOORD0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VS_INPUT
|
|
|
|
{
|
|
|
|
float4 Position : POSITION;
|
|
|
|
float4 Color : COLOR0;
|
|
|
|
float2 TexCoord : TEXCOORD0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PS_INPUT
|
|
|
|
{
|
|
|
|
float2 TexCoord : TEXCOORD0;
|
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2016-02-20 21:58:56 +01:00
|
|
|
// Pre-scale Vertex Shader
|
2011-05-30 23:10:23 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2013-08-28 02:36:02 +02:00
|
|
|
uniform float2 ScreenDims;
|
2015-12-31 16:59:23 +01:00
|
|
|
uniform float2 TargetDims;
|
2016-02-20 21:58:56 +01:00
|
|
|
uniform float2 SourceDims;
|
2011-05-30 23:10:23 +02:00
|
|
|
|
|
|
|
VS_OUTPUT vs_main(VS_INPUT Input)
|
|
|
|
{
|
|
|
|
VS_OUTPUT Output = (VS_OUTPUT)0;
|
2016-02-07 13:40:24 +01:00
|
|
|
|
2011-05-30 23:10:23 +02:00
|
|
|
Output.Position = float4(Input.Position.xyz, 1.0f);
|
2013-08-28 02:36:02 +02:00
|
|
|
Output.Position.xy /= ScreenDims;
|
2015-12-31 16:59:23 +01:00
|
|
|
Output.Position.y = 1.0f - Output.Position.y; // flip y
|
|
|
|
Output.Position.xy -= 0.5f; // center
|
|
|
|
Output.Position.xy *= 2.0f; // zoom
|
2016-02-07 13:40:24 +01:00
|
|
|
|
2015-12-31 16:59:23 +01:00
|
|
|
Output.TexCoord = Input.TexCoord;
|
2016-03-12 16:03:28 +01:00
|
|
|
Output.TexCoord += 0.5f / TargetDims; // half texel offset correction (DX9)
|
2011-05-30 23:10:23 +02:00
|
|
|
|
|
|
|
return Output;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2016-02-20 21:58:56 +01:00
|
|
|
// Pre-scale Pixel Shader
|
2011-05-30 23:10:23 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
float4 ps_main(PS_INPUT Input) : COLOR
|
|
|
|
{
|
2016-02-20 21:58:56 +01:00
|
|
|
float2 Scale = TargetDims / SourceDims;
|
|
|
|
|
|
|
|
float2 TexelDims = Input.TexCoord * SourceDims;
|
|
|
|
float2 i = floor(TexelDims);
|
|
|
|
float2 s = frac(TexelDims);
|
|
|
|
|
|
|
|
// Figure out where in the texel to sample to get the correct pre-scaled bilinear.
|
|
|
|
float2 CenterDistance = s - 0.5f;
|
|
|
|
float2 RegionRange = 0.5f - 0.5f / Scale;
|
|
|
|
float2 f = (CenterDistance - clamp(CenterDistance, -RegionRange, RegionRange)) * Scale + 0.5f;
|
|
|
|
|
|
|
|
float2 TexCoord = (i + f) / SourceDims;
|
|
|
|
|
|
|
|
return tex2D(DiffuseSampler, TexCoord);
|
2011-05-30 23:10:23 +02:00
|
|
|
}
|
|
|
|
|
2023-01-28 17:59:25 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Pre-scale Pixel Shader (point sampling)
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
float4 ps_point_main(PS_INPUT Input) : COLOR
|
|
|
|
{
|
|
|
|
return tex2D(PointSampler, Input.TexCoord);
|
|
|
|
}
|
|
|
|
|
2011-05-30 23:10:23 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
2016-02-20 21:58:56 +01:00
|
|
|
// Pre-scale Technique
|
2011-05-30 23:10:23 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2015-12-31 16:32:35 +01:00
|
|
|
technique DefaultTechnique
|
2011-05-30 23:10:23 +02:00
|
|
|
{
|
|
|
|
pass Pass0
|
|
|
|
{
|
|
|
|
Lighting = FALSE;
|
|
|
|
|
|
|
|
VertexShader = compile vs_3_0 vs_main();
|
|
|
|
PixelShader = compile ps_3_0 ps_main();
|
|
|
|
}
|
2016-02-28 18:59:10 +01:00
|
|
|
}
|
2023-01-28 17:59:25 +01:00
|
|
|
|
|
|
|
technique PointTechnique
|
|
|
|
{
|
|
|
|
pass Pass0
|
|
|
|
{
|
|
|
|
Lighting = FALSE;
|
|
|
|
|
|
|
|
VertexShader = compile vs_3_0 vs_main();
|
|
|
|
PixelShader = compile ps_3_0 ps_point_main();
|
|
|
|
}
|
|
|
|
}
|