-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbloom.fs
57 lines (48 loc) · 1.53 KB
/
bloom.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
R""(
#version 400 core
in vec2 UV;
layout (location = 0) out vec4 ColorVBO;
uniform sampler2D ColorTexture;
subroutine vec4 PointLightRoutine(vec4 color);
subroutine uniform PointLightRoutine CurrentRoutine;
// Note: Weights taken from https://learnopengl.com/#!Advanced-Lighting/Bloom
uniform float GaussianWeights[5] =
float[] (0.277027, 0.1945946, 0.1216216, 0.054054, 0.016216);
// Note: Set one component of TexelSize to 0 for blurring in the other axis.
vec4
GaussianBlur(vec4 OriginColor, vec2 TexelSize)
{
vec4 BlurredColor = OriginColor * GaussianWeights[0];
for(int WeightIndex = 1; WeightIndex < 5; ++WeightIndex)
{
BlurredColor += texture(ColorTexture,
UV + vec2(TexelSize.x * WeightIndex,
TexelSize.y * WeightIndex))
* GaussianWeights[WeightIndex];
BlurredColor += texture(ColorTexture,
UV - vec2(TexelSize.x * WeightIndex,
TexelSize.y * WeightIndex))
* GaussianWeights[WeightIndex];
}
return BlurredColor;
}
subroutine (PointLightRoutine) vec4
BlurHorizontal(vec4 OriginColor)
{
vec2 TexelSize = 1.f / textureSize(ColorTexture, 0);
TexelSize.y = 0.f;
return GaussianBlur(OriginColor, TexelSize);
}
subroutine (PointLightRoutine) vec4
BlurVertical(vec4 OriginColor)
{
vec2 TexelSize = 1.f / textureSize(ColorTexture, 0);
TexelSize.x = 0.f;
return GaussianBlur(OriginColor, TexelSize);
}
void
main()
{
ColorVBO = CurrentRoutine(texture(ColorTexture, UV));
}
)"";