From 67d6df0a70d0ed87b54ca3aa5a649968ac557d8b Mon Sep 17 00:00:00 2001 From: Simon Schneegans Date: Thu, 9 Jun 2022 08:06:43 +0200 Subject: [PATCH] :wrench: Fix incompatibilites with OpenGL 1.0 --- kwin/build.sh | 1 - resources/shaders/common.glsl | 22 +++++++++++----------- resources/shaders/tv.frag | 28 ++++++++++++++-------------- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/kwin/build.sh b/kwin/build.sh index 95550c2..447d8dd 100755 --- a/kwin/build.sh +++ b/kwin/build.sh @@ -51,7 +51,6 @@ generate() { } > "${BUILD_DIR}/kwin4_effect_$1/contents/shaders/$1_core.frag" { - echo "#version 100" echo "#define KWIN_LEGACY" echo "" echo "// This file is automatically generated during the build process." diff --git a/resources/shaders/common.glsl b/resources/shaders/common.glsl index 6a2dc8f..947420d 100644 --- a/resources/shaders/common.glsl +++ b/resources/shaders/common.glsl @@ -29,7 +29,7 @@ // Furthermore, there is the global input "vec2 iTexCoord" and the output "vec4 oColor". -#ifdef KWIN // -------------------------------------------------------------------------- +#if defined(KWIN) // -------------------------------------------------------------------- uniform float forOpening; uniform sampler2D sampler; @@ -43,13 +43,13 @@ bool uForOpening = forOpening == 1.0; in vec2 texcoord0; out vec4 fragColor; -#define uTexture sampler; +#define uTexture sampler #define uProgress animationProgress #define uPadding 0.0 #define iTexCoord texcoord0 #define oColor fragColor -#elif KWIN_LEGACY // -------------------------------------------------------------------- +#elif defined(KWIN_LEGACY) // ----------------------------------------------------------- uniform float forOpening; uniform sampler2D sampler; @@ -62,11 +62,11 @@ bool uForOpening = forOpening == 1.0; varying vec2 texcoord0; -#define uTexture sampler; +#define uTexture sampler #define uProgress animationProgress #define uPadding 0.0 #define iTexCoord texcoord0 -#define oColor gl_fragColor +#define oColor gl_FragColor #else // GNOME -------------------------------------------------------------------------- @@ -99,7 +99,7 @@ vec4 alphaOver(vec4 under, vec4 over) { // Taken from here: // https://gitlab.gnome.org/GNOME/mutter/-/blob/main/clutter/clutter/clutter-easing.c -float easeOutQuad(float x) { return -1.0 * x * (x - 2); } +float easeOutQuad(float x) { return -1.0 * x * (x - 2.0); } // --------------------------------------------------------------------- edge mask helpers @@ -108,10 +108,10 @@ float easeOutQuad(float x) { return -1.0 * x * (x - 2); } // pixels and one which takes this as a percentage. float getEdgeMask(vec2 uv, vec2 maxUV, float fadeWidth) { float mask = 1.0; - mask *= smoothstep(0, 1, clamp(uv.x / fadeWidth, 0, 1)); - mask *= smoothstep(0, 1, clamp(uv.y / fadeWidth, 0, 1)); - mask *= smoothstep(0, 1, clamp((maxUV.x - uv.x) / fadeWidth, 0, 1)); - mask *= smoothstep(0, 1, clamp((maxUV.y - uv.y) / fadeWidth, 0, 1)); + mask *= smoothstep(0.0, 1.0, clamp(uv.x / fadeWidth, 0.0, 1.0)); + mask *= smoothstep(0.0, 1.0, clamp(uv.y / fadeWidth, 0.0, 1.0)); + mask *= smoothstep(0.0, 1.0, clamp((maxUV.x - uv.x) / fadeWidth, 0.0, 1.0)); + mask *= smoothstep(0.0, 1.0, clamp((maxUV.y - uv.y) / fadeWidth, 0.0, 1.0)); return mask; } @@ -124,7 +124,7 @@ float getEdgeMask(vec2 uv, vec2 maxUV, float fadeWidth) { // (offset = 0), ontop the window borders (offset = 0.5) or outside the window borders // (offset = 1). float getAbsoluteEdgeMask(float fadePixels, float offset) { - float padding = max(0, uPadding - fadePixels * offset); + float padding = max(0.0, uPadding - fadePixels * offset); vec2 uv = iTexCoord.st * uSize - padding; return getEdgeMask(uv, uSize - 2.0 * padding, fadePixels); } diff --git a/resources/shaders/tv.frag b/resources/shaders/tv.frag index 2d84dde..f6c3ccc 100644 --- a/resources/shaders/tv.frag +++ b/resources/shaders/tv.frag @@ -23,10 +23,10 @@ const float FF_TIME = 0.1; // Relative time for the final fade to transpare const float SCALING = 0.5; // Additional vertical scaling of the window. void main() { - float progress = uForOpening ? 1.0 - easeOutQuad(uProgress) : easeOutQuad(uProgress); + float prog = uForOpening ? 1.0 - easeOutQuad(uProgress) : easeOutQuad(uProgress); // Scale down the window vertically. - float scale = 1.0 / mix(1.0, SCALING, progress) - 1.0; + float scale = 1.0 / mix(1.0, SCALING, prog) - 1.0; vec2 coords = iTexCoord.st; coords.y = coords.y * (scale + 1.0) - scale * 0.5; @@ -34,22 +34,22 @@ void main() { // tb refers to the top-bottom animation. // lr refers to the left-right animation. // ff refers to the final fade animation. - float tbProgress = smoothstep(0, 1, clamp(progress / TB_TIME, 0, 1)); - float lrProgress = smoothstep(0, 1, clamp((progress - LR_DELAY) / LR_TIME, 0, 1)); - float ffProgress = smoothstep(0, 1, clamp((progress - 1.0 + FF_TIME) / FF_TIME, 0, 1)); + float tbProg = smoothstep(0.0, 1.0, clamp(prog / TB_TIME, 0.0, 1.0)); + float lrProg = smoothstep(0.0, 1.0, clamp((prog - LR_DELAY) / LR_TIME, 0.0, 1.0)); + float ffProg = smoothstep(0.0, 1.0, clamp((prog - 1.0 + FF_TIME) / FF_TIME, 0.0, 1.0)); // This is a top-center-bottom gradient in [0..1..0] - float tb = coords.y * 2; - tb = tb < 1 ? tb : 2 - tb; + float tb = coords.y * 2.0; + tb = tb < 1.0 ? tb : 2.0 - tb; // This is a left-center-right gradient in [0..1..0] - float lr = coords.x * 2; - lr = lr < 1 ? lr : 2 - lr; + float lr = coords.x * 2.0; + lr = lr < 1.0 ? lr : 2.0 - lr; // Combine the progress values with the gradients to create the alpha masks. - float tbMask = 1 - smoothstep(0, 1, clamp((tbProgress - tb) / BLUR_WIDTH, 0, 1)); - float lrMask = 1 - smoothstep(0, 1, clamp((lrProgress - lr) / BLUR_WIDTH, 0, 1)); - float ffMask = 1 - smoothstep(0, 1, ffProgress); + float tbMask = 1.0 - smoothstep(0.0, 1.0, clamp((tbProg - tb) / BLUR_WIDTH, 0.0, 1.0)); + float lrMask = 1.0 - smoothstep(0.0, 1.0, clamp((lrProg - lr) / BLUR_WIDTH, 0.0, 1.0)); + float ffMask = 1.0 - smoothstep(0.0, 1.0, ffProg); // Assemble the final alpha value. float mask = tbMask * lrMask * ffMask; @@ -57,11 +57,11 @@ void main() { oColor = texture2D(uTexture, coords); // Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied. - if (oColor.a > 0) { + if (oColor.a > 0.0) { oColor.rgb /= oColor.a; } - oColor.rgb = mix(oColor.rgb, uColor * oColor.a, smoothstep(0, 1, progress)); + oColor.rgb = mix(oColor.rgb, uColor * oColor.a, smoothstep(0.0, 1.0, prog)); oColor.a *= mask; // These are pretty useful for understanding how this works.