2d HDR Bloom Implementation Issues, Godot 3.0.5 **Engine expert needed**

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By project_Blue_Bird

Can someone with technical knowledge about the engine please explain to me why HDR bloom isn’t possible GLSL 2.0 ? (I’m making the assumption my tablet is running GLSL 2.0)

I decided to custom write my own shader code to do this as the environment node was tanking performance on mobile in 2d mode. Otherwise 60fps or greater.

Code im using is fairly bog standard and unfinished.

shader_type canvas_item;

vec4 sample_glow_pixel(sampler2D tex, vec2 uv, float lod){
float hdr_threshold = 1.0;
return max(textureLod(tex, uv, lod) - hdr_threshold, vec4(0.0));

void fragment(){
vec4 screen_Texture_Sample = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0);
vec4 sample_Glowing_Pixel = sample_glow_pixel(SCREEN_TEXTURE, SCREEN_UV, 3.0); //mipmapped screen sample used for blur and HDR value checking.

vec4 final_Colour = vec4(screen_Texture_Sample.rgb + sample_Glowing_Pixel.rgb, screen_Texture_Sample.a); //combine both screen samples here before output.
COLOR = final_Colour; 


Now this code does work on my pc but not on tablet. I have tried adding it to both a sprite and a texturerect but to no avail.

I have broken down the code and have tested chunks of it on tablet.
The shader does have access to SCREEN_TEXTURE and SCREEN_UV (otherwise it would be a big white rectangle displayed if it didnt as the default texture is a a white rectangle)
and shader can both Mipmap on both pc and tablet.
Max function Does work on tablet and pc.

However for some reason Godot does not wont to combine both the screen sample and the hdr mipmapped sample together and instead I just get the sprite/texturerect grabbing
the underlying Screen pixel with no glow surrounding areas above LDR values.

Can someone with technical knowledge in godot explain this to me?

would it be possible to have 2d glow GLES 2.0 in godot via viewports and combining render textures?

Many Thanks.

:bust_in_silhouette: Reply From: project_Blue_Bird

Just to answer my own question in case anyone else is searching for a specific answer on this issue as well.

Unfortunately in GLES 2.0 HDR values (those above 1.0 or LDR) are clamped back down to 1.0 when executing the shader code on GPU. (or at least this is my understanding of it)

So when we go to compare values in the “sampleglowpixel” function above the value that is returned is always 0, and hence the reason why our render texture is blank or see through. Because there is literally no information being rendered to it.

Now we could lower the HDR threshold but that would make everything in our scene glow unless you designed your colour gamut around this issue (probably too much work).

There probably is some other other method to achieve this on GPU but at the moment unfortunately its pre-rendered textures and more textures.

This also appears to be the case for GLES 3.0 and framebuffer allocation in the project settings set to 2D.

AnthyG | 2021-01-09 16:16

Indeed, you need to set framebuffer allocation to 3D to use glow in 2D.

Calinou | 2021-01-09 16:16