From ecd17cff6c6b77e816f77970c8bc2a9b6e1a00f5 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Wed, 30 Jan 2019 03:37:46 +0100 Subject: [PATCH] filter-sdf-effects: Fix colored shadows changing image Colored shadows previously had an effect on the image color, but this is incorrect if the image is fully opaque. This fixes it by using premultiplied alpha mixing instead. --- data/effects/sdf-shadow.effect | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/data/effects/sdf-shadow.effect b/data/effects/sdf-shadow.effect index a3e1c856..2ffed034 100644 --- a/data/effects/sdf-shadow.effect +++ b/data/effects/sdf-shadow.effect @@ -118,11 +118,14 @@ float4 PS_SDFShadow_v1_1(VertDataOut v_in) : TARGET float t1 = sdf_distance - _outer_min; float t2 = clamp(t1 / delta, 0., 1.); - final = lerp(final, _outer_color, 1. - t2); + final = lerp(final, _outer_color, (1. - t2) * _outer_color.a); } // Base Image - final += base; + if (base.a > 0.) { + float3 rgb = base.rgb / base.a; + final = lerp(final, base, base.a); + } //! Inner Shadow // Are we allowed to draw an inner shadow?