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 <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2022-09-18 05:00:52 +01:00
parent f2970bc697
commit 5ac8b7fc56
No known key found for this signature in database
GPG Key ID: D3A4405BE6CC17F4
3 changed files with 7 additions and 4 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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.