Draw a wallpaper's subject outline first when changing to it

helpers/wallfx.py finds the subject with BiRefNet (onnxruntime, CPU),
bakes outline maps per wallpaper and caches them; scans warm the cache in
the background. The transition shader gains an outline mode: the line is
drawn, the subject fills in, then the rest grows out of it. Uncached or
subject-less wallpapers keep the colonies. wallpaper.outlineExclude opts
wallpapers out. The Nix package provides the interpreter and the model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mxandClaude Opus 5.5 committed 2026-11-08 22:37:33 +01:00
1 parent ad740ef631
commit b6d0da4679
10 files changed
+491 -28

No files matched your search

+62 -11
View File
@@ -15,8 +15,9 @@ PanelWindow {
WlrLayershell.layer:WlrLayer.Background
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 colonies of the new wallpaper eat through the old one.
readonly property string targetPath:ConfigService.ready ? (ConfigService.data.wallpaper.byMonitor[root.modelData.name] || "") : ""
readonly property string target:targetPath ? "file://"+encodeURI(targetPath).replace(/#/g,"%23").replace(/\?/g,"%3F") : ""
// 0..1 while the new wallpaper takes over (shaders/transition.frag).
property real progress:0
readonly property bool transitioning:incoming.source.toString()!==""
// The first wallpaper (and reduced motion) appears directly; later changes
@@ -24,7 +25,12 @@ PanelWindow {
onTargetChanged:{
if(!shown.source.toString() || Theme.duration===0) {reveal.stop();incoming.source="";shown.source=target;}
else if(target===shown.source.toString()) {reveal.stop();incoming.source="";}
else {reveal.stop();progress=0;WallpaperService.revealLoading(modelData.name);incoming.source=target;}
else {
reveal.stop();progress=0;reported=false;
WallpaperService.revealLoading(modelData.name);
WallpaperService.prepareTransition(targetPath,true);
incomingPath=targetPath;incoming.source=target;
}
}
Component.onCompleted:shown.source=target
function settle() {
@@ -40,8 +46,8 @@ PanelWindow {
// Drop the overlay only once the base layer shows the new image.
onStatusChanged:root.settle()
}
// The incoming image is only a texture: the colonies shader draws the
// change over `shown` (shaders/colonies.frag).
// The incoming image and the outline maps are only textures: the shader
// draws the change over `shown`.
Image {
id:incoming
visible:false
@@ -49,10 +55,43 @@ PanelWindow {
asynchronous:true
fillMode:Image.PreserveAspectCrop
onStatusChanged:{
if(status===Image.Ready && source.toString())WallpaperService.revealReady(root.modelData.name);
else if(status===Image.Error)incoming.source="";
if(status===Image.Error)incoming.source="";
else root.reportIfReady();
}
}
// The outline plan for the incoming wallpaper (WallpaperService), once known.
property string incomingPath:""
readonly property var plan:root.transitioning ? WallpaperService.transitions[root.incomingPath] : undefined
readonly property bool wantsOutline:!!root.plan && root.plan.kind==="outline"
readonly property bool outlineReady:root.wantsOutline && fieldMap.status===Image.Ready && lineMap.status===Image.Ready
// Settled: colonies, outline maps loaded, or maps that failed (colonies then).
readonly property bool planSettled:root.plan!==undefined && (!root.wantsOutline || root.outlineReady
|| fieldMap.status===Image.Error || lineMap.status===Image.Error)
onPlanSettledChanged:reportIfReady()
property bool reported:false
// Ready once the image is decoded and the plan settled. The service's
// fallback starts the change anyway if this takes too long; it then uses
// colonies unless the maps happen to be in.
function reportIfReady() {
if(reported || incoming.status!==Image.Ready || !incoming.source.toString() || !planSettled)return;
reported=true;
WallpaperService.revealReady(root.modelData.name);
}
// Maps hold numbers, not colours, at their own size; the shader interpolates.
Image {
id:fieldMap
visible:false
asynchronous:true
cache:false
source:root.wantsOutline ? "file://"+root.plan.field : ""
}
Image {
id:lineMap
visible:false
asynchronous:true
cache:false
source:root.wantsOutline ? "file://"+root.plan.line : ""
}
// 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) {
@@ -75,17 +114,30 @@ PanelWindow {
property vector4d cropOld:root.crop(shown)
property vector4d cropNew:root.crop(incoming)
property color ember:root.ember
fragmentShader:Qt.resolvedUrl("shaders/colonies.frag.qsb")
property color ink:Theme.text
property real mode:root.mode
// Unused in colonies mode, but every sampler needs a texture.
property var fieldTex:root.outlineReady ? fieldMap : incoming
property var lineTex:root.outlineReady ? lineMap : incoming
property real fw:Math.max(fieldMap.implicitWidth,1)
property real fh:Math.max(fieldMap.implicitHeight,1)
property real lineW:1.5
property real sdRange:16
fragmentShader:Qt.resolvedUrl("shaders/transition.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
property real mode:0
Connections {
target:WallpaperService
function onRevealSerialChanged() {
if(incoming.status===Image.Ready && incoming.source.toString() && !reveal.running && root.progress===0) {
root.seed=Math.random()*100;root.ember=Theme.accentVivid;reveal.restart();
root.seed=Math.random()*100;root.ember=Theme.accentVivid;
root.mode=root.outlineReady ? 1 : 0;
reveal.duration=root.mode ? 2000 : 1800;
reveal.restart();
}
}
}
@@ -93,8 +145,7 @@ PanelWindow {
id:reveal
target:root;property:"progress"
from:0;to:1
// Linear time: the shader eases its own fronts.
duration:1800
// Linear time: the shader eases its own phases. Set per change.
easing.type:Easing.Linear
onFinished:{shown.source=incoming.source;Qt.callLater(root.settle);}
}
Binary file not shown.
@@ -1,12 +1,20 @@
#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
// Wallpaper change, two kinds, both in crisp pixel cells:
//
// COLONIES (mode 0), any wallpaper: colonies of the new wallpaper land at a
// few places and moments and eat through the old one along noise-warped
// fronts. Each flipped cell burns for an instant in the accent colour, a thin
// glow rides the front, and now and then a spark jumps ahead. Procedural:
// `seed` makes every change differ.
//
// OUTLINE (mode 1), a wallpaper with a clear subject: the old wallpaper steps
// back, a thin line draws the subject's outline (two pens from its top), the
// subject fills in from that outline, and the rest of the picture grows out
// of it. The maps come from helpers/wallfx.py, in the new image's space.
//
// Extra effects vanish at both ends, 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.
// Rebuild transition.frag.qsb with scripts/build-shaders after editing.
layout(location = 0) in vec2 qt_TexCoord0;
layout(location = 0) out vec4 fragColor;
@@ -14,17 +22,25 @@ layout(std140, binding = 0) uniform buf {
mat4 qt_Matrix;
float qt_Opacity;
float t; // 0..1, linear in time
float mode; // 0 colonies, 1 outline
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;
float fw; // fieldTex / lineTex size, texels (outline only)
float fh;
float lineW; // outline width, px
float sdRange; // fieldTex G spans +-sdRange map px
vec4 cropOld; // texture uv = xy + item uv * zw (PreserveAspectCrop)
vec4 cropNew;
vec4 ember;
vec4 ember; // accent: the colonies' burning edge
vec4 ink; // light tone: the outline's line
};
layout(binding = 1) uniform sampler2D oldTex;
layout(binding = 2) uniform sampler2D newTex;
layout(binding = 3) uniform sampler2D fieldTex;
layout(binding = 4) uniform sampler2D lineTex;
const float PI = 3.14159265;
const int COLS = 3; // seeds are stratified on a COLS x ROWS grid, so
@@ -89,10 +105,11 @@ float arrivalAt(vec2 c) {
}
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; }
vec2 newUv(vec2 uv, float zoom) { return cropNew.xy + (0.5 + (uv - 0.5) / zoom) * cropNew.zw; }
vec3 newAt(vec2 uv, float zoom) { return texture(newTex, newUv(uv, zoom)).rgb; }
float luma(vec3 c) { return dot(c, vec3(0.299, 0.587, 0.114)); }
void main() {
vec2 uv = qt_TexCoord0;
vec3 colonies(vec2 uv) {
float energy = sin(PI * t);
float span = maxArrival();
float T = areaToArrival(escena(t)) * (span + LIFE + 0.01) - 0.01;
@@ -114,7 +131,61 @@ void main() {
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);
return c + ember.rgb * 0.22 * glow * energy * exp(-abs(a - T) / 0.012);
}
// 16-bit order in lineTex G (high) and B (low), interpolated by hand: the
// sampler's bilinear filter would blend the two bytes separately.
float order16(vec2 texel) {
texel = clamp(texel, vec2(0.0), vec2(fw, fh) - 1.0);
vec4 f = texture(lineTex, (texel + 0.5) / vec2(fw, fh));
return (floor(f.g * 255.0 + 0.5) * 256.0 + floor(f.b * 255.0 + 0.5)) / 65535.0;
}
float orderAt(vec2 tuv) {
vec2 p = tuv * vec2(fw, fh) - 0.5;
vec2 i = floor(p), f = p - i;
return mix(mix(order16(i), order16(i + vec2(1.0, 0.0)), f.x),
mix(order16(i + vec2(0.0, 1.0)), order16(i + vec2(1.0, 1.0)), f.x), f.y);
}
vec3 outline(vec2 uv) {
// The subject settles from a touch closer than its background: a little depth.
float zIn = 1.0 + 0.03 * (1.0 - escena(t));
float zOut = 1.0 + 0.015 * (1.0 - escena(t));
vec4 f = texture(fieldTex, newUv(uv, zIn));
float sdPx = (f.g * 2.0 - 1.0) * sdRange * sw * zIn / (fw * cropNew.z); // screen px, > 0 outside
float aa = max(fwidth(sdPx), 1e-3);
float inside = clamp(0.5 - sdPx / aa, 0.0, 1.0);
// The old wallpaper steps back: a fifth darker, a quarter greyer.
float back = escena(t / 0.18) * (1.0 - escena((t - 0.85) / 0.15));
vec3 st = oldAt(uv);
st = mix(st, vec3(luma(st)), 0.25 * back) * (1.0 - 0.2 * back);
// Fronts decide per cell centre, so they are crisp and stepped; the
// silhouette itself stays smooth.
vec2 grid = vec2(sw, sh) / cell;
vec2 cuv = (floor(uv * grid) + 0.5) / grid;
float Ti = escena((t - 0.32) / 0.32) * 1.02 - 0.01; // fill, once the line is nearly drawn
vec3 cIn = texture(fieldTex, newUv(cuv, zIn)).r <= Ti ? newAt(uv, zIn) : st;
float To = escena((t - 0.45) / 0.50) * 1.02 - 0.01; // then the world grows out of it
vec3 cOut = orderAt(newUv(cuv, zOut)) <= To ? newAt(uv, zOut) : st;
vec3 c = mix(cOut, cIn, inside);
// The line: thin and quiet, drawn by two pens from the top of every
// contour, gone once the subject is in.
float drawn = escena((t - 0.02) / 0.33);
float lp = texture(lineTex, newUv(uv, zIn)).r;
float fade = 1.0 - escena((t - 0.45) / 0.25);
if (lp > 0.0 && lp <= drawn && fade > 0.0) {
float core = clamp(0.5 - (abs(sdPx) - lineW * 0.5) / aa, 0.0, 1.0);
c = mix(c, ink.rgb, core * 0.75 * fade);
}
return c;
}
void main() {
vec2 uv = qt_TexCoord0;
vec3 c = t >= 1.0 ? newAt(uv, 1.0) : (mode < 0.5 ? colonies(uv) : outline(uv));
fragColor = vec4(clamp(c, 0.0, 1.0), 1.0) * qt_Opacity;
}
Binary file not shown.