aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/appearance/shatter.frag
diff options
context:
space:
mode:
Diffstat (limited to 'desktop/modules/appearance/shatter.frag')
-rw-r--r--desktop/modules/appearance/shatter.frag66
1 files changed, 66 insertions, 0 deletions
diff --git a/desktop/modules/appearance/shatter.frag b/desktop/modules/appearance/shatter.frag
new file mode 100644
index 0000000..4c9e40d
--- /dev/null
+++ b/desktop/modules/appearance/shatter.frag
@@ -0,0 +1,66 @@
+// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// The old wallpaper breaking into Voronoi shards that shrink, slide away from
+// where the blow landed and fade, each on its own delay. A shard only moves
+// inside the room its shrinking leaves, so a pixel needs one cell lookup to
+// find it, rather than a search of the neighbours. Compiled with:
+// qsb --qt6 -o shatter.frag.qsb shatter.frag
+#version 440
+layout(location = 0) in vec2 qt_TexCoord0;
+layout(location = 0) out vec4 fragColor;
+layout(std140, binding = 0) uniform buf {
+ mat4 qt_Matrix;
+ float qt_Opacity;
+ float progress;
+ float aspect;
+ vec2 origin;
+};
+layout(binding = 1) uniform sampler2D source;
+
+vec2 hash2(vec2 p) {
+ return fract(sin(vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)))) * 43758.5453);
+}
+
+// The nearest seed to p: its cell in xy, its position in zw.
+vec4 cell(vec2 p) {
+ vec2 i = floor(p), f = fract(p);
+ float best = 9.0;
+ vec4 r = vec4(0.0);
+ for (int y = -1; y <= 1; y++) {
+ for (int x = -1; x <= 1; x++) {
+ vec2 g = vec2(float(x), float(y));
+ vec2 s = g + hash2(i + g);
+ float d = dot(s - f, s - f);
+ if (d < best) { best = d; r = vec4(i + g, i + s); }
+ }
+ }
+ return r;
+}
+
+void main() {
+ const float n = 6.0;
+ vec2 asp = vec2(aspect, 1.0);
+ vec2 p = qt_TexCoord0 * asp * n;
+ vec4 c = cell(p);
+ vec2 seed = c.zw;
+
+ vec2 away = seed / n - origin * asp;
+ float d = clamp(length(away) / length(max(origin, 1.0 - origin) * asp), 0.0, 1.0);
+ float l = clamp((progress - 0.6 * mix(d, hash2(c.xy).x, 0.3)) / 0.4, 0.0, 1.0);
+
+ float s = 1.0 - 0.85 * l;
+ vec2 q = seed + (p - seed - normalize(away + 1e-4) * (1.0 - s) * 0.4) / s;
+ if (cell(q).xy != c.xy) { fragColor = vec4(0.0); return; }
+
+ float a = 1.0 - smoothstep(0.4, 1.0, l);
+ fragColor = vec4(texture(source, q / (asp * n)).rgb * a, a) * qt_Opacity;
+}