add default auto-pre-scale to sharp-bilinear

This commit is contained in:
hizzlekizzle 2016-12-30 08:28:09 -06:00 committed by GitHub
parent 6918720885
commit 4aa0679176

View file

@ -2,15 +2,19 @@
layout(push_constant) uniform Push layout(push_constant) uniform Push
{ {
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
float SHARP_BILINEAR_PRE_SCALE; float SHARP_BILINEAR_PRE_SCALE;
} param; float AUTO_PRESCALE;
} params;
#pragma parameter SHARP_BILINEAR_PRE_SCALE "Sharp Bilinear Prescale" 4.0 1.0 10.0 1.0
#pragma parameter AUTO_PRESCALE "Automatic Prescale" 1.0 0.0 1.0 1.0
layout(std140, set = 0, binding = 0) uniform UBO layout(std140, set = 0, binding = 0) uniform UBO
{ {
mat4 MVP; mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global; } global;
/* /*
@ -22,8 +26,6 @@ layout(std140, set = 0, binding = 0) uniform UBO
* sharper image than plain bilinear. * sharper image than plain bilinear.
*/ */
#pragma parameter SHARP_BILINEAR_PRE_SCALE "Sharp Bilinear Prescale" 4.0 1.0 10.0 1.0
#pragma stage vertex #pragma stage vertex
layout(location = 0) in vec4 Position; layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord; layout(location = 1) in vec2 TexCoord;
@ -45,13 +47,14 @@ void main()
vec2 texel = vTexCoord * global.SourceSize.xy; vec2 texel = vTexCoord * global.SourceSize.xy;
vec2 texel_floored = floor(texel); vec2 texel_floored = floor(texel);
vec2 s = fract(texel); vec2 s = fract(texel);
float region_range = 0.5 - 0.5 / param.SHARP_BILINEAR_PRE_SCALE; float scale = (AUTO_PRESCALE > 0.5) ? floor(params.OutputSize.y / params.SourceSize.y) : params.SHARP_BILINEAR_PRE_SCALE;
float region_range = 0.5 - 0.5 / scale;
// Figure out where in the texel to sample to get correct pre-scaled bilinear. // Figure out where in the texel to sample to get correct pre-scaled bilinear.
// Uses the hardware bilinear interpolator to avoid having to sample 4 times manually. // Uses the hardware bilinear interpolator to avoid having to sample 4 times manually.
vec2 center_dist = s - 0.5; vec2 center_dist = s - 0.5;
vec2 f = (center_dist - clamp(center_dist, -region_range, region_range)) * param.SHARP_BILINEAR_PRE_SCALE + 0.5; vec2 f = (center_dist - clamp(center_dist, -region_range, region_range)) * scale + 0.5;
vec2 mod_texel = texel_floored + f; vec2 mod_texel = texel_floored + f;