From ff51280ecb5969a7559c5c7edffb0ec96f44972c Mon Sep 17 00:00:00 2001 From: pkv Date: Fri, 28 Feb 2025 22:13:37 +0100 Subject: [PATCH] nv-filters: Set max effective threshold to 0.95 for Background removal The threshold THR in Background removal filter has the following effect: - if alpha if between [THR - 0.1; THR], alpha is interpolated; - if alpha >= THR, alpha is set to 1.0; - if alpha <= THR - 0.1, alpha is set to 0. It was introduced in order to smooth the alpha at the edges of the foreground. This works fine unless THR == 1, where there can be bulk pixels with alpha which will be interpolated as if they were at the edge; in order to ensure that a bulk area with alpha set to 1.0 is well defined, the max threshold is now set to 0.95 (so if the user picks a unity threshold, a value of 0.95 will actually be used). This fixes a bug in third party plugins which rely on a bulk foreground safely set at alpha == 1.0. [1] [1] https://github.com/FiniteSingularity/obs-stroke-glow-shadow/issues/61 Signed-off-by: pkv --- plugins/nv-filters/nvidia-videofx-filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/nv-filters/nvidia-videofx-filter.c b/plugins/nv-filters/nvidia-videofx-filter.c index f721f6d96..3214c685d 100644 --- a/plugins/nv-filters/nvidia-videofx-filter.c +++ b/plugins/nv-filters/nvidia-videofx-filter.c @@ -834,7 +834,7 @@ static void draw_greenscreen_blur(struct nvvfx_data *filter, bool has_blur) gs_effect_set_texture_srgb(filter->blur_param, filter->blur_texture); } else { gs_effect_set_texture(filter->mask_param, filter->alpha_texture); - gs_effect_set_float(filter->threshold_param, filter->threshold); + gs_effect_set_float(filter->threshold_param, min(filter->threshold, 0.95f)); } gs_effect_set_texture_srgb(filter->image_param, gs_texrender_get_texture(filter->render));