🔧 Fix incompatibilites with OpenGL 1.0

This commit is contained in:
Simon Schneegans
2022-06-09 08:06:43 +02:00
parent e96b42a3f7
commit 67d6df0a70
3 changed files with 25 additions and 26 deletions
-1
View File
@@ -51,7 +51,6 @@ generate() {
} > "${BUILD_DIR}/kwin4_effect_$1/contents/shaders/$1_core.frag" } > "${BUILD_DIR}/kwin4_effect_$1/contents/shaders/$1_core.frag"
{ {
echo "#version 100"
echo "#define KWIN_LEGACY" echo "#define KWIN_LEGACY"
echo "" echo ""
echo "// This file is automatically generated during the build process." echo "// This file is automatically generated during the build process."
+11 -11
View File
@@ -29,7 +29,7 @@
// Furthermore, there is the global input "vec2 iTexCoord" and the output "vec4 oColor". // Furthermore, there is the global input "vec2 iTexCoord" and the output "vec4 oColor".
#ifdef KWIN // -------------------------------------------------------------------------- #if defined(KWIN) // --------------------------------------------------------------------
uniform float forOpening; uniform float forOpening;
uniform sampler2D sampler; uniform sampler2D sampler;
@@ -43,13 +43,13 @@ bool uForOpening = forOpening == 1.0;
in vec2 texcoord0; in vec2 texcoord0;
out vec4 fragColor; out vec4 fragColor;
#define uTexture sampler; #define uTexture sampler
#define uProgress animationProgress #define uProgress animationProgress
#define uPadding 0.0 #define uPadding 0.0
#define iTexCoord texcoord0 #define iTexCoord texcoord0
#define oColor fragColor #define oColor fragColor
#elif KWIN_LEGACY // -------------------------------------------------------------------- #elif defined(KWIN_LEGACY) // -----------------------------------------------------------
uniform float forOpening; uniform float forOpening;
uniform sampler2D sampler; uniform sampler2D sampler;
@@ -62,11 +62,11 @@ bool uForOpening = forOpening == 1.0;
varying vec2 texcoord0; varying vec2 texcoord0;
#define uTexture sampler; #define uTexture sampler
#define uProgress animationProgress #define uProgress animationProgress
#define uPadding 0.0 #define uPadding 0.0
#define iTexCoord texcoord0 #define iTexCoord texcoord0
#define oColor gl_fragColor #define oColor gl_FragColor
#else // GNOME -------------------------------------------------------------------------- #else // GNOME --------------------------------------------------------------------------
@@ -99,7 +99,7 @@ vec4 alphaOver(vec4 under, vec4 over) {
// Taken from here: // Taken from here:
// https://gitlab.gnome.org/GNOME/mutter/-/blob/main/clutter/clutter/clutter-easing.c // 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 // --------------------------------------------------------------------- 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. // pixels and one which takes this as a percentage.
float getEdgeMask(vec2 uv, vec2 maxUV, float fadeWidth) { float getEdgeMask(vec2 uv, vec2 maxUV, float fadeWidth) {
float mask = 1.0; float mask = 1.0;
mask *= smoothstep(0, 1, clamp(uv.x / fadeWidth, 0, 1)); mask *= smoothstep(0.0, 1.0, clamp(uv.x / fadeWidth, 0.0, 1.0));
mask *= smoothstep(0, 1, clamp(uv.y / fadeWidth, 0, 1)); mask *= smoothstep(0.0, 1.0, clamp(uv.y / fadeWidth, 0.0, 1.0));
mask *= smoothstep(0, 1, clamp((maxUV.x - uv.x) / fadeWidth, 0, 1)); mask *= smoothstep(0.0, 1.0, clamp((maxUV.x - uv.x) / fadeWidth, 0.0, 1.0));
mask *= smoothstep(0, 1, clamp((maxUV.y - uv.y) / fadeWidth, 0, 1)); mask *= smoothstep(0.0, 1.0, clamp((maxUV.y - uv.y) / fadeWidth, 0.0, 1.0));
return mask; 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 = 0), ontop the window borders (offset = 0.5) or outside the window borders
// (offset = 1). // (offset = 1).
float getAbsoluteEdgeMask(float fadePixels, float offset) { 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; vec2 uv = iTexCoord.st * uSize - padding;
return getEdgeMask(uv, uSize - 2.0 * padding, fadePixels); return getEdgeMask(uv, uSize - 2.0 * padding, fadePixels);
} }
+14 -14
View File
@@ -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. const float SCALING = 0.5; // Additional vertical scaling of the window.
void main() { 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. // 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; vec2 coords = iTexCoord.st;
coords.y = coords.y * (scale + 1.0) - scale * 0.5; coords.y = coords.y * (scale + 1.0) - scale * 0.5;
@@ -34,22 +34,22 @@ void main() {
// tb refers to the top-bottom animation. // tb refers to the top-bottom animation.
// lr refers to the left-right animation. // lr refers to the left-right animation.
// ff refers to the final fade animation. // ff refers to the final fade animation.
float tbProgress = smoothstep(0, 1, clamp(progress / TB_TIME, 0, 1)); float tbProg = smoothstep(0.0, 1.0, clamp(prog / TB_TIME, 0.0, 1.0));
float lrProgress = smoothstep(0, 1, clamp((progress - LR_DELAY) / LR_TIME, 0, 1)); float lrProg = smoothstep(0.0, 1.0, clamp((prog - LR_DELAY) / LR_TIME, 0.0, 1.0));
float ffProgress = smoothstep(0, 1, clamp((progress - 1.0 + FF_TIME) / FF_TIME, 0, 1)); 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] // This is a top-center-bottom gradient in [0..1..0]
float tb = coords.y * 2; float tb = coords.y * 2.0;
tb = tb < 1 ? tb : 2 - tb; tb = tb < 1.0 ? tb : 2.0 - tb;
// This is a left-center-right gradient in [0..1..0] // This is a left-center-right gradient in [0..1..0]
float lr = coords.x * 2; float lr = coords.x * 2.0;
lr = lr < 1 ? lr : 2 - lr; lr = lr < 1.0 ? lr : 2.0 - lr;
// Combine the progress values with the gradients to create the alpha masks. // 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 tbMask = 1.0 - smoothstep(0.0, 1.0, clamp((tbProg - tb) / BLUR_WIDTH, 0.0, 1.0));
float lrMask = 1 - smoothstep(0, 1, clamp((lrProgress - lr) / BLUR_WIDTH, 0, 1)); float lrMask = 1.0 - smoothstep(0.0, 1.0, clamp((lrProg - lr) / BLUR_WIDTH, 0.0, 1.0));
float ffMask = 1 - smoothstep(0, 1, ffProgress); float ffMask = 1.0 - smoothstep(0.0, 1.0, ffProg);
// Assemble the final alpha value. // Assemble the final alpha value.
float mask = tbMask * lrMask * ffMask; float mask = tbMask * lrMask * ffMask;
@@ -57,11 +57,11 @@ void main() {
oColor = texture2D(uTexture, coords); oColor = texture2D(uTexture, coords);
// Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied. // 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 /= 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; oColor.a *= mask;
// These are pretty useful for understanding how this works. // These are pretty useful for understanding how this works.