WorldEnvironment Glow invisible over a Shader

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

Hello,

I have a 2D scene with 2D objects that have glow through an WorldEnvironment.
This works fine, until I add a background with a Shader (simple 2D polygon with a shader that simulates a “deep space” effect), which makes the glow not show. Is there a way to fix that?

I may need your shader code to understand what happened.

dethland | 2021-09-08 20:15

:bust_in_silhouette: Reply From: Amateur.game.dev.

you could use this shader which simulates a glow effect:

shader_type canvas_item;
render_mode blend_premul_alpha;

uniform float radius = 1.0;
uniform float amount = 0.5;

void fragment() {
    float r = radius;
    vec2 ps = TEXTURE_PIXEL_SIZE;
    vec4 col = texture(TEXTURE, UV);
    vec4 glow = col;

    glow += texture(TEXTURE, UV + vec2(-r, -r) * ps);
    glow += texture(TEXTURE, UV + vec2(-r, 0.0) * ps);
    glow += texture(TEXTURE, UV + vec2(-r, r) * ps);
    glow += texture(TEXTURE, UV + vec2(0.0, -r) * ps);
    glow += texture(TEXTURE, UV + vec2(0.0, r) * ps);
    glow += texture(TEXTURE, UV + vec2(r, -r) * ps);
    glow += texture(TEXTURE, UV + vec2(r, 0.0) * ps);
    glow += texture(TEXTURE, UV + vec2(r, r) * ps);

    r *= 2.0;
    glow += texture(TEXTURE, UV + vec2(-r, -r) * ps);
    glow += texture(TEXTURE, UV + vec2(-r, 0.0) * ps);
    glow += texture(TEXTURE, UV + vec2(-r, r) * ps);
    glow += texture(TEXTURE, UV + vec2(0.0, -r) * ps);
    glow += texture(TEXTURE, UV + vec2(0.0, r) * ps);
    glow += texture(TEXTURE, UV + vec2(r, -r) * ps);
    glow += texture(TEXTURE, UV + vec2(r, 0.0) * ps);
    glow += texture(TEXTURE, UV + vec2(r, r) * ps);

    glow /= 21.0;
    glow *= amount;
    col.rgb *= col.a;

    COLOR = glow + col;
}