From fa8e3a17c16c2681c60dbb0dfb9f56dd1cb8f3d3 Mon Sep 17 00:00:00 2001 From: Simon Schneegans Date: Sun, 8 May 2022 14:15:54 +0200 Subject: [PATCH] :wrench: Add compositing snippet --- src/shaderSnippets.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/shaderSnippets.js b/src/shaderSnippets.js index 9b31e5c..40bc23f 100644 --- a/src/shaderSnippets.js +++ b/src/shaderSnippets.js @@ -51,6 +51,17 @@ function math2D() { `; } +// The Shell.GLSLEffect uses straight alpha blending. This helper method allows +// compositing color values in the shader in the same way. +function compositing() { + return ` + vec4 blendOver(vec4 over, vec4 under) { + float alpha = over.a + under.a * (1.0 - over.a); + return vec4((over.rgb * over.a + under.rgb * under.a * (1.0 - over.a)) / alpha, alpha); + } + `; +} + // This method returns a mask which smoothly transitions towards zero when approaching // the window's borders. There is a variant which takes the transition area width in // pixels and one which takes this as a percentage.