From 59e6aa174a9b99f9b66ca22c684b93207f457e87 Mon Sep 17 00:00:00 2001 From: fishcu Date: Sun, 25 Jun 2023 05:40:26 +0200 Subject: [PATCH] Fix some further scaling bugs in border fill shaders (#458) * Fix more scaling bugs in border fill shaders * Fix numerical issues; Remove useless mipmap --- border/blur_fill.slangp | 2 +- border/blur_fill_stronger_blur.slangp | 2 +- border/blur_fill_weaker_blur.slangp | 2 +- border/shaders/average_fill/compose.slang | 3 +- border/shaders/average_fill/parameters.slang | 12 ++-- border/shaders/blur_fill/compose.slang | 3 +- border/shaders/blur_fill/parameters.slang | 10 +-- border/shaders/blur_fill/scaling.slang | 65 +++++++++----------- 8 files changed, 46 insertions(+), 53 deletions(-) diff --git a/border/blur_fill.slangp b/border/blur_fill.slangp index 60c9a67..2d4c312 100644 --- a/border/blur_fill.slangp +++ b/border/blur_fill.slangp @@ -80,7 +80,7 @@ filter_linear10 = true scale_type10 = viewport scale10 = 1.0 float_framebuffer10 = true -mipmap_input10 = true +wrap_mode10 = mirrored_repeat shader11 = ../blurs/shaders/kawase/delinearize.slang filter_linear11 = true diff --git a/border/blur_fill_stronger_blur.slangp b/border/blur_fill_stronger_blur.slangp index ed68c11..1844874 100644 --- a/border/blur_fill_stronger_blur.slangp +++ b/border/blur_fill_stronger_blur.slangp @@ -80,7 +80,7 @@ filter_linear10 = true scale_type10 = viewport scale10 = 1.0 float_framebuffer10 = true -mipmap_input10 = true +wrap_mode10 = mirrored_repeat shader11 = ../blurs/shaders/kawase/delinearize.slang filter_linear11 = true diff --git a/border/blur_fill_weaker_blur.slangp b/border/blur_fill_weaker_blur.slangp index 04fdd6c..7c9e171 100644 --- a/border/blur_fill_weaker_blur.slangp +++ b/border/blur_fill_weaker_blur.slangp @@ -80,7 +80,7 @@ filter_linear10 = true scale_type10 = viewport scale10 = 1.0 float_framebuffer10 = true -mipmap_input10 = true +wrap_mode10 = mirrored_repeat shader11 = ../blurs/shaders/kawase/delinearize.slang filter_linear11 = true diff --git a/border/shaders/average_fill/compose.slang b/border/shaders/average_fill/compose.slang index bf0ec3c..27d06a9 100644 --- a/border/shaders/average_fill/compose.slang +++ b/border/shaders/average_fill/compose.slang @@ -1,7 +1,7 @@ #version 450 /* - Average fill v1.2 by fishku + Average fill v1.3 by fishku Copyright (C) 2023 Public domain license (CC0) @@ -27,6 +27,7 @@ 3 = Smooth angle-based blending Changelog: + v1.3: Fix scaling bugs. v1.2: Fix scaling bugs. v1.1: Add extension modes from blur fill; Add average gamma adjustment. v1.0: Initial release. diff --git a/border/shaders/average_fill/parameters.slang b/border/shaders/average_fill/parameters.slang index 79261e0..f937f0e 100644 --- a/border/shaders/average_fill/parameters.slang +++ b/border/shaders/average_fill/parameters.slang @@ -1,9 +1,9 @@ // See compose.slang for copyright and other information. // clang-format off -#pragma parameter AVERAGE_FILL_SETTINGS "=== Average fill v1.2 settings ===" 0.0 0.0 1.0 1.0 -#pragma parameter OS_CROP_TOP "Overscan crop top" 8.0 0.0 1024.0 1.0 -#pragma parameter OS_CROP_BOTTOM "Overscan crop bottom" 8.0 0.0 1024.0 1.0 +#pragma parameter AVERAGE_FILL_SETTINGS "=== Average fill v1.3 settings ===" 0.0 0.0 1.0 1.0 +#pragma parameter OS_CROP_TOP "Overscan crop top" 0.0 0.0 1024.0 1.0 +#pragma parameter OS_CROP_BOTTOM "Overscan crop bottom" 0.0 0.0 1024.0 1.0 #pragma parameter OS_CROP_LEFT "Overscan crop left" 0.0 0.0 1024.0 1.0 #pragma parameter OS_CROP_RIGHT "Overscan crop right" 0.0 0.0 1024.0 1.0 @@ -16,9 +16,9 @@ #pragma parameter CORNER_BLEND_MODE "Cropped corner blend mode" 0.0 0.0 3.0 1.0 -#pragma parameter FORCE_ASPECT_RATIO "Force aspect ratio" 0.0 0.0 1.0 1.0 -#pragma parameter ASPECT_H "Horizontal aspect ratio before crop" 4.0 1.0 100.0 1.0 -#pragma parameter ASPECT_V "Vertical aspect ratio before crop" 3.0 1.0 100.0 1.0 +#pragma parameter FORCE_ASPECT_RATIO "Force aspect ratio" 1.0 0.0 1.0 1.0 +#pragma parameter ASPECT_H "Horizontal aspect ratio before crop (0 = original)" 0.0 0.0 256.0 1.0 +#pragma parameter ASPECT_V "Vertical aspect ratio before crop (0 = original)" 0.0 0.0 256.0 1.0 #pragma parameter FORCE_INTEGER_SCALING "Force integer scaling" 1.0 0.0 1.0 1.0 #pragma parameter FILL_GAMMA "Background fill gamma adjustment" 1.0 0.5 2.0 0.1 diff --git a/border/shaders/blur_fill/compose.slang b/border/shaders/blur_fill/compose.slang index 372008a..0c3959d 100644 --- a/border/shaders/blur_fill/compose.slang +++ b/border/shaders/blur_fill/compose.slang @@ -1,7 +1,7 @@ #version 450 /* - Blur fill v1.3 by fishku + Blur fill v1.4 by fishku Copyright (C) 2023 Public domain license (CC0) @@ -27,6 +27,7 @@ strength of the blur. Changelog: + v1.4: Fix scaling bugs. v1.3: Reduce shimmering artifacts. v1.2: Fix scaling bugs. v1.1: Fix bug with glcore driver. diff --git a/border/shaders/blur_fill/parameters.slang b/border/shaders/blur_fill/parameters.slang index 41ce08f..ee49f16 100644 --- a/border/shaders/blur_fill/parameters.slang +++ b/border/shaders/blur_fill/parameters.slang @@ -1,7 +1,7 @@ // See compose.slang for copyright and other information. // clang-format off -#pragma parameter BLUR_FILL_SETTINGS "=== Blur fill v1.3 settings ===" 0.0 0.0 1.0 1.0 +#pragma parameter BLUR_FILL_SETTINGS "=== Blur fill v1.4 settings ===" 0.0 0.0 1.0 1.0 #pragma parameter OS_CROP_TOP "Overscan crop top" 0.0 0.0 1024.0 1.0 #pragma parameter OS_CROP_BOTTOM "Overscan crop bottom" 0.0 0.0 1024.0 1.0 #pragma parameter OS_CROP_LEFT "Overscan crop left" 0.0 0.0 1024.0 1.0 @@ -11,13 +11,13 @@ #pragma parameter SAMPLE_SIZE "No. of lines for rendering the blur" 16.0 1.0 1024.0 1.0 -#pragma parameter BLUR_EXTEND_H "Extend the blur horizontally" 0.0 0.0 1.0 1.0 +#pragma parameter BLUR_EXTEND_H "Extend the blur horizontally" 1.0 0.0 1.0 1.0 #pragma parameter BLUR_EXTEND_V "Extend the blur vertically" 1.0 0.0 1.0 1.0 #pragma parameter MIRROR_BLUR "Mirror the blur" 0.0 0.0 1.0 1.0 -#pragma parameter FORCE_ASPECT_RATIO "Force aspect ratio" 0.0 0.0 1.0 1.0 -#pragma parameter ASPECT_H "Horizontal aspect ratio before crop" 4.0 1.0 100.0 1.0 -#pragma parameter ASPECT_V "Vertical aspect ratio before crop" 3.0 1.0 100.0 1.0 +#pragma parameter FORCE_ASPECT_RATIO "Force aspect ratio" 1.0 0.0 1.0 1.0 +#pragma parameter ASPECT_H "Horizontal aspect ratio before crop (0 = original)" 0.0 0.0 256.0 1.0 +#pragma parameter ASPECT_V "Vertical aspect ratio before crop (0 = original)" 0.0 0.0 256.0 1.0 #pragma parameter FORCE_INTEGER_SCALING "Force integer scaling" 1.0 0.0 1.0 1.0 #pragma parameter FILL_GAMMA "Background fill gamma adjustment" 1.4 0.5 2.0 0.1 diff --git a/border/shaders/blur_fill/scaling.slang b/border/shaders/blur_fill/scaling.slang index 3f13db0..de0c9c1 100644 --- a/border/shaders/blur_fill/scaling.slang +++ b/border/shaders/blur_fill/scaling.slang @@ -1,5 +1,11 @@ // See compose.slang for copyright and other information. +void apply_integer_scaling(inout float x) { + if (param.FORCE_INTEGER_SCALING > 0.5 && x > 1.0) { + x = floor(x); + } +} + // Scaling from unit output to pixel input space. vec2 scale_o2i() { // Pixels in input coord. space, after cropping. @@ -10,58 +16,43 @@ vec2 scale_o2i() { param.OS_CROP_TOP + param.OS_CROP_BOTTOM) : 2 * vec2(min(param.OS_CROP_LEFT, param.OS_CROP_RIGHT), min(param.OS_CROP_TOP, param.OS_CROP_BOTTOM))); - // Integer aspect ratio after cropping. + // Aspect ratio before cropping. // lambda_1 * input_pixels.x, lambda_2 * input_pixels.y, // possibly corrected for forced aspect ratio - const vec2 eff_aspect = param.FORCE_ASPECT_RATIO < 0.5 - ? eff_input_res - : vec2(eff_input_res.x * param.ASPECT_H, - eff_input_res.y * param.ASPECT_V); + const vec2 eff_aspect = + (param.FORCE_ASPECT_RATIO < 0.5 + ? param.FinalViewportSize.xy * param.InputSize.yx + : (param.ASPECT_H < 0.5 || param.ASPECT_V < 0.5 + ? vec2(1.0) + : vec2(param.ASPECT_H, param.ASPECT_V) * + param.InputSize.yx)); float scale_x, scale_y; - if (param.FinalViewportSize.x * eff_aspect.y < - param.FinalViewportSize.y * eff_aspect.x) { + if (param.FinalViewportSize.x / (eff_input_res.x * eff_aspect.x) < + param.FinalViewportSize.y / (eff_input_res.y * eff_aspect.y)) { // Scale will be limited by width. Calc x scale, then derive y scale // using aspect ratio. scale_x = param.FinalViewportSize.x / eff_input_res.x; - if (param.FORCE_INTEGER_SCALING > 0.5) { - scale_x = max(1.0, floor(scale_x)); - } - if (param.FORCE_ASPECT_RATIO < 0.5) { - scale_y = scale_x; - } else { - scale_y = scale_x * param.ASPECT_V / param.ASPECT_H; - if (param.FORCE_INTEGER_SCALING > 0.5) { - scale_y = max(1.0, floor(scale_y)); - } - } + apply_integer_scaling(scale_x); + scale_y = scale_x * eff_aspect.y / eff_aspect.x; + apply_integer_scaling(scale_y); } else { // Scale will be limited by height. scale_y = param.FinalViewportSize.y / eff_input_res.y; - if (param.FORCE_INTEGER_SCALING > 0.5) { - scale_y = max(1.0, floor(scale_y)); - } - if (param.FORCE_ASPECT_RATIO < 0.5) { - scale_x = scale_y; - } else { - scale_x = scale_y * param.ASPECT_H / param.ASPECT_V; - if (param.FORCE_INTEGER_SCALING > 0.5) { - scale_x = max(1.0, floor(scale_x)); - } - } + apply_integer_scaling(scale_y); + scale_x = scale_y * eff_aspect.x / eff_aspect.y; + apply_integer_scaling(scale_x); } return param.FinalViewportSize.xy / vec2(scale_x, scale_y); } // Get adjusted center in input pixel coordinate system. -// Round to whole pixels to avoid issues on low-res output resolutions, e.g., -// when using a 10x by 1x horizontal superresolution. vec2 get_input_center() { - return floor(param.CENTER_CROP > 0.5 - ? 0.5 * vec2(param.OS_CROP_LEFT + param.InputSize.x - - param.OS_CROP_RIGHT, - param.OS_CROP_TOP + param.InputSize.y - - param.OS_CROP_BOTTOM) - : vec2(0.49999) * param.InputSize.xy); + return param.CENTER_CROP > 0.5 + ? 0.5 * vec2(param.OS_CROP_LEFT + param.InputSize.x - + param.OS_CROP_RIGHT, + param.OS_CROP_TOP + param.InputSize.y - + param.OS_CROP_BOTTOM) + : vec2(0.49999) * param.InputSize.xy; } // From unit output to pixel input space.