Android login: animated shader background and sea-glass method cards

8cd9941 · gmorell · 2026-12-03 20:36

43 files +2272 -22
Message
{commit_body(@commit)}

Files changed

modified android/app/build.gradle.kts
+2 −0
@@ -107,6 +107,8 @@ dependencies {
107 107 implementation(libs.compose.ui)
108 108 implementation(libs.compose.ui.tooling.preview)
109 109 implementation(libs.compose.material3)
110 + // The login cards' backdrop blur.
111 + implementation(libs.haze)
110 112 implementation(libs.compose.material.icons)
111 113 debugImplementation(libs.compose.ui.tooling)
112 114
added android/app/src/main/assets/bubbles.frag
+144 −0
@@ -0,0 +1,144 @@
1 +// Bubbles: soap bubbles drifting and bouncing (moved on the CPU, in
2 +// balls.js, Balls.kt and the site's shader_balls.js).
3 +// Each is nearly clear, its film banded light and dark in one colour and
4 +// swirling, brighter towards the rim, with a window's highlight.
5 +#version 440
6 +
7 +layout(location = 0) in vec2 qt_TexCoord0;
8 +layout(location = 0) out vec4 fragColor;
9 +
10 +layout(std140, binding = 0) uniform buf {
11 + mat4 qt_Matrix;
12 + float qt_Opacity;
13 +
14 + vec2 size; // pixels
15 + // ball0-ball47: x, y, radius (shorter side units), film phase 0-1
16 + vec4 ball0;
17 + vec4 ball1;
18 + vec4 ball2;
19 + vec4 ball3;
20 + vec4 ball4;
21 + vec4 ball5;
22 + vec4 ball6;
23 + vec4 ball7;
24 + vec4 ball8;
25 + vec4 ball9;
26 + vec4 ball10;
27 + vec4 ball11;
28 + vec4 ball12;
29 + vec4 ball13;
30 + vec4 ball14;
31 + vec4 ball15;
32 + vec4 ball16;
33 + vec4 ball17;
34 + vec4 ball18;
35 + vec4 ball19;
36 + vec4 ball20;
37 + vec4 ball21;
38 + vec4 ball22;
39 + vec4 ball23;
40 + vec4 ball24;
41 + vec4 ball25;
42 + vec4 ball26;
43 + vec4 ball27;
44 + vec4 ball28;
45 + vec4 ball29;
46 + vec4 ball30;
47 + vec4 ball31;
48 + vec4 ball32;
49 + vec4 ball33;
50 + vec4 ball34;
51 + vec4 ball35;
52 + vec4 ball36;
53 + vec4 ball37;
54 + vec4 ball38;
55 + vec4 ball39;
56 + vec4 ball40;
57 + vec4 ball41;
58 + vec4 ball42;
59 + vec4 ball43;
60 + vec4 ball44;
61 + vec4 ball45;
62 + vec4 ball46;
63 + vec4 ball47;
64 + float count; // how many of balls are in use
65 + float breath; // multiplies the light, near 1
66 + float grain; // 0-1, film grain
67 + float dither; // 0-1, dither
68 + float seed; // 0-1, changes each frame to move the grain
69 +
70 + vec4 base; // the ground
71 + vec4 deep; // the ground at the edges
72 + vec4 ink;
73 + vec4 tone;
74 +};
75 +
76 +const float TAU = 6.2831853;
77 +
78 +float hash12(vec2 p)
79 +{
80 + vec3 p3 = fract(vec3(p.xyx) * 0.1031);
81 + p3 += dot(p3, p3.yzx + 33.33);
82 + return fract((p3.x + p3.y) * p3.z);
83 +}
84 +
85 +void main()
86 +{
87 + float px = 1.0 / min(size.x, size.y);
88 + vec2 extent = size * px;
89 + vec2 p = qt_TexCoord0 * extent;
90 +
91 + // The discs, gathered into an array the loop can index. They arrive
92 + // as separate uniforms because Qt's ShaderEffect has no array
93 + // properties: x, y, radius (shorter side units), and a fourth value.
94 + vec4 balls[48] = vec4[48](
95 + ball0, ball1, ball2, ball3, ball4, ball5, ball6, ball7,
96 + ball8, ball9, ball10, ball11, ball12, ball13, ball14, ball15,
97 + ball16, ball17, ball18, ball19, ball20, ball21, ball22, ball23,
98 + ball24, ball25, ball26, ball27, ball28, ball29, ball30, ball31,
99 + ball32, ball33, ball34, ball35, ball36, ball37, ball38, ball39,
100 + ball40, ball41, ball42, ball43, ball44, ball45, ball46, ball47);
101 +
102 + float v = smoothstep(0.35, 1.25, length(p - 0.5 * extent));
103 + vec3 colour = mix(base.rgb, deep.rgb, v);
104 +
105 + vec3 light = vec3(0.0);
106 + for (int i = 0; i < 48; i++) {
107 + if (float(i) >= count)
108 + break;
109 + vec4 b = balls[i];
110 + vec2 q = (p - b.xy) / b.z;
111 + float d = length(q);
112 + if (d > 1.2)
113 + continue;
114 + float inside = clamp((1.0 - d) * b.z / px + 0.5, 0.0, 1.0);
115 +
116 + // The film: thickness varying down the bubble (it drains) and
117 + // swirling around it.
118 + float ang = atan(q.y, q.x);
119 + float th = b.w + 0.45 * q.y + 0.15 * d * sin(2.0 * ang + TAU * b.w) + 0.3 * d * d;
120 + vec3 iris = ink.rgb * (0.55 + 0.45 * cos(TAU * 1.6 * th));
121 + float fresnel = d * d * d * d;
122 + light += iris * (0.05 + 0.5 * fresnel) * inside;
123 +
124 + // A thin bright rim, and a little glow outside it.
125 + float rim = exp(-abs(d - 1.0) * b.z / (1.2 * px + 0.0025));
126 + light += mix(iris, vec3(1.0), 0.4) * rim * 0.35;
127 +
128 + // A window's highlight up and to the left, a fainter one opposite.
129 + vec2 h = q - vec2(-0.38, -0.42);
130 + float hl = exp(-dot(h, h) / 0.018);
131 + vec2 h2 = q - vec2(0.42, 0.45);
132 + float hl2 = exp(-dot(h2, h2) / 0.01);
133 + light += vec3(1.0) * (0.55 * hl + 0.18 * hl2) * inside;
134 + }
135 + colour += (vec3(1.0) - exp(-light)) * breath;
136 +
137 + vec2 pixel = qt_TexCoord0 * size;
138 + if (grain > 0.0)
139 + colour += (hash12(pixel + seed * 1000.0) - 0.5) * 0.06 * grain;
140 + if (dither > 0.0)
141 + colour += (hash12(pixel + 0.5) + hash12(pixel + 91.3) - 1.0) / 255.0 * dither;
142 +
143 + fragColor = vec4(colour, 1.0) * qt_Opacity;
144 +}
added android/app/src/main/assets/field.frag
+279 −0
@@ -0,0 +1,279 @@
1 +// The moire wallpaper's whole picture, back to front: ground, stars,
2 +// bokeh, halftone dots, moire rings (the patterns fading out into the
3 +// ground away from a drifting hub), foreground discs, then grain and
4 +// dither over the finished pixel.
5 +//
6 +// Everything that moves is computed in Field.qml, in double precision,
7 +// and arrives here as positions and phases; the shader holds no clock,
8 +// so it never loses precision however long the session runs.
9 +//
10 +// Compiled into ../theme/contents/ui/field.frag.qsb by tools/shaders.sh.
11 +#version 440
12 +
13 +layout(location = 0) in vec2 qt_TexCoord0;
14 +layout(location = 0) out vec4 fragColor;
15 +
16 +layout(std140, binding = 0) uniform buf {
17 + mat4 qt_Matrix;
18 + float qt_Opacity;
19 +
20 + vec2 size; // pixels
21 + // Positions and lengths below are in units of the shorter side, so
22 + // every aspect ratio, landscape or portrait, shows the same pattern
23 + // at the same apparent scale. The screen spans 0 to size / shorter.
24 + vec2 ringA; // centres of the two ring families
25 + vec2 ringB;
26 + vec2 hub; // where the pattern is strongest
27 + float reach; // distance at which it has faded out entirely
28 + float period; // ring spacing
29 + float moire; // 0-1, how much of the rings to show
30 + float halftone; // 0-1, how much of the dots to show
31 + float cell; // halftone grid spacing
32 + float angle; // halftone grid rotation, radians
33 + float wave; // halftone wave phase, radians, kept in [0, 2pi)
34 + float bokeh; // 0-1, how much of the bokeh to show
35 + float lights; // how many bokeh discs, up to MAX_DISCS
36 + float flare; // 0-1, how much of the large foreground discs to show
37 + float drift; // bokeh phase, 0-1 over its whole cycle
38 + float stars; // 0-1, how much of the starfield to show
39 + float twinkle; // star phase, 0-1 over its whole cycle
40 + float glints; // 0-1, how much light the glint catches
41 + float glintPhase; // 0-1 over one glint cycle; the sweep is its first 30%
42 + float breath; // multiplies the patterns' strength, near 1
43 + float grain; // 0-1, film grain
44 + float dither; // 0-1, dither
45 + float seed; // 0-1, changes each frame to move the grain
46 +
47 + vec4 base; // the ground
48 + vec4 deep; // the ground at the edges
49 + vec4 ink; // the moire
50 + vec4 tone; // the halftone
51 +};
52 +
53 +float fade(vec2 p)
54 +{
55 + float t = clamp(1.0 - length(p - hub) / reach, 0.0, 1.0);
56 + return t * t * (3.0 - 2.0 * t);
57 +}
58 +
59 +float rings(vec2 p, vec2 centre, float px)
60 +{
61 + float r = length(p - centre);
62 + float d = abs(fract(r / period + 0.5) - 0.5) * period;
63 + float halfWidth = max(0.9 * px, period * 0.09);
64 + return clamp(1.0 - (d - halfWidth) / px, 0.0, 1.0);
65 +}
66 +
67 +// A repeatable pseudo-random number in [0, 1) per disc and purpose.
68 +float hash(float n)
69 +{
70 + return fract(sin(n * 127.1 + 311.7) * 43758.5453);
71 +}
72 +
73 +// Per-pixel noise without sin() or integers: GLSL ES 100, one of the
74 +// targets, has no unsigned integers, and sin() of a large pixel
75 +// coordinate loses precision on some GPUs. (Dave Hoskins' hash12.)
76 +float hash12(vec2 p)
77 +{
78 + vec3 p3 = fract(vec3(p.xyx) * 0.1031);
79 + p3 += dot(p3, p3.yzx + 33.33);
80 + return fract((p3.x + p3.y) * p3.z);
81 +}
82 +
83 +// Stars on a jittered grid, most faint and a few bright, each
84 +// twinkling at a whole multiple of the twinkle phase so the wrap is
85 +// seamless. A star sits well inside its cell, so only one cell needs
86 +// checking per pixel. The brightest carry a soft halo.
87 +float starLayer(vec2 p, float px, float spacing, float salt)
88 +{
89 + vec2 id = floor(p / spacing) + salt;
90 + if (hash12(id) > 0.45)
91 + return 0.0; // 45% of cells hold a star
92 + vec2 at = (floor(p / spacing) + 0.15 + 0.7 * vec2(hash12(id + 17.0), hash12(id + 31.0))) * spacing;
93 + float bright = hash12(id + 47.0);
94 + bright *= bright;
95 + float rate = 1.0 + floor(hash12(id + 59.0) * 4.0);
96 + float shimmer = 0.55 + 0.45 * sin(6.2831853 * (rate * twinkle + hash12(id + 71.0)));
97 + float r = px * (0.8 + 1.4 * bright);
98 + float d = length(p - at);
99 + float core = exp(-d * d / (r * r)) * (0.25 + 0.75 * bright);
100 + float halo = exp(-d / (7.0 * px)) * 0.18 * bright * bright * bright;
101 + return (core + halo) * shimmer;
102 +}
103 +
104 +// Two layers: the stars proper, and a denser scatter of fainter,
105 +// smaller ones behind them that gives the field depth.
106 +float starLight(vec2 p, float px)
107 +{
108 + return starLayer(p, px, 0.035, 0.0) + 0.4 * starLayer(p, px, 0.016, 113.0);
109 +}
110 +
111 +// A band of light sweeping diagonally across the screen during the
112 +// first 30% of each glint cycle. It lights only the rings and dots, as
113 +// light catches fine grooves, and is zero between sweeps.
114 +float glintBand(vec2 p, vec2 extent)
115 +{
116 + if (glintPhase >= 0.3)
117 + return 0.0;
118 + float s = glintPhase / 0.3;
119 + vec2 dir = vec2(0.8, -0.6);
120 + float c0 = 0.0, c1 = extent.x * dir.x, c2 = extent.y * dir.y, c3 = c1 + c2;
121 + float lo = min(min(c0, c1), min(c2, c3));
122 + float hi = max(max(c0, c1), max(c2, c3));
123 + const float width = 0.08;
124 + float x = (dot(p, dir) - mix(lo - 3.0 * width, hi + 3.0 * width, s)) / width;
125 + return exp(-x * x) * sin(3.1415927 * s);
126 +}
127 +
128 +// Out-of-focus lights drifting upward. Each disc moves at a whole
129 +// multiple of drift, so when drift wraps from 1 back to 0 every disc
130 +// is exactly where it started; each fades in rising from the bottom
131 +// and out before the top, so none ever appears or vanishes abruptly.
132 +//
133 +// Every disc has its own colour: somewhere from the primary to the
134 +// accent, weighted towards the accent, and somewhere from muted to
135 +// vivid. Returns the discs' blended colour and their combined coverage.
136 +const int MAX_DISCS = 64;
137 +
138 +vec4 bokehLight(vec2 p, vec2 extent, float px)
139 +{
140 + // More discs means smaller ones, so a crowd stays a scatter of
141 + // lights rather than a haze.
142 + float scale = clamp(pow(14.0 / max(lights, 1.0), 0.3), 0.6, 1.2);
143 +
144 + vec3 sum = vec3(0.0);
145 + float total = 0.0;
146 + for (int i = 0; i < MAX_DISCS; i++) {
147 + if (float(i) >= lights)
148 + break;
149 + float n = float(i);
150 + float climb = 1.0 + floor(hash(n + 1.0) * 3.0); // 1-3 laps a cycle
151 + float sway = 1.0 + floor(hash(n + 2.0) * 2.0);
152 + float life = fract(hash(n + 3.0) + climb * drift); // 0 at bottom, 1 at top
153 + vec2 c = vec2(hash(n + 4.0) * extent.x
154 + + 0.04 * sin(6.2831853 * (sway * drift + hash(n + 5.0))),
155 + extent.y + 0.15 - (extent.y + 0.3) * life);
156 + float radius = (0.035 + 0.075 * hash(n + 6.0)) * scale;
157 + float d = length(p - c);
158 + float disc = clamp((radius - d) / (2.5 * px) + 0.5, 0.0, 1.0);
159 + // A lens renders a defocused point with a slightly brighter rim.
160 + float rim = smoothstep(radius * 0.7, radius, d) * disc;
161 + float shape = disc * 0.65 + rim * 0.35;
162 + float strength = shape * sin(3.1415927 * life) * (0.45 + 0.55 * hash(n + 7.0));
163 +
164 + vec3 colour = mix(tone.rgb, ink.rgb, sqrt(hash(n + 8.0)));
165 + float grey = dot(colour, vec3(0.2126, 0.7152, 0.0722));
166 + colour = clamp(mix(vec3(grey), colour, 0.3 + 0.9 * hash(n + 9.0)), 0.0, 1.0);
167 +
168 + sum += colour * strength;
169 + total += strength;
170 + }
171 + return vec4(total > 0.0 ? sum / total : vec3(0.0), min(total, 1.0));
172 +}
173 +
174 +// A few large, very defocused discs in front of everything, like a
175 +// light passing close to the lens. Each is visible for about a third
176 +// of its cycle, fading in and out as it slides across, and absent the
177 +// rest of the time, so they come by every so often rather than always.
178 +// As with the bokeh, whole-number laps keep the drift wrap seamless.
179 +const int FLARES = 3;
180 +
181 +vec4 foregroundLight(vec2 p, vec2 extent)
182 +{
183 + vec3 sum = vec3(0.0);
184 + float total = 0.0;
185 + for (int i = 0; i < FLARES; i++) {
186 + float n = float(i) + 40.0;
187 + float laps = 1.0 + floor(hash(n) * 2.0); // 1-2 visits a cycle
188 + float life = fract(hash(n + 1.0) + laps * drift);
189 + float window = life / 0.35; // visible for the first 35%
190 + if (window >= 1.0)
191 + continue;
192 + float envelope = sin(3.1415927 * window);
193 + envelope *= envelope; // ease in and out
194 + float fromRight = step(0.5, hash(n + 2.0));
195 + float x = mix(-0.2, extent.x + 0.2, hash(n + 3.0))
196 + + mix(0.35, -0.35, fromRight) * window;
197 + vec2 c = vec2(x, mix(0.15, 0.85, hash(n + 4.0)) * extent.y - 0.12 * window);
198 + float radius = 0.22 + 0.2 * hash(n + 5.0);
199 + float d = length(p - c);
200 + // Far out of focus: a wide soft edge and only a hint of a rim.
201 + float disc = 1.0 - smoothstep(radius * 0.72, radius, d);
202 + float rim = smoothstep(radius * 0.6, radius * 0.88, d) * disc;
203 + float strength = (disc * 0.8 + rim * 0.2) * envelope;
204 +
205 + sum += mix(tone.rgb, ink.rgb, 0.6 + 0.4 * hash(n + 6.0)) * strength;
206 + total += strength;
207 + }
208 + return vec4(total > 0.0 ? sum / total : vec3(0.0), min(total, 1.0));
209 +}
210 +
211 +void main()
212 +{
213 + float px = 1.0 / min(size.x, size.y);
214 + vec2 extent = size * px;
215 + vec2 p = qt_TexCoord0 * extent;
216 + vec2 centre = 0.5 * extent;
217 +
218 + // Ground: base, darkening towards deep at the corners.
219 + float v = smoothstep(0.35, 1.25, length(p - centre));
220 + vec3 colour = mix(base.rgb, deep.rgb, v);
221 +
222 + if (stars > 0.0)
223 + colour = mix(colour, ink.rgb, starLight(p, px) * 0.85 * stars);
224 +
225 + float glint = glints > 0.0 ? glintBand(p, extent) * glints : 0.0;
226 +
227 + if (bokeh > 0.0) {
228 + vec4 light = bokehLight(p, extent, px);
229 + colour = mix(colour, light.rgb, light.a * 0.3 * bokeh);
230 + }
231 +
232 + // Halftone: dots on a rotated grid, each sized by the fade and a
233 + // travelling wave sampled at its cell's centre, so a dot is round
234 + // and uniform rather than cut by the field. Area, not radius, is
235 + // proportional to the field, as in print.
236 + if (halftone > 0.0) {
237 + mat2 rot = mat2(cos(angle), sin(angle), -sin(angle), cos(angle));
238 + vec2 q = rot * p;
239 + vec2 index = floor(q / cell);
240 + vec2 local = (q / cell - index - 0.5) * cell;
241 + vec2 cellCentre = transpose(rot) * ((index + 0.5) * cell);
242 + float field = fade(cellCentre)
243 + * (0.55 + 0.45 * sin(dot(cellCentre, vec2(0.8, 0.6)) * 9.0 - wave));
244 + float radius = 0.5 * cell * sqrt(field);
245 + float dotCover = clamp((radius - length(local)) / px + 0.5, 0.0, 1.0);
246 + colour = mix(colour, tone.rgb, dotCover * halftone * breath * 0.55);
247 + colour = mix(colour, ink.rgb, dotCover * halftone * glint * 0.5);
248 + }
249 +
250 + // Moire: two ring families slightly apart. Where their rings
251 + // interleave the light doubles up, where they coincide it thins
252 + // out, and that beat is the moire.
253 + if (moire > 0.0) {
254 + float a = rings(p, ringA, px);
255 + float b = rings(p, ringB, px);
256 + float light = 1.0 - (1.0 - 0.85 * a) * (1.0 - 0.85 * b);
257 + float f = fade(p);
258 + colour = mix(colour, ink.rgb, light * 0.6 * f * moire * breath);
259 + // The glint reaches a little past the fade, catching rings the
260 + // eye had lost.
261 + colour = mix(colour, mix(ink.rgb, vec3(1.0), 0.3), light * glint * moire * (0.4 + 0.6 * f) * 0.55);
262 + }
263 +
264 + // In front of everything, so drawn last.
265 + if (flare > 0.0) {
266 + vec4 light = foregroundLight(p, extent);
267 + colour = mix(colour, light.rgb, light.a * 0.11 * flare);
268 + }
269 +
270 + vec2 pixel = qt_TexCoord0 * size;
271 + if (grain > 0.0)
272 + colour += (hash12(pixel + seed * 1000.0) - 0.5) * 0.06 * grain;
273 + // Triangular noise of about one 8-bit step: invisible as noise, but
274 + // it breaks the slow gradients' banding into something smooth.
275 + if (dither > 0.0)
276 + colour += (hash12(pixel + 0.5) + hash12(pixel + 91.3) - 1.0) / 255.0 * dither;
277 +
278 + fragColor = vec4(colour, 1.0) * qt_Opacity;
279 +}
added android/app/src/main/assets/oil.frag
+110 −0
@@ -0,0 +1,110 @@
1 +// Oil on glass: slicks of thin film on dark glass, banded light and dark
2 +// as an oil film's interference is, in one colour, swirling slowly. The swirl is
3 +// domain-warped noise sampled at two points in its drift, crossfaded so
4 +// each is invisible as it jumps back: the shader holds no clock, only a
5 +// wrapped phase, as field.frag.
6 +#version 440
7 +
8 +layout(location = 0) in vec2 qt_TexCoord0;
9 +layout(location = 0) out vec4 fragColor;
10 +
11 +layout(std140, binding = 0) uniform buf {
12 + mat4 qt_Matrix;
13 + float qt_Opacity;
14 +
15 + vec2 size; // pixels
16 + float oilCycle; // 0-1 over one drift
17 + float coverage; // 0-1, how much of the glass the slicks cover
18 + float breath; // multiplies the film's strength, near 1
19 + float grain; // 0-1, film grain
20 + float dither; // 0-1, dither
21 + float seed; // 0-1, changes each frame to move the grain
22 +
23 + vec4 base; // the ground
24 + vec4 deep; // the ground at the edges
25 + vec4 ink;
26 + vec4 tone;
27 +};
28 +
29 +const float TAU = 6.2831853;
30 +
31 +float hash12(vec2 p)
32 +{
33 + vec3 p3 = fract(vec3(p.xyx) * 0.1031);
34 + p3 += dot(p3, p3.yzx + 33.33);
35 + return fract((p3.x + p3.y) * p3.z);
36 +}
37 +
38 +float noise(vec2 p)
39 +{
40 + vec2 i = floor(p);
41 + vec2 f = fract(p);
42 + vec2 u = f * f * (3.0 - 2.0 * f);
43 + return mix(mix(hash12(i), hash12(i + vec2(1.0, 0.0)), u.x),
44 + mix(hash12(i + vec2(0.0, 1.0)), hash12(i + vec2(1.0, 1.0)), u.x), u.y);
45 +}
46 +
47 +float fbm(vec2 p)
48 +{
49 + float sum = 0.0;
50 + float amp = 0.5;
51 + mat2 turn = mat2(0.8, 0.6, -0.6, 0.8);
52 + for (int i = 0; i < 5; i++) {
53 + sum += amp * noise(p);
54 + p = turn * p * 2.02 + 17.1;
55 + amp *= 0.5;
56 + }
57 + return sum;
58 +}
59 +
60 +// The film's thickness, and how much film there is, at time t.
61 +vec2 film(vec2 p, float t)
62 +{
63 + vec2 q = vec2(fbm(p + vec2(0.0, t)), fbm(p + vec2(5.2, -t) + 1.3));
64 + vec2 r = vec2(fbm(p + 3.0 * q + vec2(1.7, 9.2) + 0.5 * t), fbm(p + 3.0 * q + vec2(8.3, 2.8) - 0.5 * t));
65 + float thick = fbm(p + 2.5 * r);
66 + float lo = mix(0.78, 0.3, coverage);
67 + float slick = smoothstep(lo, lo + 0.14, fbm(p * 0.6 + 1.5 * q - 0.3 * t + 40.0));
68 + return vec2(thick, slick);
69 +}
70 +
71 +void main()
72 +{
73 + float px = 1.0 / min(size.x, size.y);
74 + vec2 extent = size * px;
75 + vec2 p = qt_TexCoord0 * extent;
76 +
77 + float v = smoothstep(0.35, 1.25, length(p - 0.5 * extent));
78 + vec3 colour = mix(base.rgb, deep.rgb, v);
79 +
80 + // Two samples half a drift apart, each weighted to nothing as it wraps.
81 + float a = oilCycle;
82 + float b = fract(oilCycle + 0.5);
83 + float w = abs(2.0 * a - 1.0);
84 + vec2 s1 = film(p * 2.2, a * 6.0);
85 + vec2 s2 = film(p * 2.2 + 31.7, b * 6.0);
86 + vec2 f = mix(s1, s2, w);
87 +
88 + // Interference bands, monochrome: the film goes light and dark as it
89 + // thickens, in the theme's ink.
90 + float th = f.x * 3.2;
91 + float band = 0.5 + 0.5 * cos(TAU * th);
92 + vec3 tint = mix(mix(deep.rgb, ink.rgb, 0.35), ink.rgb, band);
93 + // Thin film at the slick's edge is brightest; its thick heart darker.
94 + float edge = f.y * (1.0 - f.y) * 4.0;
95 + float strength = f.y * (0.28 + 0.4 * edge) * breath;
96 + colour = mix(colour, tint, strength);
97 + colour = mix(colour, deep.rgb, f.y * smoothstep(0.62, 0.8, f.x) * 0.35);
98 +
99 + // The glass: a faint sheen in a long diagonal.
100 + float sheen = exp(-pow(dot(p - 0.5 * extent, vec2(0.6, 0.8)) / 0.35, 2.0));
101 + colour += vec3(0.04) * sheen;
102 +
103 + vec2 pixel = qt_TexCoord0 * size;
104 + if (grain > 0.0)
105 + colour += (hash12(pixel + seed * 1000.0) - 0.5) * 0.06 * grain;
106 + if (dither > 0.0)
107 + colour += (hash12(pixel + 0.5) + hash12(pixel + 91.3) - 1.0) / 255.0 * dither;
108 +
109 + fragColor = vec4(colour, 1.0) * qt_Opacity;
110 +}
added android/app/src/main/assets/prism.frag
+153 −0
@@ -0,0 +1,153 @@
1 +// Prism: one glowing beam comes in from a set angle and hits a slowly
2 +// turning shape (a circle or a regular polygon), which throws out a
3 +// fan of smaller rays. The rays turn around the shape, each wanders a
4 +// little on its own, and each has its own width, every one slowly
5 +// swelling and thinning at a different rate.
6 +//
7 +// Written in the same Qt header style as field.frag, so Shader.kt's
8 +// (and the site's) `toGles` reads it as is. As there, everything that
9 +// moves is computed in double precision on the CPU (Field.qml,
10 +// Motion.kt) and arrives here as wrapped phases: the shader holds no
11 +// clock.
12 +#version 440
13 +
14 +layout(location = 0) in vec2 qt_TexCoord0;
15 +layout(location = 0) out vec4 fragColor;
16 +
17 +layout(std140, binding = 0) uniform buf {
18 + mat4 qt_Matrix;
19 + float qt_Opacity;
20 +
21 + vec2 size; // pixels
22 + // Positions and lengths in units of the shorter side, as in field.frag.
23 + vec2 centre; // the shape's centre
24 + float radius; // the shape's circumradius
25 + float sides; // 0 for a circle, else 3 to 8
26 + float spin; // the shape's rotation, radians, kept in [0, 2pi)
27 + float beamAngle; // the way the beam travels, radians, 0 = rightward
28 + float rays; // how many rays come out, up to MAX_RAYS
29 + float rayTurn; // the rays' shared rotation, radians, in [0, 2pi)
30 + float cycle; // 0-1; each ray's wander and width change by whole laps of it
31 + float breath; // multiplies the light, near 1
32 + float grain; // 0-1, film grain
33 + float dither; // 0-1, dither
34 + float seed; // 0-1, changes each frame to move the grain
35 +
36 + vec4 base; // the ground
37 + vec4 deep; // the ground at the edges
38 + vec4 ink; // the beam, the shape's edge
39 + vec4 tone; // the rays lean towards this
40 +};
41 +
42 +const float TAU = 6.2831853;
43 +const int MAX_RAYS = 24;
44 +
45 +float hash(float n)
46 +{
47 + return fract(sin(n * 127.1 + 311.7) * 43758.5453);
48 +}
49 +
50 +float hash12(vec2 p)
51 +{
52 + vec3 p3 = fract(vec3(p.xyx) * 0.1031);
53 + p3 += dot(p3, p3.yzx + 33.33);
54 + return fract((p3.x + p3.y) * p3.z);
55 +}
56 +
57 +// Signed distance to the shape, centred at the origin: negative inside.
58 +float shapeDistance(vec2 q)
59 +{
60 + if (sides < 2.5)
61 + return length(q) - radius;
62 + float sector = TAU / sides;
63 + float a = atan(q.y, q.x);
64 + float apothem = radius * cos(0.5 * sector);
65 + return cos(floor(0.5 + a / sector) * sector - a) * length(q) - apothem;
66 +}
67 +
68 +// A ray leaving the centre along `dir`: a bright core `width` wide and a
69 +// softer halo, both widening a little and fading as it goes.
70 +float ray(vec2 q, vec2 dir, float width, float reach)
71 +{
72 + float along = dot(q, dir);
73 + if (along <= 0.0)
74 + return 0.0;
75 + float across = abs(q.x * dir.y - q.y * dir.x);
76 + float w = width * (1.0 + 0.6 * along);
77 + float core = exp(-(across * across) / (w * w));
78 + float halo = exp(-across / (4.0 * w)) * 0.2;
79 + return (core + halo) * exp(-along / reach);
80 +}
81 +
82 +void main()
83 +{
84 + float px = 1.0 / min(size.x, size.y);
85 + vec2 extent = size * px;
86 + vec2 p = qt_TexCoord0 * extent;
87 + vec2 q = p - centre;
88 +
89 + float v = smoothstep(0.35, 1.25, length(p - 0.5 * extent));
90 + vec3 colour = mix(base.rgb, deep.rgb, v);
91 +
92 + // The shape, turned.
93 + mat2 rot = mat2(cos(spin), -sin(spin), sin(spin), cos(spin));
94 + float d = shapeDistance(rot * q);
95 + float outside = smoothstep(-px, px, d);
96 +
97 + vec3 light = vec3(0.0);
98 +
99 + // The beam, from off screen up to the shape. Its far end is the
100 + // centre, under the shape's fill.
101 + vec2 dirIn = vec2(cos(beamAngle), sin(beamAngle));
102 + {
103 + float along = dot(q, dirIn);
104 + float across = abs(q.x * dirIn.y - q.y * dirIn.x);
105 + float w = radius * 0.11;
106 + float core = exp(-(across * across) / (w * w));
107 + float hot = exp(-(across * across) / (0.12 * w * w));
108 + float halo = exp(-across / (3.0 * w)) * 0.35;
109 + float beam = along < 0.0 ? 1.0 : exp(-along * along / (radius * radius * 0.05));
110 + light += (mix(ink.rgb, vec3(1.0), 0.35) * (core + halo) + vec3(0.6) * hot) * beam;
111 + }
112 +
113 + // The rays: spread around the shape, turning together, each with its
114 + // own wander and width. Whole laps of `cycle` keep its wrap seamless,
115 + // and different lap counts keep every ray's width changing at its own
116 + // rate.
117 + for (int i = 0; i < MAX_RAYS; i++) {
118 + if (float(i) >= rays)
119 + break;
120 + float n = float(i) * 7.31 + 1.7;
121 + float wander = 0.35 * (hash(n) - 0.5) + 0.06 * sin(TAU * ((1.0 + mod(float(i), 3.0)) * cycle + hash(n + 1.0)));
122 + float a = TAU * (float(i) + wander) / rays + rayTurn;
123 + vec2 dir = vec2(cos(a), sin(a));
124 + float swell = 0.5 + 0.5 * sin(TAU * (float(i + 2) * cycle + hash(n + 2.0)));
125 + float width = radius * (0.012 + 0.05 * hash(n + 3.0)) * (0.35 + 0.9 * swell);
126 + float reach = 0.5 + 0.9 * hash(n + 4.0);
127 + float strength = 0.55 + 0.45 * hash(n + 5.0);
128 + vec3 tint = mix(ink.rgb, tone.rgb, 0.3 + 0.7 * hash(n + 6.0));
129 + light += mix(tint, vec3(1.0), 0.15) * ray(q, dir, width, reach) * strength;
130 + }
131 +
132 + light *= breath;
133 + // Soft-clip, so where light piles up it whitens rather than clipping.
134 + colour += (vec3(1.0) - exp(-light * 1.1)) * outside;
135 +
136 + // The shape: dark glass with a glowing edge, brightest where the beam
137 + // strikes, and a glow just outside.
138 + vec2 normal = q / max(length(q), 1e-4);
139 + float lit = 0.35 + 0.65 * max(0.0, -dot(normal, dirIn));
140 + vec3 glass = mix(mix(deep.rgb, ink.rgb, 0.1), ink.rgb, 0.25 * smoothstep(-radius, 0.0, d) * lit);
141 + colour = mix(glass, colour, outside);
142 + float edge = exp(-abs(d) / (2.5 * px + radius * 0.012));
143 + float glow = exp(-max(d, 0.0) / (radius * 0.18)) * 0.25 * outside;
144 + colour += mix(ink.rgb, vec3(1.0), 0.3) * (edge * 0.8 + glow) * lit * breath;
145 +
146 + vec2 pixel = qt_TexCoord0 * size;
147 + if (grain > 0.0)
148 + colour += (hash12(pixel + seed * 1000.0) - 0.5) * 0.06 * grain;
149 + if (dither > 0.0)
150 + colour += (hash12(pixel + 0.5) + hash12(pixel + 91.3) - 1.0) / 255.0 * dither;
151 +
152 + fragColor = vec4(colour, 1.0) * qt_Opacity;
153 +}
added android/app/src/main/assets/spheres.frag
+139 −0

Click to load diff…

added android/app/src/main/java/org/neiam/recourse/app/ui/login/Glass.kt
+147 −0

Click to load diff…

added android/app/src/main/java/org/neiam/recourse/app/ui/login/LoginBackdrop.kt
+52 −0

Click to load diff…

modified android/app/src/main/java/org/neiam/recourse/app/ui/login/LoginScreen.kt
+54 −22

Click to load diff…

added android/app/src/main/java/org/neiam/recourse/app/ui/shader/Balls.kt
+219 −0

Click to load diff…

added android/app/src/main/java/org/neiam/recourse/app/ui/shader/FieldRenderer.kt
+158 −0

Click to load diff…

added android/app/src/main/java/org/neiam/recourse/app/ui/shader/FieldTextureView.kt
+160 −0

Click to load diff…

added android/app/src/main/java/org/neiam/recourse/app/ui/shader/Motion.kt
+240 −0

Click to load diff…

added android/app/src/main/java/org/neiam/recourse/app/ui/shader/Shader.kt
+57 −0

Click to load diff…

added android/app/src/main/java/org/neiam/recourse/app/ui/shader/ShaderBackground.kt
+94 −0

Click to load diff…

added android/app/src/main/java/org/neiam/recourse/app/ui/shader/ShaderPalette.kt
+47 −0

Click to load diff…

added android/app/src/main/java/org/neiam/recourse/app/ui/shader/ShaderSettings.kt
+79 −0

Click to load diff…

added android/app/src/test/java/org/neiam/recourse/app/ui/login/LoginGlassContrastTest.kt
+73 −0

Click to load diff…

added android/app/src/test/java/org/neiam/recourse/app/ui/shader/ShaderTest.kt
+62 −0

Click to load diff…

modified android/gradle/libs.versions.toml
+3 −0

Click to load diff…

Parents: a8b6885