Merge pull request #256 from HyperspaceMadness/master

Reshade Magicbloom Added
This commit is contained in:
LibretroAdmin 2022-07-04 05:30:58 +01:00 committed by GitHub
commit defceb3d0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 1050 additions and 0 deletions

View file

@ -0,0 +1,108 @@
shaders = 12
shader0 = ../../stock.slang
filter_linear0 = true
wrap_mode0 = mirrored_repeat
scale_type0 = viewport
scale0 = 1.0
alias0 = "PreBloomPass"
// shader0 = ../kawase/linearize.slang
// filter_linear0 = true
// wrap_mode0 = mirrored_repeat
// scale_type0 = viewport
// scale0 = 1.0
// alias0 = "PreBloomPass"
shader1 = ./magicbloom_blur_pass_1.slang
filter_linear1 = true
mipmap_input1 = true
wrap_mode1 = mirrored_repeat
scale_type1 = absolute
// scale_x1 = 960
// scale_y1 = 540
scale_x1 = 1920
scale_y1 = 1080
// scale_type1 = viewport
// scale1 = 0.5
alias1 = "tMagicBloom_1"
shader2 = ./magicbloom_blur_pass_2.slang
filter_linear2 = true
mipmap_input2 = true
wrap_mode2 = mirrored_repeat
scale_type2 = source
scale2 = 0.75
// scale2 = 0.25
alias2 = "tMagicBloom_2"
shader3 = ./magicbloom_blur_pass_3.slang
filter_linear3 = true
mipmap_input3 = true
wrap_mode3 = mirrored_repeat
scale_type3 = source
scale3 = 0.75
// scale3 = 0.125
alias3 = "tMagicBloom_3"
shader4 = ./magicbloom_blur_pass_4.slang
filter_linear4 = true
mipmap_input4 = true
wrap_mode4 = mirrored_repeat
scale_type4 = source
scale4 = 0.75
alias4 = "tMagicBloom_4"
shader5 = ./magicbloom_blur_pass_5.slang
filter_linear5 = true
mipmap_input5 = true
wrap_mode5 = mirrored_repeat
scale_type5 = source
scale5 = 0.75
alias5 = "tMagicBloom_5"
shader6 = ./magicbloom_blur_pass_6.slang
filter_linear6 = true
mipmap_input6 = true
scale_type6 = source
scale6 = 0.5
alias6 = "tMagicBloom_6"
shader7 = ./magicbloom_blur_pass_7.slang
filter_linear7 = true
mipmap_input7 = true
scale_type7 = source
scale7 = 0.5
alias7 = "tMagicBloom_7"
shader8 = ./magicbloom_blur_pass_8.slang
filter_linear8 = true
mipmap_input8 = true
scale_type8 = source
scale8 = 0.5
alias8 = "tMagicBloom_8"
shader9 = ./magicbloom_get_small_luma.slang
filter_linear9 = true
mipmap_input9 = true
scale_type9 = absolute
scale_x9 = 256
scale_y9 = 256
alias9 = "tMagicBloom_Small"
shader10 = ./magicbloom_get_adapt.slang
filter_linear10 = true
mipmap_input10 = true
scale_type10 = source
scale10 = 1.0
alias10 = "tMagicBloom_Adapt"
shader11 = ./magicbloom_blend.slang
filter_linear11 = true
mipmap_input11 = true
scale_type11 = viewport
scale11 = 1.0
textures = "tMagicBloom_Dirt"
tMagicBloom_Dirt = "MagicBloom_dirt.png"

95
reshade/magicbloom.slangp Normal file
View file

@ -0,0 +1,95 @@
shaders = 12
shader0 = ../stock.slang
filter_linear0 = true
wrap_mode0 = mirrored_repeat
scale_type0 = viewport
scale0 = 1.0
alias0 = "PreBloomPass"
shader1 = ./shaders/magicbloom/magicbloom_blur_pass_1.slang
filter_linear1 = true
mipmap_input1 = true
wrap_mode1 = mirrored_repeat
scale_type1 = absolute
scale_x1 = 1920
scale_y1 = 1080
alias1 = "tMagicBloom_1"
shader2 = ./shaders/magicbloom/magicbloom_blur_pass_2.slang
filter_linear2 = true
mipmap_input2 = true
wrap_mode2 = mirrored_repeat
scale_type2 = source
scale2 = 0.75
alias2 = "tMagicBloom_2"
shader3 = ./shaders/magicbloom/magicbloom_blur_pass_3.slang
filter_linear3 = true
mipmap_input3 = true
wrap_mode3 = mirrored_repeat
scale_type3 = source
scale3 = 0.75
alias3 = "tMagicBloom_3"
shader4 = ./shaders/magicbloom/magicbloom_blur_pass_4.slang
filter_linear4 = true
mipmap_input4 = true
wrap_mode4 = mirrored_repeat
scale_type4 = source
scale4 = 0.75
alias4 = "tMagicBloom_4"
shader5 = ./shaders/magicbloom/magicbloom_blur_pass_5.slang
filter_linear5 = true
mipmap_input5 = true
wrap_mode5 = mirrored_repeat
scale_type5 = source
scale5 = 0.75
alias5 = "tMagicBloom_5"
shader6 = ./shaders/magicbloom/magicbloom_blur_pass_6.slang
filter_linear6 = true
mipmap_input6 = true
scale_type6 = source
scale6 = 0.5
alias6 = "tMagicBloom_6"
shader7 = ./shaders/magicbloom/magicbloom_blur_pass_7.slang
filter_linear7 = true
mipmap_input7 = true
scale_type7 = source
scale7 = 0.5
alias7 = "tMagicBloom_7"
shader8 = ./shaders/magicbloom/magicbloom_blur_pass_8.slang
filter_linear8 = true
mipmap_input8 = true
scale_type8 = source
scale8 = 0.5
alias8 = "tMagicBloom_8"
shader9 = ./shaders/magicbloom/magicbloom_get_small_luma.slang
filter_linear9 = true
mipmap_input9 = true
scale_type9 = absolute
scale_x9 = 256
scale_y9 = 256
alias9 = "tMagicBloom_Small"
shader10 = ./shaders/magicbloom/magicbloom_get_adapt.slang
filter_linear10 = true
mipmap_input10 = true
scale_type10 = source
scale10 = 1.0
alias10 = "tMagicBloom_Adapt"
shader11 = ./shaders/magicbloom/magicbloom_blend.slang
filter_linear11 = true
mipmap_input11 = true
scale_type11 = viewport
scale11 = 1.0
textures = "tMagicBloom_Dirt"
tMagicBloom_Dirt = "./shaders/magicbloom/MagicBloom_dirt.png"

Binary file not shown.

After

Width:  |  Height:  |  Size: 585 KiB

View file

@ -0,0 +1,215 @@
#version 450
/*
Magic Bloom by luluco250
Attempts to simulate a natural-looking bloom.
Features:
--Wide bloom blurring, derived from the gaussian function
defined here: https://en.wikipedia.org/wiki/Gaussian_blur#Mathematics
--Eye adaptation, decreases or increases the brightness
of bloom according to the overall image luminance.
--Lens dirt, as standard I suppose. Really not much here.
It uses an image named "MagicBloom_Dirt.png" so make
sure you have one in your textures directory.
--Unwanted features can be disabled through
preprocessor definitions, saving performance.
Preprocessor definitions:
--MAGICBLOOM_ADAPT_RESOLUTION:
Determines the width/height of the texture used for adaptation.
It is recommended to use 256, but you can use as far as 1024 without issues.
Too low resolutions will make adaptation seem "unstable".
Must be a power of two value: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 etc.
--MAGICBLOOM_BLUR_PRECALCULATED:
If set to 0 the gaussian blur will be calculated inside the shader.
Otherwise, it uses a pre-calculated kernel (array).
--MAGICBLOOM_NODIRT:
If set to 1 all lens dirt related features are disabled.
Beneficial for performance if you don't wish to use lens dirt.
--MAGICBLOOM_NOADAPT:
If set to 1 all adaptation related features are disabled.
Beneficial for performance if you don't wish to use adaptation.
MIT Licensed:
Copyright (c) 2017 luluco250
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
//Statics
#ifndef MAGICBLOOM_ADAPT_RESOLUTION
#define MAGICBLOOM_ADAPT_RESOLUTION 256
#endif
#ifndef MAGICBLOOM_BLUR_PRECALCULATED
#define MAGICBLOOM_BLUR_PRECALCULATED 1
#endif
#ifndef MAGICBLOOM_NODIRT
#define MAGICBLOOM_NODIRT 0
#endif
// #ifndef MAGICBLOOM_NOADAPT
#define MAGICBLOOM_NOADAPT 0
// #endif
#define iBlurSamples 4
float iAdaptResolution = MAGICBLOOM_ADAPT_RESOLUTION;
// #define CONST_LOG2(v) (((v) & 0xAAAAAAAA) != 0) | ((((v) & 0xFFFF0000) != 0) << 4) | ((((v) & 0xFF00FF00) != 0) << 3) | ((((v) & 0xF0F0F0F0) != 0) << 2) | ((((v) & 0xCCCCCCCC) != 0) << 1)
#define CONST_LOG2(v) log2(v)
int sigma = int(float(iBlurSamples) / 2.0);
float double_pi = 6.283185307179586476925286766559;
float lowest_mip = CONST_LOG2(iAdaptResolution) + 1;
vec3 luma_value = vec3(0.2126, 0.7152, 0.0722);
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float ApplyBloom;
float fExposure;
float iDebug;
float fDirt_Intensity;
} params;
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
#pragma parameter ApplyBloom " Apply Bloom" 1 0 1 1
#define ApplyBloom params.ApplyBloom
#pragma parameter fExposure " Exposure" 0.2 0 1 0.001
#define fExposure params.fExposure
#pragma parameter fDirt_Intensity " Dirt Intensity" 0 0 1 0.001
#define fDirt_Intensity params.fDirt_Intensity
#pragma parameter iDebug " Debug: Show Blur Pass" 0 0 1 1
#define iDebug params.iDebug
#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 * 1.00001;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
layout(set = 0, binding = 3) uniform sampler2D PreBloomPass;
layout(set = 0, binding = 4) uniform sampler2D tMagicBloom_1;
layout(set = 0, binding = 5) uniform sampler2D tMagicBloom_2;
layout(set = 0, binding = 6) uniform sampler2D tMagicBloom_3;
layout(set = 0, binding = 7) uniform sampler2D tMagicBloom_4;
layout(set = 0, binding = 8) uniform sampler2D tMagicBloom_5;
layout(set = 0, binding = 9) uniform sampler2D tMagicBloom_6;
layout(set = 0, binding = 10) uniform sampler2D tMagicBloom_7;
layout(set = 0, binding = 11) uniform sampler2D tMagicBloom_8;
layout(set = 0, binding = 12) uniform sampler2D tMagicBloom_Adapt;
layout(set = 0, binding = 13) uniform sampler2D tMagicBloom_Dirt;
//Functions
/*
Uncharted 2 Tonemapper
Thanks John Hable and Naughty Dog.
*/
vec3 tonemap(vec3 col, float exposure) {
const float A = 0.15; //shoulder strength
const float B = 0.50; //linear strength
const float C = 0.10; //linear angle
const float D = 0.20; //toe strength
const float E = 0.02; //toe numerator
const float F = 0.30; //toe denominator
const float W = 11.2; //linear white point value
col *= exposure;
col = ((col * (A * col + C * B) + D * E) / (col * (A * col + B) + D * F)) - E / F;
const float white = 1.0 / (((W * (A * W + C * B) + D * E) / (W * (A * W + B) + D * F)) - E / F);
col *= white;
return col;
}
vec3 blend_screen(vec3 a, vec3 b) {
return 1.0 - (1.0 - a) * (1.0 - b);
}
//Final blend shader
vec4 PS_Blend(vec2 uv){
vec3 col = texture(PreBloomPass, uv).rgb;
vec3 bloom = 0
+ texture(tMagicBloom_1, uv).rgb
+ texture(tMagicBloom_2, uv).rgb
+ texture(tMagicBloom_3, uv).rgb
+ texture(tMagicBloom_4, uv).rgb
+ texture(tMagicBloom_5, uv).rgb
+ texture(tMagicBloom_6, uv).rgb
+ texture(tMagicBloom_7, uv).rgb
+ texture(tMagicBloom_8, uv).rgb;
bloom /= 8;
// TODO need to use the feedback, also the blend is possibly the last pass
// #if !MAGICBLOOM_NOADAPT
float exposure = fExposure / max(texture(tMagicBloom_Adapt, vec2(0.0)).x, 0.00001);
bloom = tonemap(bloom, exposure);
// #else
// Without adaptation it seems 100.0 exposure is needed for bloom to look bright enough.
// bloom = tonemap(bloom, 100.0);
// #endif
// // #if !MAGICBLOOM_NODIRT
vec3 dirt = texture(tMagicBloom_Dirt, uv).rgb;
dirt *= fDirt_Intensity;
bloom = blend_screen(bloom, dirt * bloom);
// // #endif
col = blend_screen(col, bloom);
// If we're to display the bloom texture, we replace col with it.
col = iDebug == 1 ? bloom : col;
// col = pow(abs(col), vec3(1/2.2));
return vec4(col, 1.0);
}
void main()
{
if (ApplyBloom < 1){
FragColor = texture(PreBloomPass, vTexCoord);
// FragColor = pow(abs(FragColor), vec4(1/2.2));
return;
}
FragColor = PS_Blend(vTexCoord);
// FragColor = pow(abs(FragColor), vec4(1/2.2));
}

View file

@ -0,0 +1,247 @@
/*
Magic Bloom by luluco250
Attempts to simulate a natural-looking bloom.
Features:
--Wide bloom blurring, derived from the gaussian function
defined here: https://en.wikipedia.org/wiki/Gaussian_blur#Mathematics
--Eye adaptation, decreases or increases the brightness
of bloom according to the overall image luminance.
--Lens dirt, as standard I suppose. Really not much here.
It uses an image named "MagicBloom_Dirt.png" so make
sure you have one in your textures directory.
--Unwanted features can be disabled through
preprocessor definitions, saving performance.
Preprocessor definitions:
--MAGICBLOOM_ADAPT_RESOLUTION:
Determines the width/height of the texture used for adaptation.
It is recommended to use 256, but you can use as far as 1024 without issues.
Too low resolutions will make adaptation seem "unstable".
Must be a power of two value: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 etc.
--MAGICBLOOM_BLUR_PRECALCULATED:
If set to 0 the gaussian blur will be calculated inside the shader.
Otherwise, it uses a pre-calculated kernel (array).
--MAGICBLOOM_NODIRT:
If set to 1 all lens dirt related features are disabled.
Beneficial for performance if you don't wish to use lens dirt.
--MAGICBLOOM_NOADAPT:
If set to 1 all adaptation related features are disabled.
Beneficial for performance if you don't wish to use adaptation.
MIT Licensed:
Copyright (c) 2017 luluco250
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma format R16G16B16A16_SFLOAT
//Statics
#ifndef MAGICBLOOM_ADAPT_RESOLUTION
#define MAGICBLOOM_ADAPT_RESOLUTION 256
#endif
#ifndef MAGICBLOOM_BLUR_PRECALCULATED
#define MAGICBLOOM_BLUR_PRECALCULATED 1
#endif
#ifndef MAGICBLOOM_NODIRT
#define MAGICBLOOM_NODIRT 0
#endif
#ifndef MAGICBLOOM_NOADAPT
#define MAGICBLOOM_NOADAPT 0
#endif
#define iBlurSamples 4
float iAdaptResolution = MAGICBLOOM_ADAPT_RESOLUTION;
// #define CONST_LOG2(v) (((v) & 0xAAAAAAAA) != 0) | ((((v) & 0xFFFF0000) != 0) << 4) | ((((v) & 0xFF00FF00) != 0) << 3) | ((((v) & 0xF0F0F0F0) != 0) << 2) | ((((v) & 0xCCCCCCCC) != 0) << 1)
#define CONST_LOG2(v) log2(v)
int sigma = int(float(iBlurSamples) / 2.0);
float double_pi = 6.283185307179586476925286766559;
float lowest_mip = CONST_LOG2(iAdaptResolution) + 1;
vec3 luma_value = vec3(0.2126, 0.7152, 0.0722);
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float fBloom_Intensity;
float fBloom_Threshold;
float ApplyBloom;
} params;
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
#pragma parameter MagicBloomTitle "[ MAGIC BLOOM ]" 0 0 0.001 0.001
#pragma parameter ApplyBloom " Apply Bloom" 1 0 1 1
#define ApplyBloom params.ApplyBloom
#pragma parameter fBloom_Intensity " Bloom Intensity" 1 0 10 0.1
#define fBloom_Intensity params.fBloom_Intensity / 4
#pragma parameter fBloom_Threshold " Bloom Threshold" 2 1 10 0.1
#define fBloom_Threshold params.fBloom_Threshold
#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 * 1.00001;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
//Functions
#if !MAGICBLOOM_BLUR_PRECALCULATED
float gaussian_function(vec2 i) {
float first_part = 1.0 / (double_pi * pow(sigma, 2.0));
float second_part_a = 1.0 / (2.0 * pow(sigma, 2.0));
float second_part_b = (pow(i.x, 2.0) + pow(i.y, 2.0)) * second_part_a;
return first_part * exp(-second_part_b);
}
#endif
//Why use a single-pass blur? To reduce the amount of textures used in half.
//Scale should be the original resolution divided by target resolution.
vec3 blur(sampler2D sp, vec2 uv, float scale) {
vec2 ps = params.OutputSize.zw * scale;
#if MAGICBLOOM_BLUR_PRECALCULATED
float kernel[9] = {
0.0269955, 0.0647588, 0.120985, 0.176033, 0.199471, 0.176033, 0.120985, 0.0647588, 0.0269955
};
float accum = 1.02352;
#else
float accum = 0.0;
#endif
float gaussian_weight = 0.0;
vec3 col = vec3(0);
// [unroll]
for (int x = int(-iBlurSamples); x <= int(iBlurSamples); ++x) {
for (int y = int(-iBlurSamples); y <= int(iBlurSamples); ++y) {
#if MAGICBLOOM_BLUR_PRECALCULATED
gaussian_weight = kernel[x + iBlurSamples] * kernel[y + iBlurSamples];
#else
gaussian_weight = gaussian_function(vec2(x, y));
accum += gaussian_weight;
#endif
col += texture(sp, uv + ps * vec2(x, y)).rgb * gaussian_weight;
}
}
#if MAGICBLOOM_BLUR_PRECALCULATED
return col * accum;
#else
return col / accum;
#endif
}
vec4 PS_Blur1(vec2 uv, sampler2D in_sampler) {
vec3 col = blur(in_sampler, uv, 2.0);
col = pow(abs(col), vec3(fBloom_Threshold));
col *= fBloom_Intensity;
return vec4(col, 1.0);
}
vec4 PS_Blur2(vec2 uv, sampler2D in_sampler) {
return vec4(blur(in_sampler, uv, 4.0), 1.0);
}
vec4 PS_Blur3(vec2 uv, sampler2D in_sampler) {
return vec4(blur(in_sampler, uv, 8.0), 1.0);
}
vec4 PS_Blur4(vec2 uv, sampler2D in_sampler) {
return vec4(blur(in_sampler, uv, 8.0), 1.0);
}
vec4 PS_Blur5(vec2 uv, sampler2D in_sampler) {
return vec4(blur(in_sampler, uv, 16.0), 1.0);
}
vec4 PS_Blur6(vec2 uv, sampler2D in_sampler) {
return vec4(blur(in_sampler, uv, 32.0), 1.0);
}
vec4 PS_Blur7(vec2 uv, sampler2D in_sampler) {
return vec4(blur(in_sampler, uv, 64.0), 1.0);
}
vec4 PS_Blur8(vec2 uv, sampler2D in_sampler) {
return vec4(blur(in_sampler, uv, 128.0), 1.0);
}
void main()
{
if (ApplyBloom < 1)
return;
#ifdef BLUR_PASS_1
FragColor = PS_Blur1(vTexCoord, Source);
#endif
#ifdef BLUR_PASS_2
FragColor = PS_Blur2(vTexCoord, Source);
#endif
#ifdef BLUR_PASS_3
FragColor = PS_Blur3(vTexCoord, Source);
#endif
#ifdef BLUR_PASS_4
FragColor = PS_Blur4(vTexCoord, Source);
#endif
#ifdef BLUR_PASS_5
FragColor = PS_Blur5(vTexCoord, Source);
#endif
#ifdef BLUR_PASS_6
FragColor = PS_Blur6(vTexCoord, Source);
#endif
#ifdef BLUR_PASS_7
FragColor = PS_Blur7(vTexCoord, Source);
#endif
#ifdef BLUR_PASS_8
FragColor = PS_Blur8(vTexCoord, Source);
#endif
}

View file

@ -0,0 +1,12 @@
#version 450
/*
Magic Bloom by luluco250
See .inc file for more info
*/
#define BLUR_PASS_1
#pragma alias tMagicBloom_1
#include "magicbloom_blur.inc"

View file

@ -0,0 +1,12 @@
#version 450
/*
Magic Bloom by luluco250
See .inc file for more info
*/
#define BLUR_PASS_2
#pragma alias tMagicBloom_2
#include "magicbloom_blur.inc"

View file

@ -0,0 +1,12 @@
#version 450
/*
Magic Bloom by luluco250
See .inc file for more info
*/
#define BLUR_PASS_3
#pragma alias tMagicBloom_3
#include "magicbloom_blur.inc"

View file

@ -0,0 +1,12 @@
#version 450
/*
Magic Bloom by luluco250
See .inc file for more info
*/
#define BLUR_PASS_4
#pragma alias tMagicBloom_4
#include "magicbloom_blur.inc"

View file

@ -0,0 +1,12 @@
#version 450
/*
Magic Bloom by luluco250
See .inc file for more info
*/
#define BLUR_PASS_5
#pragma alias tMagicBloom_5
#include "magicbloom_blur.inc"

View file

@ -0,0 +1,12 @@
#version 450
/*
Magic Bloom by luluco250
See .inc file for more info
*/
#define BLUR_PASS_6
#pragma alias tMagicBloom_6
#include "magicbloom_blur.inc"

View file

@ -0,0 +1,12 @@
#version 450
/*
Magic Bloom by luluco250
See .inc file for more info
*/
#define BLUR_PASS_7
#pragma alias tMagicBloom_7
#include "magicbloom_blur.inc"

View file

@ -0,0 +1,12 @@
#version 450
/*
Magic Bloom by luluco250
See .inc file for more info
*/
#define BLUR_PASS_8
#pragma alias tMagicBloom_8
#include "magicbloom_blur.inc"

View file

@ -0,0 +1,159 @@
#version 450
/*
Magic Bloom by luluco250
Attempts to simulate a natural-looking bloom.
Features:
--Wide bloom blurring, derived from the gaussian function
defined here: https://en.wikipedia.org/wiki/Gaussian_blur#Mathematics
--Eye adaptation, decreases or increases the brightness
of bloom according to the overall image luminance.
--Lens dirt, as standard I suppose. Really not much here.
It uses an image named "MagicBloom_Dirt.png" so make
sure you have one in your textures directory.
--Unwanted features can be disabled through
preprocessor definitions, saving performance.
Preprocessor definitions:
--MAGICBLOOM_ADAPT_RESOLUTION:
Determines the width/height of the texture used for adaptation.
It is recommended to use 256, but you can use as far as 1024 without issues.
Too low resolutions will make adaptation seem "unstable".
Must be a power of two value: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 etc.
--MAGICBLOOM_BLUR_PRECALCULATED:
If set to 0 the gaussian blur will be calculated inside the shader.
Otherwise, it uses a pre-calculated kernel (array).
--MAGICBLOOM_NODIRT:
If set to 1 all lens dirt related features are disabled.
Beneficial for performance if you don't wish to use lens dirt.
--MAGICBLOOM_NOADAPT:
If set to 1 all adaptation related features are disabled.
Beneficial for performance if you don't wish to use adaptation.
MIT Licensed:
Copyright (c) 2017 luluco250
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma format R32G32B32A32_SFLOAT
//Statics
#ifndef MAGICBLOOM_ADAPT_RESOLUTION
#define MAGICBLOOM_ADAPT_RESOLUTION 256
#endif
#ifndef MAGICBLOOM_BLUR_PRECALCULATED
#define MAGICBLOOM_BLUR_PRECALCULATED 1
#endif
#ifndef MAGICBLOOM_NODIRT
#define MAGICBLOOM_NODIRT 0
#endif
// #ifndef MAGICBLOOM_NOADAPT
#define MAGICBLOOM_NOADAPT 0
// #endif
#define iBlurSamples 4
float iAdaptResolution = MAGICBLOOM_ADAPT_RESOLUTION;
// #define CONST_LOG2(v) (((v) & 0xAAAAAAAA) != 0) | ((((v) & 0xFFFF0000) != 0) << 4) | ((((v) & 0xFF00FF00) != 0) << 3) | ((((v) & 0xF0F0F0F0) != 0) << 2) | ((((v) & 0xCCCCCCCC) != 0) << 1)
#define CONST_LOG2(v) log2(v)
int sigma = int(float(iBlurSamples) / 2.0);
float double_pi = 6.283185307179586476925286766559;
float lowest_mip = CONST_LOG2(iAdaptResolution) + 1;
vec3 luma_value = vec3(0.2126, 0.7152, 0.0722);
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float fAdapt_Speed;
float fAdapt_Sensitivity;
float f2Adapt_Clip_Min;
float f2Adapt_Clip_Max;
float ApplyBloom;
} params;
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
#pragma parameter ApplyBloom " Apply Bloom" 1 0 1 1
#define ApplyBloom params.ApplyBloom
#pragma parameter fAdapt_Speed " Adaptation Speed" 1 0.001 1 0.001
#define fAdapt_Speed params.fAdapt_Speed
#pragma parameter fAdapt_Sensitivity " Adaptation Sensitivity" 1 0 3 0.001
float fAdapt_Sensitivity = params.fAdapt_Sensitivity;
#pragma parameter f2Adapt_Clip_Min " Adaptation Min" 0 0 3 0.001
#define f2Adapt_Clip_Min params.f2Adapt_Clip_Min
#pragma parameter f2Adapt_Clip_Max " Adaptation Max" 1 0 3 0.001
#define f2Adapt_Clip_Max params.f2Adapt_Clip_Max
#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 * 1.00001;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
layout(set = 0, binding = 3) uniform sampler2D tMagicBloom_Small;
layout(set = 0, binding = 4) uniform sampler2D tMagicBloom_AdaptFeedback;
//Functions
float PS_GetAdapt(vec2 uv){
float m = max(log2(params.SourceSize.x), log2(params.SourceSize.y));
// m = floor(max(m, 1.0))-1.0;
float curr = textureLod(tMagicBloom_Small, vec2(0.5, 0.5), m - 2).x;
curr *= fAdapt_Sensitivity;
curr = clamp(curr, f2Adapt_Clip_Min, f2Adapt_Clip_Max);
float last = texture(tMagicBloom_AdaptFeedback, vec2(0.5)).x;
//Using the frametime/delta here would actually scale adaptation with the framerate.
//We don't want that, so we don't even bother with it.
return mix(float(last), float(curr), float(fAdapt_Speed));
}
void main()
{
if (ApplyBloom < 1)
return;
FragColor = vec4(PS_GetAdapt(vTexCoord));
}

View file

@ -0,0 +1,130 @@
#version 450
/*
Magic Bloom by luluco250
Attempts to simulate a natural-looking bloom.
Features:
--Wide bloom blurring, derived from the gaussian function
defined here: https://en.wikipedia.org/wiki/Gaussian_blur#Mathematics
--Eye adaptation, decreases or increases the brightness
of bloom according to the overall image luminance.
--Lens dirt, as standard I suppose. Really not much here.
It uses an image named "MagicBloom_Dirt.png" so make
sure you have one in your textures directory.
--Unwanted features can be disabled through
preprocessor definitions, saving performance.
Preprocessor definitions:
--MAGICBLOOM_ADAPT_RESOLUTION:
Determines the width/height of the texture used for adaptation.
It is recommended to use 256, but you can use as far as 1024 without issues.
Too low resolutions will make adaptation seem "unstable".
Must be a power of two value: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 etc.
--MAGICBLOOM_BLUR_PRECALCULATED:
If set to 0 the gaussian blur will be calculated inside the shader.
Otherwise, it uses a pre-calculated kernel (array).
--MAGICBLOOM_NODIRT:
If set to 1 all lens dirt related features are disabled.
Beneficial for performance if you don't wish to use lens dirt.
--MAGICBLOOM_NOADAPT:
If set to 1 all adaptation related features are disabled.
Beneficial for performance if you don't wish to use adaptation.
MIT Licensed:
Copyright (c) 2017 luluco250
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma format R32G32B32A32_SFLOAT
//Statics
#ifndef MAGICBLOOM_ADAPT_RESOLUTION
#define MAGICBLOOM_ADAPT_RESOLUTION 256
#endif
#ifndef MAGICBLOOM_BLUR_PRECALCULATED
#define MAGICBLOOM_BLUR_PRECALCULATED 1
#endif
#ifndef MAGICBLOOM_NODIRT
#define MAGICBLOOM_NODIRT 0
#endif
// #ifndef MAGICBLOOM_NOADAPT
#define MAGICBLOOM_NOADAPT 0
// #endif
#define iBlurSamples 4
float iAdaptResolution = MAGICBLOOM_ADAPT_RESOLUTION;
// #define CONST_LOG2(v) (((v) & 0xAAAAAAAA) != 0) | ((((v) & 0xFFFF0000) != 0) << 4) | ((((v) & 0xFF00FF00) != 0) << 3) | ((((v) & 0xF0F0F0F0) != 0) << 2) | ((((v) & 0xCCCCCCCC) != 0) << 1)
#define CONST_LOG2(v) log2(v)
int sigma = int(float(iBlurSamples) / 2.0);
float double_pi = 6.283185307179586476925286766559;
float lowest_mip = CONST_LOG2(iAdaptResolution) + 1;
vec3 luma_value = vec3(0.2126, 0.7152, 0.0722);
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float ApplyBloom;
} params;
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
#pragma parameter ApplyBloom " Apply Bloom" 1 0 1 1
#define ApplyBloom params.ApplyBloom
#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 * 1.00001;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D PreBloomPass;
//Functions
float PS_GetSmall(vec2 uv){
return dot(texture(PreBloomPass, uv).rgb, luma_value);
}
void main()
{
if (ApplyBloom < 1)
return;
FragColor = vec4(PS_GetSmall(vTexCoord));
}