Gaussian Glow

this is sort of unusable but eh

Shader code
shader_type canvas_item;


uniform float BLOOM_THRESHOLD = 0.7;
uniform float BLOOM_INTENSITY = 3.0;

uniform int BLUR_ITERATIONS = 3;
uniform float BLUR_SIZE = 0.03;
uniform int BLUR_SUBDIVISIONS = 32;

vec3 getHDR(vec3 tex) {
    return max((tex - BLOOM_THRESHOLD) * BLOOM_INTENSITY, vec3(0.0));
}

vec3 gaussian(sampler2D sampler, vec2 uv) {
    vec3 sum = vec3(0.0);

    for (int i = 1; i <= BLUR_ITERATIONS; i++) {
        float angle = 360.0 / float(BLUR_SUBDIVISIONS);

        for (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(texture(sampler, uv + vec2(c, s) * dist).xyz);
        }
    }

    sum /= float(BLUR_ITERATIONS * BLUR_SUBDIVISIONS);
    return sum * BLOOM_INTENSITY;
}

vec3 blend(vec3 a, vec3 b) {
    return 1.0 - (1.0 - a) * (1.0 - b);
}

void fragment() {
    vec4 tx = texture(TEXTURE, UV);
    vec3 result = gaussian(TEXTURE, UV);

	vec4 bg = vec4(result, 1);

    float gray = dot(bg.rgb, vec3(0.299, 0.587, 0.114));
    bg = vec4(bg.rgb, gray);

	vec4 final = bg;

	final = bg + tx;

    COLOR = final;
}
Tags
glow
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from RuverQ

Squareish

2D Liquid Fill Inside Sphere

Related shaders

Glow effect 2D

Back glow effect for item backgrounds

Sobel with Gaussian filter

Subscribe
Notify of
guest

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Galla
Galla
6 months ago

This shader broke my project… if you put a high number in it it freeze the project and you cant load or anything. Tried restart but nothing loads it just freeze. Dont download!

Last edited 6 months ago by Galla
Gogo
Gogo
2 months ago
Reply to  Galla

Same here, it didn’t worked at first, tried pumping up the numbers, and it broke everything. Still, I was able to recover my work, but it kinda scared me at first.

It was my fault by pumping the number of iterations, but yeah, take this as a warning, it could mess your project up.