This is just an adapted version of this: https://www.shadertoy.com/view/4dcXWs
It’s surprisingly fast, and it looks really good.
Here’s the source code:
uniform sampler2D bgl_RenderedTexture;
<i>//// ADD THESE AS PROPERTIES!</i>
uniform float BLOOM_THRESHOLD; <i>// default: 0.7</i>
uniform float BLOOM_INTENSITY; <i>// default: 3.0</i>
uniform int BLUR_ITERATIONS; <i>// default: 3</i>
uniform int BLUR_SUBDIVISIONS; <i>// default: 32</i>
uniform float BLUR_SIZE; <i>// default: 0.03</i>
<i>////</i>
vec3 getHDR(vec3 tex) {
<b>return</b> max((tex - BLOOM_THRESHOLD) * BLOOM_INTENSITY, 0.0);
}
vec3 gaussian(sampler2D sampler, vec2 uv) {
vec3 sum = vec3(0.0);
<b>for</b>(int i = 1; i <= BLUR_ITERATIONS; i++) {
float angle = 360. / float(BLUR_SUBDIVISIONS);
<b>for</b>(int j = 0; j < BLUR_SUBDIVISIONS; j++) {
float dist = BLUR_SIZE * (float(i + 1) / float(BLUR_ITERATIONS));
float s = sin(angle * float(j));
float c = cos(angle * float(j));
sum += getHDR(texture2D(sampler, uv + vec2(c,s)*dist).xyz);
}
}
sum /= float(BLUR_ITERATIONS * BLUR_SUBDIVISIONS);
<b>return</b> sum * BLOOM_INTENSITY;
}
vec3 blend(vec3 a, vec3 b) {
<b>return</b> 1.0 - (1.0 - a) * (1.0 - b);
}
void main() {
vec2 uv = gl_TexCoord[0].st;
vec4 tx = texture2D(bgl_RenderedTexture, uv);
gl_FragColor.rgb = gaussian(bgl_RenderedTexture, uv);
gl_FragColor.a = tx.a;
gl_FragColor.xyz = blend(tx.rgb, gl_FragColor.rgb);
}