diff --git a/dependencies.json b/dependencies.json index 736aa92..4e53fb5 100644 --- a/dependencies.json +++ b/dependencies.json @@ -39,7 +39,7 @@ }, "development": [ "qmllint", - "qsb from Qt Shader Tools (only to rebuild lock/shaders/*.qsb: scripts/build-shaders)", + "qsb from Qt Shader Tools (only to rebuild lock/shaders and wallpaper/shaders *.qsb: scripts/build-shaders)", "node (configuration, dock and launcher logic tests)", "QtTest (tray, dock, launcher, settings, media and Control Center input tests only)", "Python 3 with dbus-python and PyGObject (isolated tray and MPRIS fixtures)", diff --git a/quickshell/wallpaper/WallpaperBackground.qml b/quickshell/wallpaper/WallpaperBackground.qml index f2a6010..34053ae 100644 --- a/quickshell/wallpaper/WallpaperBackground.qml +++ b/quickshell/wallpaper/WallpaperBackground.qml @@ -1,6 +1,5 @@ pragma ComponentBehavior: Bound import QtQuick -import QtQuick.Effects import Quickshell import Quickshell.Wayland import "../services" @@ -17,7 +16,7 @@ PanelWindow { WlrLayershell.namespace:"glassMxrph-wallpaper" mask:Region {} readonly property string target:ConfigService.ready && ConfigService.data.wallpaper.byMonitor[root.modelData.name] ? "file://"+encodeURI(ConfigService.data.wallpaper.byMonitor[root.modelData.name]).replace(/#/g,"%23").replace(/\?/g,"%3F") : "" - // 0..1 while a new wallpaper grows in from the centre over the old one. + // 0..1 while colonies of the new wallpaper eat through the old one. property real progress:0 readonly property bool transitioning:incoming.source.toString()!=="" // The first wallpaper (and reduced motion) appears directly; later changes @@ -41,53 +40,62 @@ PanelWindow { // Drop the overlay only once the base layer shows the new image. onStatusChanged:root.settle() } - Item { - id:revealMask - anchors.fill:parent - visible:false - layer.enabled:root.transitioning - Rectangle { - readonly property real reach:Math.hypot(root.width,root.height)*1.15 - anchors.centerIn:parent - width:reach*root.progress;height:width;radius:width/2 - color:"black" - } - } - // The mask must be the image's own layer effect: a MultiEffect pointed at a - // hidden source renders nothing here. + // The incoming image is only a texture: the colonies shader draws the + // change over `shown` (shaders/colonies.frag). Image { id:incoming - anchors.fill:parent - visible:root.transitioning && root.progress>0 - sourceSize:Qt.size(parent.width,parent.height) + visible:false + sourceSize:Qt.size(root.width,root.height) asynchronous:true fillMode:Image.PreserveAspectCrop - // Settles from a slight zoom while the circle widens, like swww/awww "grow". - scale:1.06-0.06*root.progress onStatusChanged:{ if(status===Image.Ready && source.toString())WallpaperService.revealReady(root.modelData.name); else if(status===Image.Error)incoming.source=""; } - layer.enabled:root.transitioning - layer.effect:MultiEffect { - maskEnabled:true - maskSource:revealMask - maskThresholdMin:0.5 - maskSpreadAtMin:1 - } } + // PreserveAspectCrop decodes to cover the output, so the texture can be + // larger than the item on one axis: sample its centred window. + function crop(img) { + const iw=Math.max(img.implicitWidth,1),ih=Math.max(img.implicitHeight,1); + const s=Math.max(root.width/iw,root.height/ih); + const w=root.width/(iw*s),h=root.height/(ih*s); + return Qt.vector4d((1-w)/2,(1-h)/2,w,h); + } + ShaderEffect { + anchors.fill:parent + visible:root.transitioning && incoming.status===Image.Ready && root.progress>0 + property var oldTex:shown + property var newTex:incoming + property real t:root.progress + property real sw:width + property real sh:height + property real cell:4 + property real glow:0.9 + property real seed:root.seed + property vector4d cropOld:root.crop(shown) + property vector4d cropNew:root.crop(incoming) + property color ember:root.ember + fragmentShader:Qt.resolvedUrl("shaders/colonies.frag.qsb") + } + // Captured when a change starts, so the burn keeps its colour even if the + // palette regenerates from the new wallpaper halfway through. + property real seed:0 + property color ember:Theme.accentVivid Connections { target:WallpaperService function onRevealSerialChanged() { - if(incoming.status===Image.Ready && incoming.source.toString() && !reveal.running && root.progress===0)reveal.restart(); + if(incoming.status===Image.Ready && incoming.source.toString() && !reveal.running && root.progress===0) { + root.seed=Math.random()*100;root.ember=Theme.accentVivid;reveal.restart(); + } } } NumberAnimation { id:reveal target:root;property:"progress" from:0;to:1 - duration:1100 - easing.type:Easing.InOutCubic + // Linear time: the shader eases its own fronts. + duration:1800 + easing.type:Easing.Linear onFinished:{shown.source=incoming.source;Qt.callLater(root.settle);} } } diff --git a/quickshell/wallpaper/shaders/colonies.frag b/quickshell/wallpaper/shaders/colonies.frag new file mode 100644 index 0000000..e3e9c4a --- /dev/null +++ b/quickshell/wallpaper/shaders/colonies.frag @@ -0,0 +1,120 @@ +#version 440 +// Wallpaper change: colonies of the new wallpaper land at a few places and +// moments and eat through the old one in crisp pixel cells, along organic, +// noise-warped fronts. Each cell that has just flipped burns for an instant in +// the accent colour, a thin glow rides the front, and now and then a spark +// jumps ahead of it. Everything is procedural: `seed` makes every change differ. +// Extra effects scale with sin(pi*t), so t=0 is exactly the old wallpaper and +// t=1 exactly the new one. +// Rebuild colonies.frag.qsb with scripts/build-shaders after editing. +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 t; // 0..1, linear in time + float sw; // item size, px + float sh; + float cell; // cell size, px + float glow; // 0..1, strength of the burn and the front glow + float seed; + vec4 cropOld; // texture uv = xy + item uv * zw (PreserveAspectCrop) + vec4 cropNew; + vec4 ember; +}; +layout(binding = 1) uniform sampler2D oldTex; +layout(binding = 2) uniform sampler2D newTex; + +const float PI = 3.14159265; +const int COLS = 3; // seeds are stratified on a COLS x ROWS grid, so +const int ROWS = 2; // no part of the screen is far from every colony +const float START = 0.22; // latest moment a colony may land +const float WARP = 0.22; // how far the noise bends the fronts, screen heights +const float GRAIN = 0.035; // per-cell jitter: ragged, crisp edges +const float LIFE = 0.06; // how long a flipped cell burns + +float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7)) + seed * 13.17) * 43758.5453); } +float hash1(float n) { return fract(sin(n * 91.345 + seed * 7.91) * 47453.5453); } +float escena(float x) { x = clamp(x, 0.0, 1.0); return x * x * (3.0 - 2.0 * x); } + +float vnoise(vec2 p) { + vec2 i = floor(p), f = p - i; + f = f * f * (3.0 - 2.0 * f); + return mix(mix(hash(i), hash(i + vec2(1.0, 0.0)), f.x), + mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), f.x), f.y); +} +float fbm(vec2 p) { + return 0.52 * vnoise(p) + 0.30 * vnoise(p * 2.7 + 17.0) + 0.18 * vnoise(p * 7.3 + 41.0); +} + +// Latest arrival, measured over many seeds and aspect ratios (16:9, 21:9, 1:1, +// 9:16): the worst case stays under half the latest landing plus one zone +// diagonal. Any straggler past it is closed at t=1. +float aspect() { return sw / sh; } +float maxArrival() { + vec2 zone = vec2(aspect() / float(COLS), 1.0 / float(ROWS)); + return START * 0.5 + length(zone) + 0.04; +} + +// Arrival (as a fraction of maxArrival) at which a given fraction of the +// screen is covered, from the same measurements: mapping time through it +// makes the covered AREA grow evenly instead of crawling, then rushing. +float areaToArrival(float f) { + if (f < 0.10) return mix(0.00, 0.22, f / 0.10); + if (f < 0.25) return mix(0.22, 0.29, (f - 0.10) / 0.15); + if (f < 0.50) return mix(0.29, 0.37, (f - 0.25) / 0.25); + if (f < 0.75) return mix(0.37, 0.46, (f - 0.50) / 0.25); + if (f < 0.90) return mix(0.46, 0.54, (f - 0.75) / 0.15); + return mix(0.54, 1.00, (f - 0.90) / 0.10); +} + +// When the cell at `c` (cell coordinates) flips, in the same units as maxArrival(). +float arrivalAt(vec2 c) { + vec2 q = (c + 0.5) * cell / sh; // screen-height units + vec2 w = vec2(fbm(q * 3.1 + seed), fbm(q * 3.1 + seed + 23.7)) - 0.5; + q += w * WARP; + float a = 1e6; + for (int y = 0; y < ROWS; y++) { + for (int x = 0; x < COLS; x++) { + float n = float(y * COLS + x); + vec2 zone = vec2(aspect() / float(COLS), 1.0 / float(ROWS)); + vec2 s = (vec2(float(x), float(y)) + 0.2 + 0.6 * vec2(hash1(n), hash1(n + 31.0))) * zone; + float t0 = START * hash1(n + 57.0); + float speed = 0.85 + 0.3 * hash1(n + 83.0); // some colonies are hungrier + a = min(a, t0 + length(q - s) / speed); + } + } + return a + GRAIN * hash(c + 0.37); +} + +vec3 oldAt(vec2 uv) { return texture(oldTex, cropOld.xy + uv * cropOld.zw).rgb; } +vec3 newAt(vec2 uv, float zoom) { return texture(newTex, cropNew.xy + (0.5 + (uv - 0.5) / zoom) * cropNew.zw).rgb; } + +void main() { + vec2 uv = qt_TexCoord0; + float energy = sin(PI * t); + float span = maxArrival(); + float T = areaToArrival(escena(t)) * (span + LIFE + 0.01) - 0.01; + vec2 cellPos = floor(uv * vec2(sw, sh) / cell); + float a = arrivalAt(cellPos); + float flick = hash(cellPos + 0.71); + vec3 hot = mix(ember.rgb, vec3(1.0), 0.18); + vec3 c; + if (a > T) { + c = oldAt(uv); + float ahead = a - T; // a spark just ahead of the front + if (flick > 0.985 && ahead < 0.03) + c = mix(c, hot, (1.0 - ahead / 0.03) * 0.8 * glow * step(0.0, T)); + } else { + c = newAt(uv, 1.0 + 0.025 * (1.0 - escena(t))); // settles from a touch closer + bool edge = max(max(arrivalAt(cellPos + vec2(1.0, 0.0)), arrivalAt(cellPos - vec2(1.0, 0.0))), + max(arrivalAt(cellPos + vec2(0.0, 1.0)), arrivalAt(cellPos - vec2(0.0, 1.0)))) > T; + float life = clamp((T - a) / LIFE, 0.0, 1.0); + float burn = (1.0 - life) * (1.0 - life) * (edge ? 1.0 : 0.55); + c = mix(c, hot, burn * (0.55 + 0.45 * flick) * 0.85 * glow); + } + c += ember.rgb * 0.22 * glow * energy * exp(-abs(a - T) / 0.012); + if (t >= 1.0) c = newAt(uv, 1.0); + fragColor = vec4(clamp(c, 0.0, 1.0), 1.0) * qt_Opacity; +} diff --git a/quickshell/wallpaper/shaders/colonies.frag.qsb b/quickshell/wallpaper/shaders/colonies.frag.qsb new file mode 100644 index 0000000..d3440dc Binary files /dev/null and b/quickshell/wallpaper/shaders/colonies.frag.qsb differ diff --git a/scripts/build-shaders b/scripts/build-shaders index 83a901e..9cf3eb4 100755 --- a/scripts/build-shaders +++ b/scripts/build-shaders @@ -4,6 +4,6 @@ # nix shell nixpkgs#qt6.qtshadertools -c ./scripts/build-shaders set -eu project_dir=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) -for source in "$project_dir"/quickshell/lock/shaders/*.frag; do +for source in "$project_dir"/quickshell/lock/shaders/*.frag "$project_dir"/quickshell/wallpaper/shaders/*.frag; do qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -o "$source.qsb" "$source" done