Merge pull request #457 from fishcu/fishcu/blur-fill-fix-shimmering

Fix blur fill shimmering
This commit is contained in:
hizzlekizzle 2023-06-23 17:07:42 -05:00 committed by GitHub
commit 7f264bcc4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 250 additions and 114 deletions

13
blurs/gauss_4tap.slangp Normal file
View file

@ -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

View file

@ -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);
}

View file

@ -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));
}

View file

@ -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));
}

View file

@ -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 "Gaussian filtering sigma" 1.0 0.0 2.0 0.05
// clang-format on

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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.

View file

@ -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

View file

@ -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)),