-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbloomUpFragment.glsl
47 lines (39 loc) · 1.61 KB
/
bloomUpFragment.glsl
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
#version 300 es
precision highp float;
// This shader performs upsampling on a texture,
// as taken from Call Of Duty method, presented at ACM Siggraph 2014.
// Remember to add bilinear minification filter for this texture!
// Remember to use a floating-point texture format (for HDR)!
// Remember to use edge clamping for this texture!
uniform sampler2D srcTexture;
uniform float filterRadius;
in vec2 texCoord;
layout (location = 0) out vec3 upsample;
void main() {
// The filter kernel is applied with a radius, specified in texture
// coordinates, so that the radius will vary across mip resolutions.
float x = filterRadius;
float y = filterRadius;
// Take 9 samples around current texel:
// a - b - c
// d - e - f
// g - h - i
// === ('e' is the current texel) ===
vec3 a = texture(srcTexture, vec2(texCoord.x - x, texCoord.y + y)).rgb;
vec3 b = texture(srcTexture, vec2(texCoord.x, texCoord.y + y)).rgb;
vec3 c = texture(srcTexture, vec2(texCoord.x + x, texCoord.y + y)).rgb;
vec3 d = texture(srcTexture, vec2(texCoord.x - x, texCoord.y)).rgb;
vec3 e = texture(srcTexture, vec2(texCoord.x, texCoord.y)).rgb;
vec3 f = texture(srcTexture, vec2(texCoord.x + x, texCoord.y)).rgb;
vec3 g = texture(srcTexture, vec2(texCoord.x - x, texCoord.y - y)).rgb;
vec3 h = texture(srcTexture, vec2(texCoord.x, texCoord.y - y)).rgb;
vec3 i = texture(srcTexture, vec2(texCoord.x + x, texCoord.y - y)).rgb;
// Apply weighted distribution, by using a 3x3 tent filter:
// 1 | 1 2 1 |
// -- * | 2 4 2 |
// 16 | 1 2 1 |
upsample = e*4.0;
upsample += (b+d+f+h)*2.0;
upsample += (a+c+g+i);
upsample *= 1.0 / 16.0;
}