Files
demo-godot-2502/blur.gdshader
2025-02-16 14:28:47 +01:00

23 lines
672 B
Plaintext

shader_type canvas_item;
uniform float sigma: hint_range(0.0, 20.0) = 3.3;
float gaussian(float x, float std) {
return exp(x * x / (-2.0 * std * std)) / (sqrt(2.0 * PI) * std);
}
void fragment() {
float ksize = round(3.0 * sigma);
float std = (sigma != 0.0 ? sigma : 1.0);
vec4 col = vec4(0.0);
float total_weight = 0.0;
for(float i = -ksize ; i <= ksize; ++i) {
for(float j = -ksize; j <= ksize; ++j) {
float weight = gaussian(i, std) * gaussian(j, std);
col += texture(TEXTURE, UV + vec2(i, j) * SCREEN_PIXEL_SIZE) * weight;
total_weight += weight;
}
}
COLOR = col / total_weight;
}