From 50b75bdd277e693e40d6be1445c8a1831ad6abe8 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Sat, 26 Feb 2022 14:33:26 +0300 Subject: [PATCH] Make blur effect alpha-aware --- libs/gfx/source/effect/blur.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libs/gfx/source/effect/blur.cpp b/libs/gfx/source/effect/blur.cpp index fff3d60f..2d00238a 100644 --- a/libs/gfx/source/effect/blur.cpp +++ b/libs/gfx/source/effect/blur.cpp @@ -55,9 +55,15 @@ void main() vec4 result = vec4(0.0); for (int i = -BLUR_SIZE; i <= BLUR_SIZE; ++i) { - result += texture(u_texture, texcoord + float(i) * direction * u_inv_texture_size) * coeffs[i + BLUR_SIZE]; + vec4 p = texture(u_texture, texcoord + float(i) * direction * u_inv_texture_size); + float c = coeffs[i + BLUR_SIZE]; + result.rgb += p.rgb * p.a * c; + result.a += p.a * c; } - out_color = result; + if (result.a == 0.0) + out_color = result; + else + out_color = vec4(result.rgb / result.a, result.a); } )";