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);
}
Attachments
youle
(youle)
May 4, 2016, 1:20pm
2
TwisterGE: very cool . Remark: you should post the code elsewhere than in pasteall (it will be removed in a few month on pasteall I think)
I tried adding to a .blend but it just seems to render black. Are there any requirements other than the 2d filter?
@Thatimster : the “//// ADD THESE AS PROPERTIES!” part is important! Add every variable between // as properties then set their default values like in the comments.
EDIT: The reason why I didn’t put a demo .blend file is because I used UPBGE, and It might not work on normal Blender.
HG1
(HG1)
May 19, 2016, 3:41am
5
@TwisterGE you can initialize your uniforms to a default value using standard GLSL initalizer syntax by changing
uniform float BLOOM_THRESHOLD; <i>// default: 0.7</i>
to
uniform float BLOOM_THRESHOL[I]D = 0.7;</i>
[/I]This will cause the uniform to have this vector as its value, until the user changes it.
Unknown Platform Issue: Some drivers do not implement uniform initializers correctly.
<b>[B]Unknown </b>Platform Issue: Some drivers do not implement uniform initializers correctly.[/B]
That’s my case, I only have OGL 2.1 (Mesa 11.0.4) w/ GLSL 1.2 …
if you want to set the value inside of the shader just use ‘const’
const float BLOOM_THRESHOLD = .7; <i>// default: 0.7</i>
const float BLOOM_INTENSITY = 3.0; <i>// default: 3.0</i>
const int BLUR_ITERATIONS = 3; <i>// default: 3</i>
const int BLUR_SUBDIVISIONS = 32; <i>// default: 32</i>
const float BLUR_SIZE = .03; <i>// default: 0.03</i>
HG1
(HG1)
May 19, 2016, 11:49pm
8
TwisterGE:
<b>[B]Unknown </b>Platform Issue: Some drivers do not implement uniform initializers correctly.[/B]
That’s my case, I only have OGL 2.1 (Mesa 11.0.4) w/ GLSL 1.2 …
Normally you should not get an error. It just not work.
I am not sure, but I thought since Mesa 11.0.4 uniform initialization should be supported.
By the way. Why do you use such an old version. The actual version is 11.2.2.
TwisterGE
(TwisterGE)
May 20, 2016, 12:42pm
9
I use xorg-edgers PPA for Video Drivers, i thought they were the latest If you have any tips on how can I update Mesa, I will appreciate
sorry for the nerco, but when i went to use this script, i found the forum messed it up, theres the fixed shader (constants version)
bloom.glsl (1.1 KB)
thx for this. I think that a parameter to make the bloom less colorful should be available too
https://i.imgur.com/VVi9iQW.mp4
1 Like
ANSH
(IUGR)
July 8, 2021, 2:25pm
12
Woah, didn’t knew you were still around haha