2021-01-17 02:31:32 +11:00
|
|
|
#version 450
|
|
|
|
|
|
|
|
/*
|
2021-07-30 23:24:20 +10:00
|
|
|
Average Luminance Shader
|
2021-01-17 02:31:32 +11:00
|
|
|
|
2021-07-30 23:24:20 +10:00
|
|
|
Copyright (C) 2018-2020 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
|
|
|
Thanks to HunterK for the mipmap hint. :D
|
2021-01-17 02:31:32 +11:00
|
|
|
*/
|
|
|
|
|
|
|
|
layout(push_constant) uniform Push
|
|
|
|
{
|
|
|
|
uint FrameCount;
|
2021-07-30 23:24:20 +10:00
|
|
|
vec4 SourceSize;
|
|
|
|
float lsmooth;
|
2021-01-17 02:31:32 +11:00
|
|
|
} params;
|
|
|
|
|
2021-07-30 23:24:20 +10:00
|
|
|
#pragma parameter lsmooth "Raster Bloom Effect Smoothing" 0.70 0.50 0.99 0.01
|
|
|
|
|
|
|
|
#define lsmooth params.lsmooth
|
|
|
|
|
2021-01-17 02:31:32 +11:00
|
|
|
#define COMPAT_TEXTURE(c,d) texture(c,d)
|
2021-07-30 23:24:20 +10:00
|
|
|
#define SourceSize params.SourceSize
|
|
|
|
#define InputSize SourceSize
|
|
|
|
#define TEX0 vTexCoord
|
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;
|
2021-07-30 23:24:20 +10:00
|
|
|
vTexCoord = TexCoord * 1.0001;
|
2021-01-17 02:31:32 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma stage fragment
|
|
|
|
layout(location = 0) in vec2 vTexCoord;
|
|
|
|
layout(location = 0) out vec4 FragColor;
|
2021-07-30 23:24:20 +10:00
|
|
|
layout(set = 0, binding = 2) uniform sampler2D PrePass;
|
|
|
|
layout(set = 0, binding = 3) uniform sampler2D AvgLumPassFeedback;
|
2021-01-17 02:31:32 +11:00
|
|
|
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2021-07-30 23:24:20 +10:00
|
|
|
if (vTexCoord.x > 0.2 || vTexCoord.y > 0.2) discard;
|
|
|
|
|
|
|
|
float m = max(log2(SourceSize.x), log2(SourceSize.y));
|
|
|
|
m = floor(max(m, 1.0));
|
|
|
|
|
|
|
|
float ltotal = 0.0;
|
2021-01-17 02:31:32 +11:00
|
|
|
|
2021-07-30 23:24:20 +10:00
|
|
|
ltotal+= length(textureLod(PrePass, vec2(0.25, 0.25), m).rgb);
|
|
|
|
ltotal+= length(textureLod(PrePass, vec2(0.25, 0.75), m).rgb);
|
|
|
|
ltotal+= length(textureLod(PrePass, vec2(0.75, 0.25), m).rgb);
|
|
|
|
ltotal+= length(textureLod(PrePass, vec2(0.75, 0.75), m).rgb);
|
2021-01-17 02:31:32 +11:00
|
|
|
|
2021-07-30 23:24:20 +10:00
|
|
|
ltotal*=0.25;
|
|
|
|
|
|
|
|
ltotal = pow(0.577350269 * ltotal, 0.65);
|
|
|
|
|
|
|
|
float lhistory = texture(AvgLumPassFeedback, vec2(0.1,0.1)).a;
|
|
|
|
|
|
|
|
ltotal = mix(ltotal, lhistory, lsmooth);
|
2021-01-17 02:31:32 +11:00
|
|
|
|
2021-07-30 23:24:20 +10:00
|
|
|
FragColor = vec4(ltotal);
|
2021-01-17 02:31:32 +11:00
|
|
|
}
|