Gaussian blur
#5
I played around with it a bit and added a toggle --> with the "Blur Regler" line you can adjust the blur.


shader_type canvas_item;

// =====================
// Gaussian Blur (Original + extrem starker Bereich)
// =====================

const float COHERENT_BASE = 1920.0;

// Basis-Radius (Qualität)
uniform int radius : hint_range(1, 32) = 24;

// ? Blur-Regler (jetzt wirklich extrem)
uniform float blur_strength : hint_range(20.0, 60.0) = 50.0;

uniform float opacity : hint_range(0.0, 1.0) = 1.0;
uniform int use_smooth : hint_enum("sharp:0","smooth:1");

global uniform int ScreenRotation;
global uniform sampler2D CurrentScreenTexture;

// ---------------------
vec4 sampleCurrentScreen(vec2 uv, vec2 screen_pixel_size) {
    vec2 rotated_uv = uv * (1.0 - screen_pixel_size);
    if (ScreenRotation == 2) {
        rotated_uv = vec2(uv.y, 1.0 - uv.x);
    } else if (ScreenRotation == 3) {
        rotated_uv = vec2(uv.x, uv.y);
    } else if (ScreenRotation == 4) {
        rotated_uv = vec2(1.0 - uv.y, uv.x);
    }
    return texture(CurrentScreenTexture, rotated_uv).bgra;
}

// ---------------------
float gaussian(float x, float sigma) {
    return exp(-(x * x) / (2.0 * sigma * sigma));
}

void fragment() {
    vec2 uv = SCREEN_UV;

    float base_texel = 1.0 / COHERENT_BASE;
    vec2 texel = vec2(
        base_texel,
        base_texel * SCREEN_PIXEL_SIZE.y / SCREEN_PIXEL_SIZE.x
    );

    // Radius leicht dynamisch an Stärke koppeln
    int r = int(float(radius) * (blur_strength / 25.0));

    float sigma = float® * 0.5 * (blur_strength / 25.0); // höhere Werte → mehr Weichheit

    vec3 accum_rgb = vec3(0.0);
    float accum_a = 0.0;
    float weight_sum = 0.0;

    for (int x = -r; x <= r; x++) {
        for (int y = -r; y <= r; y++) {

            vec2 offset = vec2(float(x), float(y)) * texel;

            float dist = length(vec2(float(x), float(y)));
            float w = gaussian(dist, sigma);

            vec4 s = sampleCurrentScreen(uv + offset, SCREEN_PIXEL_SIZE);

            accum_rgb += s.rgb * w;
            accum_a  += s.a * w;
            weight_sum += w;
        }
    }

    vec3 blurred_rgb = accum_rgb / weight_sum;
    float blurred_a  = accum_a  / weight_sum;

    vec4 final_color = vec4(blurred_rgb, blurred_a * opacity);

    if (use_smooth == 1) {
        final_color.a *= texture(TEXTURE, UV).r;
    }
    final_color.a *= COLOR.a;

    COLOR = final_color;
}
  Reply


Messages In This Thread
Gaussian blur - by siamirold - 03-24-2026, 06:27 AM
RE: Gaussian blur - by Wombatant1 - 03-24-2026, 12:31 PM
RE: Gaussian blur - by bobbob9999 - 03-27-2026, 12:47 PM
RE: Gaussian blur - by whizzkid - 03-31-2026, 09:59 AM
RE: Gaussian blur - by whizzkid - 04-01-2026, 07:02 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)