Glow/Bloom shader using GLES2 in Godot 3.1+

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

I have a shader that produces glow perfectly in GLES3, but won’t work in GLES2 because of the lack of textureLod available. Do you have any idea how to make it work?

It looks like this in the current state (not working in GLES2, but perfect in GLES3, as originally posted by Zylann):

    shader_type canvas_item;

uniform float amount : hint_range(0,0.5);

vec4 sample_glow_pixel(sampler2D tex, vec2 uv) {
   float hdr_threshold = amount; 
    return max(textureLod(tex, uv, 2.0) - hdr_threshold, vec4(0.0));
}

void fragment() {
    vec2 ps = SCREEN_PIXEL_SIZE;
    // Get blurred color from pixels considered glowing
    vec4 col0 = sample_glow_pixel(SCREEN_TEXTURE, SCREEN_UV + vec2(-ps.x, 0));
    vec4 col1 = sample_glow_pixel(SCREEN_TEXTURE, SCREEN_UV + vec2(ps.x, 0));
    vec4 col2 = sample_glow_pixel(SCREEN_TEXTURE, SCREEN_UV + vec2(0, -ps.y));
    vec4 col3 = sample_glow_pixel(SCREEN_TEXTURE, SCREEN_UV + vec2(0, ps.y));

    vec4 col = texture(SCREEN_TEXTURE, SCREEN_UV);
    vec4 glowing_col = 0.25 * (col0 + col1 + col2 + col3);

    COLOR = vec4(col.rgb + glowing_col.rgb, col.a);
}