11#version 460
22#extension GL_ARB_separate_shader_objects : enable
33
4+ #include "pl_shader_interop_renderer.h"
45
56layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
67
78layout(set = 0, binding = 0, rgba16f) uniform image2D target;
89layout(set = 0, binding = 1) uniform texture2D source;
910layout(set = 0, binding = 2) uniform sampler tSamplerLinearClamp;
1011
12+ layout(set = 3, binding = 0) uniform PL_DYNAMIC_DATA
13+ {
14+ plGpuDynBloomData tData;
15+ } tDynamicData;
16+
17+ vec3 PowVec3(vec3 v, float p)
18+ {
19+ return vec3(pow(v.x, p), pow(v.y, p), pow(v.z, p));
20+ }
21+
22+ const float invGamma = 1.0 / 2.2;
23+ vec3 ToSRGB(vec3 v) { return PowVec3(v, invGamma); }
24+
25+ float RGBToLuminance(vec3 col)
26+ {
27+ return dot(col, vec3(0.2126f, 0.7152f, 0.0722f));
28+ }
29+
30+ float KarisAverage(vec3 col)
31+ {
32+ // Formula is 1 / (1 + luma)
33+ float luma = RGBToLuminance(ToSRGB(col)) * 0.25f;
34+ return 1.0f / (1.0f + luma);
35+ }
36+
1137void main()
1238{
1339 ivec2 iUV = ivec2(gl_GlobalInvocationID.xy);
1440 ivec2 targetResolution = imageSize(target);
1541
16-
1742 if(iUV.x >= targetResolution.x || iUV.y >= targetResolution.y)
1843 return;
1944
@@ -24,27 +49,56 @@ void main()
2449
2550 vec3 color = vec3(0);
2651
52+
53+
2754 //sampling pattern from "Next Generation Post Processing in Call of Duty Advanced Warfare"
2855 //center
29- color + = textureLod(sampler2D(source, tSamplerLinearClamp), uv, 0).rgb * 0.125 ;
56+ vec3 e = textureLod(sampler2D(source, tSamplerLinearClamp), uv, 0).rgb;
3057
3158 //center pixel corners
32- color + = textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2(0.5, 0.5), 0).rgb * 0.125 ;
33- color + = textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2(0.5, -0.5), 0).rgb * 0.125 ;
34- color + = textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2(-0.5, 0.5), 0).rgb * 0.125 ;
35- color + = textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2(-0.5, -0.5), 0).rgb * 0.125 ;
59+ vec3 j = textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2(0.5, 0.5), 0).rgb;
60+ vec3 k = textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2(0.5, -0.5), 0).rgb;
61+ vec3 l = textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2(-0.5, 0.5), 0).rgb;
62+ vec3 m = textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2(-0.5, -0.5), 0).rgb;
3663
3764 //left, rigth, up and down
38- color + = textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2( 1.5, 0), 0).rgb * 0.0625 ;
39- color + = textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2(-1.5, 0), 0).rgb * 0.0625 ;
40- color + = textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2(0, 1.5), 0).rgb * 0.0625 ;
41- color + = textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2(0, -1.5), 0).rgb * 0.0625 ;
65+ vec3 b = textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2( 1.5, 0), 0).rgb;
66+ vec3 d = textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2(-1.5, 0), 0).rgb;
67+ vec3 f = textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2(0, 1.5), 0).rgb;
68+ vec3 h = textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2(0, -1.5), 0).rgb;
4269
4370 //diagonal corners
44- color += textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2( 1.5, 1.5), 0).rgb * 0.03125;
45- color += textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2( 1.5, -1.5), 0).rgb * 0.03125;
46- color += textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2(-1.5, 1.5), 0).rgb * 0.03125;
47- color += textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2(-1.5, -1.5), 0).rgb * 0.03125;
71+ vec3 a = textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2( 1.5, 1.5), 0).rgb;
72+ vec3 c = textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2( 1.5, -1.5), 0).rgb;
73+ vec3 g = textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2(-1.5, 1.5), 0).rgb;
74+ vec3 i = textureLod(sampler2D(source, tSamplerLinearClamp), uv + texelSize * vec2(-1.5, -1.5), 0).rgb;
75+
76+ // vec3 groups[5];
77+ // switch (tDynamicData.tData.iMipLevel)
78+ // {
79+ // case 0:
80+ // // We are writing to mip 0, so we need to apply Karis average to each block
81+ // // of 4 samples to prevent fireflies (very bright subpixels, leads to pulsating
82+ // // artifacts).
83+ // groups[0] = (a+b+d+e) * (0.125f/4.0f);
84+ // groups[1] = (b+c+e+f) * (0.125f/4.0f);
85+ // groups[2] = (d+e+g+h) * (0.125f/4.0f);
86+ // groups[3] = (e+f+h+i) * (0.125f/4.0f);
87+ // groups[4] = (j+k+l+m) * (0.5f/4.0f);
88+ // groups[0] *= KarisAverage(groups[0]);
89+ // groups[1] *= KarisAverage(groups[1]);
90+ // groups[2] *= KarisAverage(groups[2]);
91+ // groups[3] *= KarisAverage(groups[3]);
92+ // groups[4] *= KarisAverage(groups[4]);
93+ // color = groups[0]+groups[1]+groups[2]+groups[3]+groups[4];
94+ // break;
95+ // default:
96+ color = e*0.125;
97+ color += (a+c+g+i)*0.03125;
98+ color += (b+d+f+h)*0.0625;
99+ color += (j+k+l+m)*0.125;
100+ // break;
101+ // }
48102
49103 color = clamp(color, 0.0, 100.0);
50104 imageStore(target, iUV, vec4(color, 0));
0 commit comments