mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2024-11-22 15:51:30 +11:00
add hyllian's gaussian blur shaders and presets
This commit is contained in:
parent
9e9804c428
commit
c317d89a53
8
blurs/gaussian_blur-sharp.slangp
Executable file
8
blurs/gaussian_blur-sharp.slangp
Executable file
|
@ -0,0 +1,8 @@
|
||||||
|
shaders = 1
|
||||||
|
|
||||||
|
shader0 = gaussian_blur_filtering/gaussian-sharp.slang
|
||||||
|
filter_linear0 = false
|
||||||
|
scale_type_x0 = viewport
|
||||||
|
scale_x0 = 1.0
|
||||||
|
scale_type_y0 = viewport
|
||||||
|
scale_y0 = 1.0
|
8
blurs/gaussian_blur.slangp
Executable file
8
blurs/gaussian_blur.slangp
Executable file
|
@ -0,0 +1,8 @@
|
||||||
|
shaders = 1
|
||||||
|
|
||||||
|
shader0 = gaussian_blur_filtering/gaussian.slang
|
||||||
|
filter_linear0 = false
|
||||||
|
scale_type_x0 = viewport
|
||||||
|
scale_x0 = 1.0
|
||||||
|
scale_type_y0 = viewport
|
||||||
|
scale_y0 = 1.0
|
15
blurs/gaussian_blur_2_pass-sharp.slangp
Executable file
15
blurs/gaussian_blur_2_pass-sharp.slangp
Executable file
|
@ -0,0 +1,15 @@
|
||||||
|
shaders = 2
|
||||||
|
|
||||||
|
shader0 = gaussian_blur_filtering/gaussian_horizontal-sharp.slang
|
||||||
|
filter_linear0 = false
|
||||||
|
scale_type_x0 = viewport
|
||||||
|
scale_x0 = 1.0
|
||||||
|
scale_type_y0 = source
|
||||||
|
scale_y0 = 1.0
|
||||||
|
|
||||||
|
shader1 = gaussian_blur_filtering/gaussian_vertical-sharp.slang
|
||||||
|
filter_linear1 = false
|
||||||
|
scale_type_x1 = viewport
|
||||||
|
scale_x1 = 1.0
|
||||||
|
scale_type_y1 = viewport
|
||||||
|
scale_y1 = 1.0
|
15
blurs/gaussian_blur_2_pass.slangp
Executable file
15
blurs/gaussian_blur_2_pass.slangp
Executable file
|
@ -0,0 +1,15 @@
|
||||||
|
shaders = 2
|
||||||
|
|
||||||
|
shader0 = gaussian_blur_filtering/gaussian_horizontal.slang
|
||||||
|
filter_linear0 = false
|
||||||
|
scale_type_x0 = viewport
|
||||||
|
scale_x0 = 1.0
|
||||||
|
scale_type_y0 = source
|
||||||
|
scale_y0 = 1.0
|
||||||
|
|
||||||
|
shader1 = gaussian_blur_filtering/gaussian_vertical.slang
|
||||||
|
filter_linear1 = false
|
||||||
|
scale_type_x1 = viewport
|
||||||
|
scale_x1 = 1.0
|
||||||
|
scale_type_y1 = viewport
|
||||||
|
scale_y1 = 1.0
|
157
blurs/gaussian_blur_filtering/gaussian-sharp.slang
Executable file
157
blurs/gaussian_blur_filtering/gaussian-sharp.slang
Executable file
|
@ -0,0 +1,157 @@
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
/*
|
||||||
|
Gaussian blur 'sharp'- dynamic range, resizable
|
||||||
|
|
||||||
|
Copyright (C) 2020 guest(r) - guest.r@gmail.com
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Anti-Ringing inspired by Hyllian
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
layout(push_constant) uniform Push
|
||||||
|
{
|
||||||
|
vec4 SourceSize;
|
||||||
|
vec4 OriginalSize;
|
||||||
|
vec4 OutputSize;
|
||||||
|
uint FrameCount;
|
||||||
|
float SIZEH;
|
||||||
|
float SIGMA_H;
|
||||||
|
float HSHARP0;
|
||||||
|
float HAR;
|
||||||
|
float SHAR;
|
||||||
|
} params;
|
||||||
|
|
||||||
|
#pragma parameter SIZEH "Gaussian Blur Radius" 6.0 0.0 25.0 1.0
|
||||||
|
#define SIZEH params.SIZEH
|
||||||
|
|
||||||
|
#pragma parameter SIGMA_H "Gaussian Blur Sigma" 1.50 0.1 12.0 0.05
|
||||||
|
#define SIGMA_H params.SIGMA_H
|
||||||
|
|
||||||
|
#pragma parameter HSHARP0 "Sharpness Filter 'Range'" 0.8 0.8 20.0 0.2
|
||||||
|
#define HSHARP0 params.HSHARP0
|
||||||
|
|
||||||
|
#pragma parameter SHAR "Sharpness Definition" 0.5 0.0 2.0 0.05
|
||||||
|
#define SHAR params.SHAR
|
||||||
|
|
||||||
|
#pragma parameter HAR "Anti-Ringing" 0.5 0.0 1.0 0.10
|
||||||
|
#define HAR params.HAR
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
#define COMPAT_TEXTURE(c,d) texture(c,d)
|
||||||
|
#define SourceSize params.SourceSize
|
||||||
|
|
||||||
|
float invsqrsigma_h = 1.0/(2.0*SIGMA_H*SIGMA_H);
|
||||||
|
|
||||||
|
float gaussian_h(float x)
|
||||||
|
{
|
||||||
|
return exp(-x*x*invsqrsigma_h);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 f = fract(SourceSize.xy * vTexCoord.xy);
|
||||||
|
f = 0.5 - f;
|
||||||
|
vec2 tex = floor(SourceSize.xy * vTexCoord)*SourceSize.zw + 0.5*SourceSize.zw;
|
||||||
|
vec2 dx = vec2(SourceSize.z, 0.0);
|
||||||
|
vec2 dy = vec2(0.0, SourceSize.w);
|
||||||
|
|
||||||
|
vec3 colorx = vec3(0.0);
|
||||||
|
vec3 colory = vec3(0.0);
|
||||||
|
float wx, wy;
|
||||||
|
float wsumx;
|
||||||
|
float wsumy = 0.0;
|
||||||
|
vec3 pixel;
|
||||||
|
float x;
|
||||||
|
float y = -SIZEH;
|
||||||
|
|
||||||
|
vec3 xcmax = COMPAT_TEXTURE(Source, tex).rgb;
|
||||||
|
vec3 xcmin = xcmax;
|
||||||
|
vec3 ycmax = xcmax;
|
||||||
|
vec3 ycmin = xcmax;
|
||||||
|
float sharp = (HSHARP0 > 0.85) ? gaussian_h(HSHARP0) : 0.0;
|
||||||
|
float FPR = HSHARP0;
|
||||||
|
float wnorm = 1.0; // /(1.0-sharp);
|
||||||
|
float fpx = 0.0;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
wsumx = 0.0;
|
||||||
|
colorx = 0.0.xxx;
|
||||||
|
x = -SIZEH;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
pixel = COMPAT_TEXTURE(Source, tex + x*dx + y*dy).rgb;
|
||||||
|
wx = (gaussian_h(x+f.x) - sharp)*wnorm;
|
||||||
|
|
||||||
|
if (HSHARP0 > 0.85)
|
||||||
|
{
|
||||||
|
if (abs(x+f.x) > FPR) { if (x < 0.0) fpx = -(x+f.x+FPR)/FPR; else fpx = (x+f.x-FPR)/FPR; fpx = min(fpx, 1.0); }
|
||||||
|
if (abs(x) <= 2.0*FPR) { xcmax = max(xcmax, pixel); xcmin = min(xcmin, pixel); }
|
||||||
|
if (wx < 0.0) wx = clamp(wx, mix(-0.18, 0.0, pow(fpx, SHAR)), 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
colorx = colorx + wx * pixel;
|
||||||
|
wsumx = wsumx+ wx;
|
||||||
|
x = x + 1.0;
|
||||||
|
|
||||||
|
} while (x <= SIZEH);
|
||||||
|
|
||||||
|
colorx = colorx / wsumx;
|
||||||
|
if (HSHARP0 > 0.85) colorx = mix(clamp(colorx, 0.0, 1.0), clamp(colorx, xcmin, xcmax), HAR);
|
||||||
|
|
||||||
|
wy = (gaussian_h(y+f.y) - sharp)*wnorm;
|
||||||
|
|
||||||
|
if (HSHARP0 > 0.85)
|
||||||
|
{
|
||||||
|
if (abs(y+f.y) > FPR) { if (y < 0.0) fpx = -(y+f.y+FPR)/FPR; else fpx = (y+f.y-FPR)/FPR; fpx = min(fpx, 1.0); }
|
||||||
|
if (abs(y) <= 2.0*FPR) { ycmax = max(ycmax, colorx); ycmin = min(ycmin, colorx); }
|
||||||
|
if (wy < 0.0) wy = clamp(wy, mix(-0.18, 0.0, pow(fpx, SHAR)), 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
colory = colory + wy * colorx;
|
||||||
|
wsumy = wsumy + wy;
|
||||||
|
y = y + 1.0;
|
||||||
|
|
||||||
|
} while (y <= SIZEH);
|
||||||
|
|
||||||
|
colory= colory/wsumy;
|
||||||
|
if (HSHARP0 > 0.85) colory = mix(clamp(colory, 0.0, 1.0), clamp(colory, ycmin, ycmax), HAR);
|
||||||
|
|
||||||
|
FragColor = vec4(colory, 1.0);
|
||||||
|
}
|
129
blurs/gaussian_blur_filtering/gaussian.slang
Executable file
129
blurs/gaussian_blur_filtering/gaussian.slang
Executable file
|
@ -0,0 +1,129 @@
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
/*
|
||||||
|
Gaussian blur - dynamic range, resizable
|
||||||
|
|
||||||
|
Copyright (C) 2020 guest(r) - guest.r@gmail.com
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
layout(push_constant) uniform Push
|
||||||
|
{
|
||||||
|
vec4 SourceSize;
|
||||||
|
vec4 OriginalSize;
|
||||||
|
vec4 OutputSize;
|
||||||
|
uint FrameCount;
|
||||||
|
float SIZEH;
|
||||||
|
float SIGMA_H;
|
||||||
|
float SIZEV;
|
||||||
|
float SIGMA_V;
|
||||||
|
} params;
|
||||||
|
|
||||||
|
#pragma parameter SIZEH "Horizontal Blur Radius" 6.0 0.0 25.0 1.0
|
||||||
|
#define SIZEH params.SIZEH
|
||||||
|
|
||||||
|
#pragma parameter SIGMA_H "Horizontal Blur Sigma" 1.50 0.1 12.0 0.05
|
||||||
|
#define SIGMA_H params.SIGMA_H
|
||||||
|
|
||||||
|
#pragma parameter SIZEV "Vertical Blur Radius" 6.0 0.0 25.0 1.0
|
||||||
|
#define SIZEV params.SIZEV
|
||||||
|
|
||||||
|
#pragma parameter SIGMA_V "Vertical Blur Sigma" 1.50 0.1 12.0 0.05
|
||||||
|
#define SIGMA_V params.SIGMA_V
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
#define COMPAT_TEXTURE(c,d) texture(c,d)
|
||||||
|
#define SourceSize params.SourceSize
|
||||||
|
|
||||||
|
float invsqrsigma_h = 1.0/(2.0*SIGMA_H*SIGMA_H);
|
||||||
|
float invsqrsigma_v = 1.0/(2.0*SIGMA_V*SIGMA_V);
|
||||||
|
|
||||||
|
float gaussian_h(float x)
|
||||||
|
{
|
||||||
|
return exp(-x*x*invsqrsigma_h);
|
||||||
|
}
|
||||||
|
|
||||||
|
float gaussian_v(float x)
|
||||||
|
{
|
||||||
|
return exp(-x*x*invsqrsigma_v);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 f = fract(SourceSize.xy * vTexCoord.xy);
|
||||||
|
f = 0.5 - f;
|
||||||
|
vec2 tex = floor(SourceSize.xy * vTexCoord)*SourceSize.zw + 0.5*SourceSize.zw;
|
||||||
|
vec2 dx = vec2(SourceSize.z, 0.0);
|
||||||
|
vec2 dy = vec2(0.0, SourceSize.w);
|
||||||
|
|
||||||
|
vec3 colorx = vec3(0.0);
|
||||||
|
vec3 colory = vec3(0.0);
|
||||||
|
float wx, wy;
|
||||||
|
float wsumx;
|
||||||
|
float wsumy = 0.0;
|
||||||
|
vec3 pixel;
|
||||||
|
float x;
|
||||||
|
float y = -SIZEV;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
wsumx = 0.0;
|
||||||
|
colorx = 0.0.xxx;
|
||||||
|
x = -SIZEH;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
pixel = COMPAT_TEXTURE(Source, tex + x*dx + y*dy).rgb;
|
||||||
|
wx = gaussian_h(x+f.x);
|
||||||
|
colorx = colorx + wx * pixel;
|
||||||
|
wsumx = wsumx+ wx;
|
||||||
|
x = x + 1.0;
|
||||||
|
|
||||||
|
} while (x <= SIZEH);
|
||||||
|
|
||||||
|
colorx = colorx / wsumx;
|
||||||
|
wy = gaussian_v(y+f.y);
|
||||||
|
colory = colory + wy * colorx;
|
||||||
|
wsumy = wsumy + wy;
|
||||||
|
y = y + 1.0;
|
||||||
|
|
||||||
|
} while (y <= SIZEV);
|
||||||
|
|
||||||
|
colory= colory/wsumy;
|
||||||
|
|
||||||
|
FragColor = vec4(colory, 1.0);
|
||||||
|
}
|
129
blurs/gaussian_blur_filtering/gaussian_horizontal-sharp.slang
Executable file
129
blurs/gaussian_blur_filtering/gaussian_horizontal-sharp.slang
Executable file
|
@ -0,0 +1,129 @@
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
/*
|
||||||
|
Gaussian blur 'sharp' - horizontal pass, dynamic range, resizable
|
||||||
|
|
||||||
|
Copyright (C) 2020 guest(r) - guest.r@gmail.com
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Anti-Ringing inspired by Hyllian
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
layout(push_constant) uniform Push
|
||||||
|
{
|
||||||
|
vec4 SourceSize;
|
||||||
|
vec4 OriginalSize;
|
||||||
|
vec4 OutputSize;
|
||||||
|
uint FrameCount;
|
||||||
|
float SIZEH;
|
||||||
|
float SIGMA_H;
|
||||||
|
float HSHARP0;
|
||||||
|
float HAR;
|
||||||
|
float HSHAR;
|
||||||
|
} params;
|
||||||
|
|
||||||
|
#pragma parameter SIZEH "Horizontal Blur Radius" 5.0 0.0 40.0 1.0
|
||||||
|
#define SIZEH params.SIZEH
|
||||||
|
|
||||||
|
#pragma parameter SIGMA_H "Horizontal Blur Sigma" 0.70 0.1 15.0 0.05
|
||||||
|
#define SIGMA_H params.SIGMA_H
|
||||||
|
|
||||||
|
#pragma parameter HSHARP0 "Horizontal Sharpness Filter 'Range'" 0.8 0.8 20.0 0.2
|
||||||
|
#define HSHARP0 params.HSHARP0
|
||||||
|
|
||||||
|
#pragma parameter HSHAR "Sharpness Definition - Horizontal" 0.5 0.0 2.0 0.05
|
||||||
|
#define HSHAR params.HSHAR
|
||||||
|
|
||||||
|
#pragma parameter HAR "Horizontal Anti-Ringing" 0.5 0.0 1.0 0.1
|
||||||
|
#define HAR params.HAR
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
#define COMPAT_TEXTURE(c,d) texture(c,d)
|
||||||
|
#define SourceSize params.SourceSize
|
||||||
|
|
||||||
|
float invsqrsigma = 1.0/(2.0*SIGMA_H*SIGMA_H);
|
||||||
|
|
||||||
|
float gaussian(float x)
|
||||||
|
{
|
||||||
|
return exp(-x*x*invsqrsigma);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
float f = fract(SourceSize.x * vTexCoord.x);
|
||||||
|
f = 0.5 - f;
|
||||||
|
vec2 tex = floor(SourceSize.xy * vTexCoord)*SourceSize.zw + 0.5*SourceSize.zw;
|
||||||
|
vec3 color = vec3(0.0);
|
||||||
|
vec2 dx = vec2(SourceSize.z, 0.0);
|
||||||
|
|
||||||
|
float w;
|
||||||
|
float wsum = 0.0;
|
||||||
|
vec3 pixel;
|
||||||
|
float n = -SIZEH;
|
||||||
|
|
||||||
|
vec3 cmax = COMPAT_TEXTURE(Source, tex).rgb;
|
||||||
|
vec3 cmin = cmax;
|
||||||
|
float sharp = (HSHARP0 > 0.85) ? gaussian(HSHARP0) : 0.0;
|
||||||
|
float FPR = HSHARP0;
|
||||||
|
float wnorm = 1.0/(1.0-sharp);
|
||||||
|
float fpx = 0.0;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
|
||||||
|
w = (gaussian(n+f) - sharp)*wnorm;
|
||||||
|
|
||||||
|
if (HSHARP0 > 0.85)
|
||||||
|
{
|
||||||
|
if (abs(n+f) > FPR) { if (n < 0.0) fpx = -(n+f+FPR)/FPR; else fpx = (n+f-FPR)/FPR; fpx = min(fpx, 1.0);}
|
||||||
|
if (abs(n) <= 2.0*FPR) { cmax = max(cmax, pixel); cmin = min(cmin, pixel); }
|
||||||
|
if (w < 0.0) w = clamp(w, mix(-0.18, 0.0, pow(fpx,HSHAR)), 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
pixel = COMPAT_TEXTURE(Source, tex + n*dx).rgb;
|
||||||
|
color = color + w * pixel;
|
||||||
|
wsum = wsum + w;
|
||||||
|
n = n + 1.0;
|
||||||
|
|
||||||
|
} while (n <= SIZEH);
|
||||||
|
|
||||||
|
color = color / wsum;
|
||||||
|
if (HSHARP0 > 0.85) color = mix(clamp(color, 0.0, 1.0), clamp(color, cmin, cmax), HAR);
|
||||||
|
|
||||||
|
FragColor = vec4(color, 1.0);
|
||||||
|
}
|
98
blurs/gaussian_blur_filtering/gaussian_horizontal.slang
Executable file
98
blurs/gaussian_blur_filtering/gaussian_horizontal.slang
Executable file
|
@ -0,0 +1,98 @@
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
/*
|
||||||
|
Gaussian blur - horizontal pass, dynamic range, resizable
|
||||||
|
|
||||||
|
Copyright (C) 2020 guest(r) - guest.r@gmail.com
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
layout(push_constant) uniform Push
|
||||||
|
{
|
||||||
|
vec4 SourceSize;
|
||||||
|
vec4 OriginalSize;
|
||||||
|
vec4 OutputSize;
|
||||||
|
uint FrameCount;
|
||||||
|
float SIZEH;
|
||||||
|
float SIGMA_H;
|
||||||
|
} params;
|
||||||
|
|
||||||
|
#pragma parameter SIZEH "Horizontal Blur Radius" 5.0 0.0 40.0 1.0
|
||||||
|
#define SIZEH params.SIZEH
|
||||||
|
|
||||||
|
#pragma parameter SIGMA_H "Horizontal Blur Sigma" 1.0 0.1 15.0 0.05
|
||||||
|
#define SIGMA_H params.SIGMA_H
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
#define COMPAT_TEXTURE(c,d) texture(c,d)
|
||||||
|
#define SourceSize params.SourceSize
|
||||||
|
|
||||||
|
float invsqrsigma = 1.0/(2.0*SIGMA_H*SIGMA_H);
|
||||||
|
|
||||||
|
float gaussian(float x)
|
||||||
|
{
|
||||||
|
return exp(-x*x*invsqrsigma);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
float f = fract(SourceSize.x * vTexCoord.x);
|
||||||
|
f = 0.5 - f;
|
||||||
|
vec2 tex = floor(SourceSize.xy * vTexCoord)*SourceSize.zw + 0.5*SourceSize.zw;
|
||||||
|
vec3 color = vec3(0.0);
|
||||||
|
vec2 dx = vec2(SourceSize.z, 0.0);
|
||||||
|
|
||||||
|
float w;
|
||||||
|
float wsum = 0.0;
|
||||||
|
vec3 pixel;
|
||||||
|
float n = -SIZEH;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
pixel = COMPAT_TEXTURE(Source, tex + n*dx).rgb;
|
||||||
|
w = gaussian(n+f);
|
||||||
|
color = color + w * pixel;
|
||||||
|
wsum = wsum + w;
|
||||||
|
n = n + 1.0;
|
||||||
|
|
||||||
|
} while (n <= SIZEH);
|
||||||
|
|
||||||
|
color = color / wsum;
|
||||||
|
|
||||||
|
FragColor = vec4(color, 1.0);
|
||||||
|
}
|
129
blurs/gaussian_blur_filtering/gaussian_vertical-sharp.slang
Executable file
129
blurs/gaussian_blur_filtering/gaussian_vertical-sharp.slang
Executable file
|
@ -0,0 +1,129 @@
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
/*
|
||||||
|
Gaussian blur 'sharp' - vertical pass, dynamic range, resizable
|
||||||
|
|
||||||
|
Copyright (C) 2020 guest(r) - guest.r@gmail.com
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Anti-Ringing inspired by Hyllian
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
layout(push_constant) uniform Push
|
||||||
|
{
|
||||||
|
vec4 SourceSize;
|
||||||
|
vec4 OriginalSize;
|
||||||
|
vec4 OutputSize;
|
||||||
|
uint FrameCount;
|
||||||
|
float SIZEV;
|
||||||
|
float SIGMA_V;
|
||||||
|
float VSHARP0;
|
||||||
|
float VAR;
|
||||||
|
float VSHAR;
|
||||||
|
} params;
|
||||||
|
|
||||||
|
#pragma parameter bogus-line "-------------------------------------------------" 0.0 0.0 0.0 0.0
|
||||||
|
|
||||||
|
#pragma parameter SIZEV "Vertical Blur Radius" 5.0 0.0 40.0 1.0
|
||||||
|
#define SIZEV params.SIZEV
|
||||||
|
|
||||||
|
#pragma parameter SIGMA_V "Vertical Blur Sigma" 0.70 0.1 15.0 0.05
|
||||||
|
#define SIGMA_V params.SIGMA_V
|
||||||
|
|
||||||
|
#pragma parameter VSHARP0 "Vertical Sharpness Filter 'Range'" 0.8 0.8 20.0 0.2
|
||||||
|
#define VSHARP0 params.VSHARP0
|
||||||
|
|
||||||
|
#pragma parameter VSHAR "Sharpness Definition - Vertical" 0.5 0.0 2.0 0.05
|
||||||
|
#define VSHAR params.VSHAR
|
||||||
|
|
||||||
|
#pragma parameter VAR "Vertical Anti-Ringing" 0.5 0.0 1.0 0.1
|
||||||
|
#define VAR params.VAR
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
#define COMPAT_TEXTURE(c,d) texture(c,d)
|
||||||
|
#define SourceSize params.SourceSize
|
||||||
|
|
||||||
|
float invsqrsigma = 1.0/(2.0*SIGMA_V*SIGMA_V);
|
||||||
|
|
||||||
|
float gaussian(float x)
|
||||||
|
{
|
||||||
|
return exp(-x*x*invsqrsigma);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
float f = fract(SourceSize.y * vTexCoord.y);
|
||||||
|
f = 0.5 - f;
|
||||||
|
vec2 tex = floor(SourceSize.xy * vTexCoord)*SourceSize.zw + 0.5*SourceSize.zw;
|
||||||
|
vec3 color = vec3(0.0);
|
||||||
|
vec2 dy = vec2(0.0, SourceSize.w);
|
||||||
|
|
||||||
|
float w;
|
||||||
|
float wsum = 0.0;
|
||||||
|
vec3 pixel;
|
||||||
|
float n = -SIZEV;
|
||||||
|
|
||||||
|
vec3 cmax = COMPAT_TEXTURE(Source, tex).rgb;
|
||||||
|
vec3 cmin = cmax;
|
||||||
|
float sharp = (VSHARP0 > 0.85) ? gaussian(VSHARP0) : 0.0;
|
||||||
|
float FPR = VSHARP0;
|
||||||
|
float wnorm = 1.0/(1.0-sharp);
|
||||||
|
float fpx = 0.0;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
w = (gaussian(n+f) - sharp)*wnorm;
|
||||||
|
|
||||||
|
if (VSHARP0 > 0.85)
|
||||||
|
{
|
||||||
|
if (abs(n+f) > FPR) { if (n < 0.0) fpx = -(n+f+FPR)/FPR; else fpx = (n+f-FPR)/FPR; fpx = min(fpx, 1.0); }
|
||||||
|
if (abs(n) <= 2.0*FPR) { cmax = max(cmax, pixel); cmin = min(cmin, pixel); }
|
||||||
|
if (w < 0.0) w = clamp(w, mix(-0.18, 0.0, pow(fpx,VSHAR)), 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
pixel = COMPAT_TEXTURE(Source, tex + n*dy).rgb;
|
||||||
|
color = color + w * pixel;
|
||||||
|
wsum = wsum + w;
|
||||||
|
n = n + 1.0;
|
||||||
|
|
||||||
|
} while (n <= SIZEV);
|
||||||
|
|
||||||
|
color = color / wsum;
|
||||||
|
if (VSHARP0 > 0.85) color = mix(clamp(color, 0.0, 1.0), clamp(color, cmin, cmax), VAR);
|
||||||
|
|
||||||
|
FragColor = vec4(color, 1.0);
|
||||||
|
}
|
98
blurs/gaussian_blur_filtering/gaussian_vertical.slang
Executable file
98
blurs/gaussian_blur_filtering/gaussian_vertical.slang
Executable file
|
@ -0,0 +1,98 @@
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
/*
|
||||||
|
Gaussian blur - vertical pass, dynamic range, resizable
|
||||||
|
|
||||||
|
Copyright (C) 2020 guest(r) - guest.r@gmail.com
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
layout(push_constant) uniform Push
|
||||||
|
{
|
||||||
|
vec4 SourceSize;
|
||||||
|
vec4 OriginalSize;
|
||||||
|
vec4 OutputSize;
|
||||||
|
uint FrameCount;
|
||||||
|
float SIZEV;
|
||||||
|
float SIGMA_V;
|
||||||
|
} params;
|
||||||
|
|
||||||
|
|
||||||
|
#pragma parameter SIZEV "Vertical Blur Radius" 5.0 0.0 40.0 1.0
|
||||||
|
#define SIZEV params.SIZEV
|
||||||
|
|
||||||
|
#pragma parameter SIGMA_V "Vertical Blur Sigma" 1.0 0.1 15.0 0.05
|
||||||
|
#define SIGMA_V params.SIGMA_V
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
#define COMPAT_TEXTURE(c,d) texture(c,d)
|
||||||
|
#define SourceSize params.SourceSize
|
||||||
|
|
||||||
|
float invsqrsigma = 1.0/(2.0*SIGMA_V*SIGMA_V);
|
||||||
|
|
||||||
|
float gaussian(float x)
|
||||||
|
{
|
||||||
|
return exp(-x*x*invsqrsigma);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
float f = fract(SourceSize.y * vTexCoord.y);
|
||||||
|
f = 0.5 - f;
|
||||||
|
vec2 tex = floor(SourceSize.xy * vTexCoord)*SourceSize.zw + 0.5*SourceSize.zw;
|
||||||
|
vec3 color = vec3(0.0);
|
||||||
|
vec2 dy = vec2(0.0, SourceSize.w);
|
||||||
|
|
||||||
|
float w;
|
||||||
|
float wsum = 0.0;
|
||||||
|
vec3 pixel;
|
||||||
|
float n = -SIZEV;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
pixel = COMPAT_TEXTURE(Source, tex + n*dy).rgb;
|
||||||
|
w = gaussian(n+f);
|
||||||
|
color = color + w * pixel;
|
||||||
|
wsum = wsum + w;
|
||||||
|
n = n + 1.0;
|
||||||
|
|
||||||
|
} while (n <= SIZEV);
|
||||||
|
|
||||||
|
color = color / wsum;
|
||||||
|
|
||||||
|
FragColor = vec4(color, 1.0);
|
||||||
|
}
|
Loading…
Reference in a new issue