Project

General

Profile

Emulator Issues #12725 » 0_IntegerScalingOPTIONS.glsl

taolas, 06/06/2022 08:55 AM

 
// Set aspect ratio to 'stretch'.

/*
[configuration]
[OptionBool]
GUIName = Please Set Aspect Ratio to Stretch
OptionName = AMPTY
DefaultValue = false

[OptionBool]
GUIName = Allow Downscale
OptionName = DOWNSCALE
DefaultValue = false

[OptionBool]
GUIName = Unlock Width
OptionName = WIDTH_SKIP
DefaultValue = false

[OptionBool]
GUIName = Scale Width to fit 4:3
OptionName = WIDTH_43
DefaultValue = false

[OptionBool]
GUIName = Apply sharp bilinear when width changes
OptionName = SHARP_BILINEAR
DefaultValue = false

[OptionBool]
GUIName = Manual Scale
OptionName = MANUALSCALE
DefaultValue = false

[OptionRangeFloat]
GUIName = Integer Scale
OptionName = INTEGER_SCALE
DependentOption = MANUALSCALE
MaxValue = 5.0
MinValue = 1.0
DefaultValue = 1.0
StepAmount = 1.0
[/configuration]
*/

void main()
{
float4 c0 = float4(0.0, 0.0, 0.0, 0.0);
float scale = 1.0;
float2 ratio = GetWindowResolution()/GetResolution();
if (OptionEnabled(WIDTH_SKIP))
ratio.x = 1.0;
else if (OptionEnabled(WIDTH_43))
ratio.x = GetWindowResolution().x / (GetResolution().y * 4/3);
if ( OptionEnabled(MANUALSCALE))
{
float calc_ir = ceil(GetResolution().y / 500);
scale = calc_ir / GetOption(INTEGER_SCALE);
ratio = ratio * float2(scale, scale);
}
else if ( OptionEnabled(DOWNSCALE) && (ratio.x < 1 || ratio.y < 1))
{
scale = ceil(max(1.0/ratio.y, 1.0/ratio.x));
ratio = ratio * float2(scale, scale);
}
float y = GetWindowResolution().y - GetResolution().y / scale;
float y_top = (y / 2.0) * GetInvWindowResolution().y;
float y_bottom = (GetWindowResolution().y - y / 2.0) * GetInvWindowResolution().y;
float yloc = GetCoordinates().y * ratio.y - y_top * ratio.y;
float x = GetWindowResolution().x - GetResolution().x / scale;
if (OptionEnabled(WIDTH_SKIP))
x = 0.0;
else if (OptionEnabled(WIDTH_43))
x = GetWindowResolution().x - GetResolution().y / scale * 4 / 3;

float x_left = (x / 2.0) * GetInvWindowResolution().x;
float x_right = (GetWindowResolution().x - x / 2.0) * GetInvWindowResolution().x;
float xloc = GetCoordinates().x * ratio.x - x_left * ratio.x;
if (OptionEnabled(SHARP_BILINEAR) && (OptionEnabled(WIDTH_SKIP) || OptionEnabled(WIDTH_43)))
{
float source_size = GetResolution().x;
float texel = xloc * source_size.x;
float texel_floored = floor(texel);
float s = frac(texel);
float scale = ceil(GetWindowResolution().x / source_size.x);
if (OptionEnabled(WIDTH_43))
scale = GetWindowResolution().x / (4/3 * GetResolution().y);
float region_range = 0.5 - 0.5 / scale;
float center_dist = s - 0.5;
float f = (center_dist - clamp(center_dist, -region_range, region_range)) * scale + 0.5;

float mod_texel = texel_floored + f;
xloc = mod_texel / source_size;
}
if (GetCoordinates().x >= x_left && x_right >= GetCoordinates().x && GetCoordinates().y >= y_top && y_bottom >= GetCoordinates().y)
{
float2 sample_loc = float2(xloc, yloc);
c0 = SampleLocation(sample_loc);
}

SetOutput(c0);
}
(4-4/5)