From 5ac8b7fc562b393ab91021b149706a7dab060496 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Sun, 18 Sep 2022 05:00:52 +0100 Subject: [PATCH] backend: gl: use gaussian blur for shadow dual kawase is fast but its blur size is coarse grained, which sometimes makes the shadow ugly. Signed-off-by: Yuxuan Shui --- src/backend/gl/gl_common.c | 6 +++--- src/kernel.c | 2 +- src/kernel.h | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/backend/gl/gl_common.c b/src/backend/gl/gl_common.c index e7416083..e019bd6e 100644 --- a/src/backend/gl/gl_common.c +++ b/src/backend/gl/gl_common.c @@ -1174,11 +1174,11 @@ struct backend_shadow_context *gl_create_shadow_context(backend_t *base, double auto ctx = ccalloc(1, struct gl_shadow_context); ctx->radius = radius; - struct dual_kawase_blur_args args = { + struct gaussian_blur_args args = { .size = (int)radius, - .strength = 0, + .deviation = gaussian_kernel_std_for_size(radius, 0.5 / 256.0), }; - ctx->blur_context = gl_create_blur_context(base, BLUR_METHOD_DUAL_KAWASE, &args); + ctx->blur_context = gl_create_blur_context(base, BLUR_METHOD_GAUSSIAN, &args); return (struct backend_shadow_context *)ctx; } diff --git a/src/kernel.c b/src/kernel.c index a96e9f30..cbb5cd12 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -103,7 +103,7 @@ static inline double estimate_first_row_sum(double size, double r) { /// Pick a suitable gaussian kernel standard deviation for a given kernel size. The /// returned radius is the maximum possible radius (<= size*2) that satisfies no sum of /// the rows in the kernel are less than `row_limit` (up to certain precision). -static inline double gaussian_kernel_std_for_size(double size, double row_limit) { +double gaussian_kernel_std_for_size(double size, double row_limit) { assert(size > 0); if (row_limit >= 1.0 / 2.0 / size) { return size * 2; diff --git a/src/kernel.h b/src/kernel.h index 85997de3..d1dd2eee 100644 --- a/src/kernel.h +++ b/src/kernel.h @@ -22,6 +22,9 @@ double attr_pure sum_kernel_normalized(const conv *map, int x, int y, int width, /// `size`. conv *gaussian_kernel(double r, int size); +/// Estimate the best standard deviation for a give kernel size. +double gaussian_kernel_std_for_size(double size, double row_limit); + /// Create a gaussian kernel with auto detected standard deviation. The choosen standard /// deviation tries to make sure the outer most pixels of the shadow are completely /// transparent.