From 9aedb6158478aaa48200db495bd7551ff924aa8c Mon Sep 17 00:00:00 2001 From: Isaac Date: Thu, 22 Jun 2023 23:21:54 +0200 Subject: [PATCH 1/3] Add gauss-4tap --- blurs/gauss_4tap.slangp | 13 ++++++++ blurs/shaders/gauss_4tap/common.slang | 21 ++++++++++++ blurs/shaders/gauss_4tap/gauss_2tap_h.slang | 37 +++++++++++++++++++++ blurs/shaders/gauss_4tap/gauss_2tap_v.slang | 37 +++++++++++++++++++++ blurs/shaders/gauss_4tap/parameters.slang | 6 ++++ 5 files changed, 114 insertions(+) create mode 100644 blurs/gauss_4tap.slangp create mode 100644 blurs/shaders/gauss_4tap/common.slang create mode 100644 blurs/shaders/gauss_4tap/gauss_2tap_h.slang create mode 100644 blurs/shaders/gauss_4tap/gauss_2tap_v.slang create mode 100644 blurs/shaders/gauss_4tap/parameters.slang diff --git a/blurs/gauss_4tap.slangp b/blurs/gauss_4tap.slangp new file mode 100644 index 0000000..3753fbc --- /dev/null +++ b/blurs/gauss_4tap.slangp @@ -0,0 +1,13 @@ +shaders = 2 + +shader0 = shaders/gauss_4tap/gauss_2tap_h.slang +filter_linear0 = true +scale_type0 = source +scale0 = 1.0 +wrap_mode0 = mirrored_repeat + +shader1 = shaders/gauss_4tap/gauss_2tap_v.slang +filter_linear1 = true +scale_type1 = source +scale1 = 1.0 +wrap_mode1 = mirrored_repeat diff --git a/blurs/shaders/gauss_4tap/common.slang b/blurs/shaders/gauss_4tap/common.slang new file mode 100644 index 0000000..c603fa8 --- /dev/null +++ b/blurs/shaders/gauss_4tap/common.slang @@ -0,0 +1,21 @@ +/* + Gauss-4tap v1.0 by fishku + Copyright (C) 2023 + Public domain license (CC0) + + Simple two-pass Gaussian blur filter which does two taps per pass. + Idea based on: + https://www.rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/ + + Changelog: + v1.0: Initial release. +*/ + +// Finds the offset so that two samples drawn with linear filtering at that +// offset from a central pixel, multiplied with 1/2 each, sum up to a 3-sample +// approximation of the Gaussian sampled at pixel centers. +float get_offset(float sigma) { + // Weight at x = 0 evaluates to 1 for all values of sigma. + const float w = exp(-1.0 / (sigma * sigma)); + return 2.0 * w / (2.0 * w + 1.0); +} diff --git a/blurs/shaders/gauss_4tap/gauss_2tap_h.slang b/blurs/shaders/gauss_4tap/gauss_2tap_h.slang new file mode 100644 index 0000000..c05fd2e --- /dev/null +++ b/blurs/shaders/gauss_4tap/gauss_2tap_h.slang @@ -0,0 +1,37 @@ +#version 450 + +// See common.slang for copyright and other information. + +#include "parameters.slang" + +layout(push_constant) uniform Push { + vec4 SourceSize; + float SIGMA; +} +param; + +#include "common.slang" + +layout(std140, set = 0, binding = 0) uniform UBO { mat4 MVP; } +global; + +#pragma stage vertex +layout(location = 0) in vec4 Position; +layout(location = 1) in vec2 TexCoord; +layout(location = 0) out vec2 vTexCoord; + +void main() { + gl_Position = global.MVP * Position; + vTexCoord = TexCoord; +} + +#pragma stage fragment +layout(location = 0) in vec2 vTexCoord; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D Source; + +void main() { + const vec2 offset = vec2(get_offset(param.SIGMA) * param.SourceSize.z, 0.0); + FragColor = 0.5 * (texture(Source, vTexCoord - offset) + + texture(Source, vTexCoord + offset)); +} diff --git a/blurs/shaders/gauss_4tap/gauss_2tap_v.slang b/blurs/shaders/gauss_4tap/gauss_2tap_v.slang new file mode 100644 index 0000000..7a8e257 --- /dev/null +++ b/blurs/shaders/gauss_4tap/gauss_2tap_v.slang @@ -0,0 +1,37 @@ +#version 450 + +// See common.slang for copyright and other information. + +#include "parameters.slang" + +layout(push_constant) uniform Push { + vec4 SourceSize; + float SIGMA; +} +param; + +#include "common.slang" + +layout(std140, set = 0, binding = 0) uniform UBO { mat4 MVP; } +global; + +#pragma stage vertex +layout(location = 0) in vec4 Position; +layout(location = 1) in vec2 TexCoord; +layout(location = 0) out vec2 vTexCoord; + +void main() { + gl_Position = global.MVP * Position; + vTexCoord = TexCoord; +} + +#pragma stage fragment +layout(location = 0) in vec2 vTexCoord; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D Source; + +void main() { + const vec2 offset = vec2(0.0, get_offset(param.SIGMA) * param.SourceSize.w); + FragColor = 0.5 * (texture(Source, vTexCoord - offset) + + texture(Source, vTexCoord + offset)); +} diff --git a/blurs/shaders/gauss_4tap/parameters.slang b/blurs/shaders/gauss_4tap/parameters.slang new file mode 100644 index 0000000..09e9cfd --- /dev/null +++ b/blurs/shaders/gauss_4tap/parameters.slang @@ -0,0 +1,6 @@ +// See common.slang for copyright and other information. + +// clang-format off +#pragma parameter GAUSS_4TAP_SETTINGS "=== Gauss-4tap v1.0 settings ===" 0.0 0.0 1.0 1.0 +#pragma parameter SIGMA "Blur radius" 1.0 0.0 2.0 0.05 +// clang-format on From a20a608b85de75c5b5e7e3188cda5c5829c166b8 Mon Sep 17 00:00:00 2001 From: fishcu Date: Thu, 22 Jun 2023 23:37:45 +0200 Subject: [PATCH 2/3] Update parameters.slang --- blurs/shaders/gauss_4tap/parameters.slang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blurs/shaders/gauss_4tap/parameters.slang b/blurs/shaders/gauss_4tap/parameters.slang index 09e9cfd..d00c92d 100644 --- a/blurs/shaders/gauss_4tap/parameters.slang +++ b/blurs/shaders/gauss_4tap/parameters.slang @@ -2,5 +2,5 @@ // clang-format off #pragma parameter GAUSS_4TAP_SETTINGS "=== Gauss-4tap v1.0 settings ===" 0.0 0.0 1.0 1.0 -#pragma parameter SIGMA "Blur radius" 1.0 0.0 2.0 0.05 +#pragma parameter SIGMA "Gaussian filtering sigma" 1.0 0.0 2.0 0.05 // clang-format on From 13f4d9184e4d44cfa885cadc0234d9800579fdeb Mon Sep 17 00:00:00 2001 From: Isaac Date: Fri, 23 Jun 2023 00:09:07 +0200 Subject: [PATCH 3/3] Reduce blur fill shimmering with lowpass filter --- border/blur_fill.slangp | 79 +++++++++--------- border/blur_fill_stronger_blur.slangp | 81 ++++++++++--------- border/blur_fill_weaker_blur.slangp | 79 +++++++++--------- border/shaders/average_fill/compose.slang | 2 +- border/shaders/blur_fill/compose.slang | 3 +- border/shaders/blur_fill/parameters.slang | 2 +- .../blur_fill/render_sampling_areas.slang | 4 +- 7 files changed, 136 insertions(+), 114 deletions(-) diff --git a/border/blur_fill.slangp b/border/blur_fill.slangp index c484d7f..60c9a67 100644 --- a/border/blur_fill.slangp +++ b/border/blur_fill.slangp @@ -1,82 +1,89 @@ -shaders = 10 +shaders = 12 -parameters = "BLUR_RADIUS" +parameters = "SIGMA;BLUR_RADIUS" +SIGMA = 1.0 BLUR_RADIUS = 2.0 shader0 = ../blurs/shaders/kawase/linearize.slang scale_type0 = source -scale_x0 = 1.0 -scale_y0 = 1.0 +scale0 = 1.0 float_framebuffer0 = true alias0 = "Input" -shader1 = shaders/blur_fill/render_sampling_areas.slang -scale_type1 = viewport -scale_x1 = 0.2 -scale_y1 = 0.2 +shader1 = ../blurs/shaders/gauss_4tap/gauss_2tap_h.slang +filter_linear1 = true +scale_type1 = source +scale1 = 1.0 float_framebuffer1 = true -alias1 = "Tiled" +wrap_mode1 = mirrored_repeat -shader2 = ../blurs/shaders/dual_filter/downsample.slang +shader2 = ../blurs/shaders/gauss_4tap/gauss_2tap_v.slang filter_linear2 = true scale_type2 = source -scale_x2 = 0.5 -scale_y2 = 0.5 +scale2 = 1.0 float_framebuffer2 = true wrap_mode2 = mirrored_repeat -shader3 = ../blurs/shaders/dual_filter/downsample.slang +shader3 = shaders/blur_fill/render_sampling_areas.slang filter_linear3 = true scale_type3 = source -scale_x3 = 0.5 -scale_y3 = 0.5 +scale_x3 = 2.0 +scale_y3 = 2.0 float_framebuffer3 = true -wrap_mode3 = mirrored_repeat +alias3 = "Tiled" shader4 = ../blurs/shaders/dual_filter/downsample.slang filter_linear4 = true scale_type4 = source -scale_x4 = 0.5 -scale_y4 = 0.5 +scale4 = 0.5 float_framebuffer4 = true wrap_mode4 = mirrored_repeat -shader5 = ../blurs/shaders/dual_filter/upsample.slang +shader5 = ../blurs/shaders/dual_filter/downsample.slang filter_linear5 = true scale_type5 = source -scale_x5 = 2.0 -scale_y5 = 2.0 +scale5 = 0.5 float_framebuffer5 = true wrap_mode5 = mirrored_repeat -shader6 = ../blurs/shaders/dual_filter/upsample.slang +shader6 = ../blurs/shaders/dual_filter/downsample.slang filter_linear6 = true scale_type6 = source -scale_x6 = 2.0 -scale_y6 = 2.0 +scale6 = 0.5 float_framebuffer6 = true wrap_mode6 = mirrored_repeat shader7 = ../blurs/shaders/dual_filter/upsample.slang filter_linear7 = true scale_type7 = source -scale_x7 = 2.0 -scale_y7 = 2.0 +scale7 = 2.0 float_framebuffer7 = true wrap_mode7 = mirrored_repeat -alias7 = "Blurred" -shader8 = shaders/blur_fill/compose.slang +shader8 = ../blurs/shaders/dual_filter/upsample.slang filter_linear8 = true -scale_type8 = viewport -scale_x8 = 1.0 -scale_y8 = 1.0 +scale_type8 = source +scale8 = 2.0 float_framebuffer8 = true -mipmap_input8 = true +wrap_mode8 = mirrored_repeat -shader9 = ../blurs/shaders/kawase/delinearize.slang +shader9 = ../blurs/shaders/dual_filter/upsample.slang filter_linear9 = true -scale_type9 = viewport -scale_x9 = 1.0 -scale_y9 = 1.0 +scale_type9 = source +scale9 = 2.0 float_framebuffer9 = true +wrap_mode9 = mirrored_repeat +alias9 = "Blurred" + +shader10 = shaders/blur_fill/compose.slang +filter_linear10 = true +scale_type10 = viewport +scale10 = 1.0 +float_framebuffer10 = true +mipmap_input10 = true + +shader11 = ../blurs/shaders/kawase/delinearize.slang +filter_linear11 = true +scale_type11 = viewport +scale11 = 1.0 +float_framebuffer11 = true diff --git a/border/blur_fill_stronger_blur.slangp b/border/blur_fill_stronger_blur.slangp index c9eb2b8..ed68c11 100644 --- a/border/blur_fill_stronger_blur.slangp +++ b/border/blur_fill_stronger_blur.slangp @@ -1,82 +1,89 @@ -shaders = 10 +shaders = 12 -parameters = "BLUR_RADIUS" -BLUR_RADIUS = 4.0 +parameters = "SIGMA;BLUR_RADIUS" +SIGMA = 2.0 +BLUR_RADIUS = 3.0 shader0 = ../blurs/shaders/kawase/linearize.slang scale_type0 = source -scale_x0 = 1.0 -scale_y0 = 1.0 +scale0 = 1.0 float_framebuffer0 = true alias0 = "Input" -shader1 = shaders/blur_fill/render_sampling_areas.slang -scale_type1 = viewport -scale_x1 = 0.1 -scale_y1 = 0.1 +shader1 = ../blurs/shaders/gauss_4tap/gauss_2tap_h.slang +filter_linear1 = true +scale_type1 = source +scale1 = 1.0 float_framebuffer1 = true -alias1 = "Tiled" +wrap_mode1 = mirrored_repeat -shader2 = ../blurs/shaders/dual_filter/downsample.slang +shader2 = ../blurs/shaders/gauss_4tap/gauss_2tap_v.slang filter_linear2 = true scale_type2 = source -scale_x2 = 0.5 -scale_y2 = 0.5 +scale2 = 1.0 float_framebuffer2 = true wrap_mode2 = mirrored_repeat -shader3 = ../blurs/shaders/dual_filter/downsample.slang +shader3 = shaders/blur_fill/render_sampling_areas.slang filter_linear3 = true scale_type3 = source -scale_x3 = 0.5 -scale_y3 = 0.5 +scale_x3 = 1.0 +scale_y3 = 1.0 float_framebuffer3 = true -wrap_mode3 = mirrored_repeat +alias3 = "Tiled" shader4 = ../blurs/shaders/dual_filter/downsample.slang filter_linear4 = true scale_type4 = source -scale_x4 = 0.5 -scale_y4 = 0.5 +scale4 = 0.5 float_framebuffer4 = true wrap_mode4 = mirrored_repeat -shader5 = ../blurs/shaders/dual_filter/upsample.slang +shader5 = ../blurs/shaders/dual_filter/downsample.slang filter_linear5 = true scale_type5 = source -scale_x5 = 2.0 -scale_y5 = 2.0 +scale5 = 0.5 float_framebuffer5 = true wrap_mode5 = mirrored_repeat -shader6 = ../blurs/shaders/dual_filter/upsample.slang +shader6 = ../blurs/shaders/dual_filter/downsample.slang filter_linear6 = true scale_type6 = source -scale_x6 = 2.0 -scale_y6 = 2.0 +scale6 = 0.5 float_framebuffer6 = true wrap_mode6 = mirrored_repeat shader7 = ../blurs/shaders/dual_filter/upsample.slang filter_linear7 = true scale_type7 = source -scale_x7 = 2.0 -scale_y7 = 2.0 +scale7 = 2.0 float_framebuffer7 = true wrap_mode7 = mirrored_repeat -alias7 = "Blurred" -shader8 = shaders/blur_fill/compose.slang +shader8 = ../blurs/shaders/dual_filter/upsample.slang filter_linear8 = true -scale_type8 = viewport -scale_x8 = 1.0 -scale_y8 = 1.0 +scale_type8 = source +scale8 = 2.0 float_framebuffer8 = true -mipmap_input8 = true +wrap_mode8 = mirrored_repeat -shader9 = ../blurs/shaders/kawase/delinearize.slang +shader9 = ../blurs/shaders/dual_filter/upsample.slang filter_linear9 = true -scale_type9 = viewport -scale_x9 = 1.0 -scale_y9 = 1.0 +scale_type9 = source +scale9 = 2.0 float_framebuffer9 = true +wrap_mode9 = mirrored_repeat +alias9 = "Blurred" + +shader10 = shaders/blur_fill/compose.slang +filter_linear10 = true +scale_type10 = viewport +scale10 = 1.0 +float_framebuffer10 = true +mipmap_input10 = true + +shader11 = ../blurs/shaders/kawase/delinearize.slang +filter_linear11 = true +scale_type11 = viewport +scale11 = 1.0 +float_framebuffer11 = true diff --git a/border/blur_fill_weaker_blur.slangp b/border/blur_fill_weaker_blur.slangp index 59eab3f..04fdd6c 100644 --- a/border/blur_fill_weaker_blur.slangp +++ b/border/blur_fill_weaker_blur.slangp @@ -1,82 +1,89 @@ -shaders = 10 +shaders = 12 -parameters = "BLUR_RADIUS" +parameters = "SIGMA;BLUR_RADIUS" +SIGMA = 1.0 BLUR_RADIUS = 1.0 shader0 = ../blurs/shaders/kawase/linearize.slang scale_type0 = source -scale_x0 = 1.0 -scale_y0 = 1.0 +scale0 = 1.0 float_framebuffer0 = true alias0 = "Input" -shader1 = shaders/blur_fill/render_sampling_areas.slang -scale_type1 = viewport -scale_x1 = 0.4 -scale_y1 = 0.4 +shader1 = ../blurs/shaders/gauss_4tap/gauss_2tap_h.slang +filter_linear1 = true +scale_type1 = source +scale1 = 1.0 float_framebuffer1 = true -alias1 = "Tiled" +wrap_mode1 = mirrored_repeat -shader2 = ../blurs/shaders/dual_filter/downsample.slang +shader2 = ../blurs/shaders/gauss_4tap/gauss_2tap_v.slang filter_linear2 = true scale_type2 = source -scale_x2 = 0.5 -scale_y2 = 0.5 +scale2 = 1.0 float_framebuffer2 = true wrap_mode2 = mirrored_repeat -shader3 = ../blurs/shaders/dual_filter/downsample.slang +shader3 = shaders/blur_fill/render_sampling_areas.slang filter_linear3 = true scale_type3 = source -scale_x3 = 0.5 -scale_y3 = 0.5 +scale_x3 = 3.0 +scale_y3 = 3.0 float_framebuffer3 = true -wrap_mode3 = mirrored_repeat +alias3 = "Tiled" shader4 = ../blurs/shaders/dual_filter/downsample.slang filter_linear4 = true scale_type4 = source -scale_x4 = 0.5 -scale_y4 = 0.5 +scale4 = 0.5 float_framebuffer4 = true wrap_mode4 = mirrored_repeat -shader5 = ../blurs/shaders/dual_filter/upsample.slang +shader5 = ../blurs/shaders/dual_filter/downsample.slang filter_linear5 = true scale_type5 = source -scale_x5 = 2.0 -scale_y5 = 2.0 +scale5 = 0.5 float_framebuffer5 = true wrap_mode5 = mirrored_repeat -shader6 = ../blurs/shaders/dual_filter/upsample.slang +shader6 = ../blurs/shaders/dual_filter/downsample.slang filter_linear6 = true scale_type6 = source -scale_x6 = 2.0 -scale_y6 = 2.0 +scale6 = 0.5 float_framebuffer6 = true wrap_mode6 = mirrored_repeat shader7 = ../blurs/shaders/dual_filter/upsample.slang filter_linear7 = true scale_type7 = source -scale_x7 = 2.0 -scale_y7 = 2.0 +scale7 = 2.0 float_framebuffer7 = true wrap_mode7 = mirrored_repeat -alias7 = "Blurred" -shader8 = shaders/blur_fill/compose.slang +shader8 = ../blurs/shaders/dual_filter/upsample.slang filter_linear8 = true -scale_type8 = viewport -scale_x8 = 1.0 -scale_y8 = 1.0 +scale_type8 = source +scale8 = 2.0 float_framebuffer8 = true -mipmap_input8 = true +wrap_mode8 = mirrored_repeat -shader9 = ../blurs/shaders/kawase/delinearize.slang +shader9 = ../blurs/shaders/dual_filter/upsample.slang filter_linear9 = true -scale_type9 = viewport -scale_x9 = 1.0 -scale_y9 = 1.0 +scale_type9 = source +scale9 = 2.0 float_framebuffer9 = true +wrap_mode9 = mirrored_repeat +alias9 = "Blurred" + +shader10 = shaders/blur_fill/compose.slang +filter_linear10 = true +scale_type10 = viewport +scale10 = 1.0 +float_framebuffer10 = true +mipmap_input10 = true + +shader11 = ../blurs/shaders/kawase/delinearize.slang +filter_linear11 = true +scale_type11 = viewport +scale11 = 1.0 +float_framebuffer11 = true diff --git a/border/shaders/average_fill/compose.slang b/border/shaders/average_fill/compose.slang index ceddf3f..bf0ec3c 100644 --- a/border/shaders/average_fill/compose.slang +++ b/border/shaders/average_fill/compose.slang @@ -1,7 +1,7 @@ #version 450 /* - Average fill v1.0 by fishku + Average fill v1.2 by fishku Copyright (C) 2023 Public domain license (CC0) diff --git a/border/shaders/blur_fill/compose.slang b/border/shaders/blur_fill/compose.slang index 494e38e..372008a 100644 --- a/border/shaders/blur_fill/compose.slang +++ b/border/shaders/blur_fill/compose.slang @@ -1,7 +1,7 @@ #version 450 /* - Blur fill v1.0 by fishku + Blur fill v1.3 by fishku Copyright (C) 2023 Public domain license (CC0) @@ -27,6 +27,7 @@ strength of the blur. Changelog: + v1.3: Reduce shimmering artifacts. v1.2: Fix scaling bugs. v1.1: Fix bug with glcore driver. v1.0: Initial release. diff --git a/border/shaders/blur_fill/parameters.slang b/border/shaders/blur_fill/parameters.slang index e6c9390..41ce08f 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.2 settings ===" 0.0 0.0 1.0 1.0 +#pragma parameter BLUR_FILL_SETTINGS "=== Blur 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 diff --git a/border/shaders/blur_fill/render_sampling_areas.slang b/border/shaders/blur_fill/render_sampling_areas.slang index 6717116..0c351eb 100644 --- a/border/shaders/blur_fill/render_sampling_areas.slang +++ b/border/shaders/blur_fill/render_sampling_areas.slang @@ -41,7 +41,7 @@ void main() { #pragma stage fragment layout(location = 0) in vec2 vTexCoord; layout(location = 0) out vec4 FragColor; -layout(set = 0, binding = 2) uniform sampler2D Input; +layout(set = 0, binding = 2) uniform sampler2D Source; float min_of_vec4(vec4 i) { return min(min(i.x, i.y), min(i.z, i.w)); } @@ -218,7 +218,7 @@ vec3 sample_mirrored_frame(sampler2D tex, vec2 coord, vec4 input_extrema) { void main() { const vec2 pixel_coord = o2i(vTexCoord); FragColor = vec4( - sample_mirrored_frame(Input, pixel_coord, + sample_mirrored_frame(Source, pixel_coord, vec4(param.OS_CROP_LEFT, param.OS_CROP_TOP, param.InputSize.x - param.OS_CROP_RIGHT, param.InputSize.y - param.OS_CROP_BOTTOM)),