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