2021-01-17 02:31:32 +11:00
|
|
|
#version 450
|
|
|
|
|
|
|
|
/*
|
2021-07-30 23:24:20 +10:00
|
|
|
Gaussian blur - vertical pass, dynamic range, resizable
|
2021-01-17 02:31:32 +11:00
|
|
|
|
2023-02-06 02:21:45 +11:00
|
|
|
Copyright (C) 2020 - 2022 guest(r) - guest.r@gmail.com
|
2021-01-17 02:31:32 +11:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2021-07-30 23:24:20 +10:00
|
|
|
*/
|
2021-01-17 02:31:32 +11:00
|
|
|
|
|
|
|
layout(push_constant) uniform Push
|
|
|
|
{
|
|
|
|
vec4 SourceSize;
|
|
|
|
vec4 OriginalSize;
|
|
|
|
vec4 OutputSize;
|
|
|
|
uint FrameCount;
|
2021-07-30 23:24:20 +10:00
|
|
|
float SIZEVB;
|
|
|
|
float SIGMA_VB;
|
2023-02-06 02:21:45 +11:00
|
|
|
float BLOOMCUT_V;
|
2021-01-17 02:31:32 +11:00
|
|
|
} params;
|
|
|
|
|
2021-07-30 23:24:20 +10:00
|
|
|
|
2022-07-29 10:48:28 +10:00
|
|
|
#pragma parameter SIZEVB " Vertical Bloom/Halation/(Glow) Radius" 3.0 1.0 50.0 1.0
|
2021-07-30 23:24:20 +10:00
|
|
|
#define SIZEVB params.SIZEVB
|
|
|
|
|
2022-07-29 10:48:28 +10:00
|
|
|
#pragma parameter SIGMA_VB " Vertical Bloom/Halation/(Glow) Sigma" 0.60 0.25 15.0 0.05
|
2021-07-30 23:24:20 +10:00
|
|
|
#define SIGMA_VB params.SIGMA_VB
|
2021-01-17 02:31:32 +11:00
|
|
|
|
2023-02-06 02:21:45 +11:00
|
|
|
#pragma parameter BLOOMCUT_V " Vertical Bloom/Halation/(Glow) Substract" 0.0 0.0 0.5 0.01
|
|
|
|
#define BLOOMCUT_V params.BLOOMCUT_V
|
|
|
|
|
2021-01-17 02:31:32 +11:00
|
|
|
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;
|
|
|
|
|
2021-07-30 23:24:20 +10:00
|
|
|
#define COMPAT_TEXTURE(c,d) texture(c,d)
|
|
|
|
|
|
|
|
float invsqrsigma = 1.0/(2.0*SIGMA_VB*SIGMA_VB);
|
|
|
|
|
|
|
|
float gaussian(float x)
|
2021-01-17 02:31:32 +11:00
|
|
|
{
|
2021-07-30 23:24:20 +10:00
|
|
|
return exp(-x*x*invsqrsigma);
|
2021-01-17 02:31:32 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2021-07-30 23:24:20 +10:00
|
|
|
vec4 SourceSize1 = params.SourceSize;
|
|
|
|
SourceSize1.yw = params.OriginalSize.yw;
|
2021-01-17 02:31:32 +11:00
|
|
|
|
2021-07-30 23:24:20 +10:00
|
|
|
float f = fract(SourceSize1.y * vTexCoord.y);
|
|
|
|
f = 0.5 - f;
|
|
|
|
vec2 tex = floor(SourceSize1.xy * vTexCoord)*SourceSize1.zw + 0.5*SourceSize1.zw;
|
|
|
|
vec4 color = vec4(0.0);
|
|
|
|
vec2 dy = vec2(0.0, SourceSize1.w);
|
|
|
|
|
|
|
|
float w;
|
|
|
|
float wsum = 0.0;
|
|
|
|
vec4 pixel;
|
|
|
|
float n = -SIZEVB;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
pixel = COMPAT_TEXTURE(Source, tex + n*dy);
|
2023-02-06 02:21:45 +11:00
|
|
|
w = max(gaussian(n+f) - BLOOMCUT_V, 0.0);
|
2021-07-30 23:24:20 +10:00
|
|
|
pixel.a*=pixel.a*pixel.a;
|
|
|
|
color = color + w * pixel;
|
|
|
|
wsum = wsum + w;
|
|
|
|
n = n + 1.0;
|
|
|
|
|
|
|
|
} while (n <= SIZEVB);
|
|
|
|
|
|
|
|
color = color / wsum;
|
2021-01-17 02:31:32 +11:00
|
|
|
|
2021-07-30 23:24:20 +10:00
|
|
|
FragColor = vec4(color.rgb, pow(color.a, 0.175));
|
2021-01-17 02:31:32 +11:00
|
|
|
}
|