-
Notifications
You must be signed in to change notification settings - Fork 0
/
bloom.gdshader
45 lines (39 loc) · 1.9 KB
/
bloom.gdshader
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
shader_type canvas_item;
uniform float bloomRadius = 1.0;
uniform float bloomThreshold = 1.0;
uniform float bloomIntensity = 1.0;
vec3 GetBloomPixel(sampler2D tex, vec2 uv, vec2 texPixelSize) {
vec2 uv2 = floor(uv / texPixelSize) * texPixelSize;
uv2 += texPixelSize * .001;
vec3 tl = max(texture(tex, uv2).rgb - bloomThreshold, 0.0);
vec3 tr = max(texture(tex, uv2 + vec2(texPixelSize.x, 0.0)).rgb - bloomThreshold, 0.0);
vec3 bl = max(texture(tex, uv2 + vec2(0.0, texPixelSize.y)).rgb - bloomThreshold, 0.0);
vec3 br = max(texture(tex, uv2 + vec2(texPixelSize.x, texPixelSize.y)).rgb - bloomThreshold, 0.0);
vec2 f = fract( uv / texPixelSize );
vec3 tA = mix( tl, tr, f.x );
vec3 tB = mix( bl, br, f.x );
return mix( tA, tB, f.y );
}
vec3 GetBloom(sampler2D tex, vec2 uv, vec2 texPixelSize) {
vec3 bloom = vec3(0.0);
vec2 off = vec2(1) * texPixelSize * bloomRadius;
bloom += GetBloomPixel(tex, uv + off * vec2(-1, -1), texPixelSize * bloomRadius) * 0.292893;
bloom += GetBloomPixel(tex, uv + off * vec2(-1, 0), texPixelSize * bloomRadius) * 0.5;
bloom += GetBloomPixel(tex, uv + off * vec2(-1, 1), texPixelSize * bloomRadius) * 0.292893;
bloom += GetBloomPixel(tex, uv + off * vec2(0, -1), texPixelSize * bloomRadius) * 0.5;
bloom += GetBloomPixel(tex, uv + off * vec2(0, 0), texPixelSize * bloomRadius) * 1.0;
bloom += GetBloomPixel(tex, uv + off * vec2(0, 1), texPixelSize * bloomRadius) * 0.5;
bloom += GetBloomPixel(tex, uv + off * vec2(1, -1), texPixelSize * bloomRadius) * 0.292893;
bloom += GetBloomPixel(tex, uv + off * vec2(1, 0), texPixelSize * bloomRadius) * 0.5;
bloom += GetBloomPixel(tex, uv + off * vec2(1, 1), texPixelSize * bloomRadius) * 0.292893;
bloom /= 4.171573f;
return bloom;
}
void fragment() {
vec4 col = texture(TEXTURE, UV);
// vec3 bloom = GetBloom(TEXTURE, UV, TEXTURE_PIXEL_SIZE);
// col.rgb += bloom * bloomIntensity;
col.r = 1.0;
col.a = 0.5;
COLOR = col;
}