From 8b91d952589fd9be9402c126220333b49b3540a2 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Fri, 9 Feb 2024 20:09:25 +0200 Subject: [PATCH] Make alpha affect all of the blend modes besides Normal and Screen --- src/Shaders/BlendLayers.gdshader | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Shaders/BlendLayers.gdshader b/src/Shaders/BlendLayers.gdshader index 4b56eed3e..40a667f39 100644 --- a/src/Shaders/BlendLayers.gdshader +++ b/src/Shaders/BlendLayers.gdshader @@ -55,11 +55,11 @@ vec3 rgb_to_hsl(vec3 rgb) vec4 blend(int blend_type, vec4 current_color, vec4 prev_color, float opacity) { - if (current_color.a <= 0.001 || opacity <= 0.001) { + current_color.a *= opacity; // Combine the layer opacity + if (current_color.a <= 0.001) { return prev_color; } vec4 result; - current_color.a *= opacity; // Combine the layer opacity switch(blend_type) { case 1: // Darken result.rgb = min(prev_color.rgb, current_color.rgb); @@ -77,7 +77,7 @@ vec4 blend(int blend_type, vec4 current_color, vec4 prev_color, float opacity) { result.rgb = max(prev_color.rgb, current_color.rgb); break; case 6: // Screen - result.rgb = mix(prev_color.rgb, 1.0 - (1.0 - prev_color.rgb) * (1.0 - current_color.rgb), current_color.a); + result.rgb = 1.0 - (1.0 - prev_color.rgb) * (1.0 - current_color.rgb); break; case 7: // Color dodge result.rgb = prev_color.rgb / (1.0 - current_color.rgb); @@ -127,9 +127,10 @@ vec4 blend(int blend_type, vec4 current_color, vec4 prev_color, float opacity) { result.rgb = hsl_to_rgb(vec3(prev_hsl.r, prev_hsl.g, current_hsl.b)); break; default: // Normal (case 0) - result.rgb = mix(prev_color.rgb, current_color.rgb, current_color.a); + result.rgb = current_color.rgb; break; } + result.rgb = mix(prev_color.rgb, result.rgb, current_color.a); result.a = prev_color.a * (1.0 - current_color.a) + current_color.a; result = clamp(result, 0.0, 1.0); return mix(current_color, result, prev_color.a);