UPBGE Bloom Shader

To better control what blooms:
simply disable/comment/delete that jodieReinhardTonemap thing in _image.fs(lines 10-15 and, 45),
set colorRange to 1.0,
enable HDR Half (for better performance).

Than you will be able to control what blooms by taking the color values of objects/ materials/ textures to go over 1.0 just like in eevee. Without needing Color Correcition. ^^)

_image.fs:

uniform float bgl_RenderedTextureWidth;
uniform float bgl_RenderedTextureHeight;
uniform sampler2D bgl_RenderedTexture;

vec2 iResolution = vec2(bgl_RenderedTextureWidth, bgl_RenderedTextureHeight); // viewport resolution (in pixels)
uniform sampler2D iChannel0; //! buffer[xbuf: 1, wrap: GL_CLAMP_TO_EDGE, mipmap: false, filter: GL_NEAREST]

#define colorRange 1.0

//vec3 jodieReinhardTonemap(vec3 c){
//    float l = dot(c, vec3(0.2126, 0.7152, 0.0722));
//    vec3 tc = c / (c + 8.0);

//    return mix(c / (l + 80.0), tc, 0.55);
//}

vec3 bloomTile(float lod, vec2 offset, vec2 uv){
    return texture(iChannel0, uv * exp2(-lod) + offset).rgb;
}

vec3 getBloom(vec2 uv){

    vec3 blur = vec3(0.0);

    blur = pow(bloomTile(2., vec2(0.0,0.0), uv),vec3(2.2)) * 0.32 + blur;
    blur = pow(bloomTile(3., vec2(0.3,0.0), uv),vec3(2.2)) * 0.16 + blur;
    blur = pow(bloomTile(4., vec2(0.0,0.3), uv),vec3(2.2)) * 0.08 + blur;
    blur = pow(bloomTile(5., vec2(0.1,0.3), uv),vec3(2.2)) * 0.04 + blur;
    blur = pow(bloomTile(6., vec2(0.2,0.3), uv),vec3(2.2)) * 0.04 + blur;

    return blur * colorRange;
}

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
	vec2 uv = fragCoord.xy / iResolution.xy;
    
    vec3 color = pow(texture(bgl_RenderedTexture, uv).rgb * colorRange, vec3(2.2));
//    color = pow(color, vec3(2.2));
    color += pow(getBloom(uv), vec3(3.5));
    color = pow(color, vec3(1.0 / 4.5));
    color = max(vec3(0.0), color-0.0);
    
//    color = jodieReinhardTonemap(color);
    
	fragColor = vec4(color,1.0);
}

void main() {
    vec4 color = vec4(0.0, 0.0, 0.0, 1.0);
    mainImage(color, gl_FragCoord.xy);

    gl_FragColor = color;
}

edit: the line =~ 40 is also useless. => color = pow(color, vec3(2.2));

2 Likes

Thanks!

I have to port this to eevee soon (when aov hit eevee)

Then I will do the temporal bloom buffer shader again (where you can choose not only what blooms but what color / animate the bloom buffer)

is that not possible with the default shader in 3.0?
played a bit with it and first thing i tried was the bloom shader.

but that was it lol, did not actually go deeper into it. and no clue if those options can be called from a script.

What is the point of temporal bloom? The nice trail effect or to reduce flickering?

because i found a simpler solution to flickering.

And what is aov? something related to deferred rendering?

I am trying to imitate eevee bloom in the 2.5.0
without using render attachments.

my attempt to TheFinalBloom.blend (96.6 KB)

2 Likes

so currently the object can emit color / bloom that color

my buffer bloom can glow blue (emission) and bloom red (glow)

and yeah the temporal thing helps with popping, and can also be cranked way up yielding ‘streaks’ from fast moving blooming objects.

this is the patch I am waiting on being merged - https://developer.blender.org/D7010
AOV = render attachments = “arbitrary output values”

1 Like

A weapon effect glow. It never worked out, when i tried the upbge last year.

I wrote it… you have to know how to use it.

you need a bloom buffer (in render tab / attachments add 1 ‘custom’ )

you need the scripts attached to the scene(in camera typically)

and you need the objects to use attachments

https://blenderartists.org/uploads/default/original/4X/b/3/6/b36186695733f1a64069324b229ee0e4d61bc0cf.blend

1 Like

I mean, when I tried this upbge it didn’t work with my blend files. Nice work though.

yeah, nice work!

i modified it from the ‘Bloom2.blend’ in the first post so it works in some older versions
that does not have render attachments branch(0.2.4).

the file i uploaded don’t need the objects to use attachments. With hdr enabled pixel with energy higher than 1.0 (white) naturally blooms, just like eevee.

To port your projects to Upbge you may have to adapt the files and scripts.

To implement this specific shader, you need to import the modules and define the logic bricks exactly as they are in the original, even their names.

buffer_bloom_temporal_4b.blend (917.1 KB)

someone informed my my test file is not working for them - here is a update

edit - the upload was bugging

2 Likes

it didn’t work for me either in the past when i was using 0.2.4 branch with no attachments.

But this changed when i updated to 0.2.5. So may be the version their using.

Now, i can’t download your update. :roll_eyes: :worried:

@Murilo_Hilas - fixed I think -

WOW! This is pretty cool. amazing. Thank you. :heart:

the gravitational lensing / distortion effect is awesome!!!

1 Like

ok - I just looked this over - what we can do - is any object whose bloom attachment buffer is not zero for that frame- we can clip that object in over the final result - yielding glow but not emit as a buffer

I have not applied it here yet

The HDR pipeline is enough for the basic bloom. With hdr enabled pixels with energy higher than 1.0 (white) naturally blooms, just like eevee.
the user can them use attachments only to customize the final result. (optional)

this is a general-purpose multi-estaged color-bleeding shader
that works in many scenarios and lighting conditions.

for now we can:

  • control what glows :ballot_box_with_check: - high-energy pixels naturally blooms
  • make it overcast, heaven-like, fantasy scenarios :ballot_box_with_check: (everything blooms)
  • temporal variables. yields trails from fast moving blooming objects :ballot_box_with_check: (‘streaks’)

we will need render attachments to do the following:

  • control how the shader reacts to specific objects
  • ‘glow behind’ - make outline glow (to highlight individual objects)
  • make some blooming moving objects yield trails but others not to.

The problem quoted above was solved here and temporal averaging was added. You can now control if it flickers, have trail effect or something in between. Enjoy: hdr_motion_bloom.blend (128.6 KB)

Preview:

4 Likes

This is amazing, really fun to see it in realtime, great work!

1 Like

thank you. :blush:
soon i’ll try to make it more physically correct and do render attachments enhancements.

2 Likes