forked from minetest/minetest
-
Notifications
You must be signed in to change notification settings - Fork 10
/
opengl_fragment.glsl
29 lines (25 loc) · 747 Bytes
/
opengl_fragment.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
#define rendered texture0
uniform sampler2D rendered;
uniform vec2 texelSize0;
uniform mediump float bloomRadius = 3.0;
#ifdef GL_ES
varying mediump vec2 varTexCoord;
#else
centroid varying vec2 varTexCoord;
#endif
void main(void)
{
// kernel distance and linear size
mediump float n = 2. * bloomRadius + 1.;
vec2 uv = varTexCoord.st - vec2(bloomRadius * texelSize0.x, 0.);
vec4 color = vec4(0.);
mediump float sum = 0.;
for (mediump float i = 0.; i < n; i++) {
mediump float weight = pow(1. - (abs(i / bloomRadius - 1.)), 1.3);
color += texture2D(rendered, uv).rgba * weight;
sum += weight;
uv += vec2(texelSize0.x, 0.);
}
color /= sum;
gl_FragColor = vec4(color.rgb, 1.0); // force full alpha to avoid holes in the image.
}