cranpose-ui-graphics 0.1.77

Pure math/data for drawing & units in Cranpose
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
//! LiquidGlass effect: a refractive glass material rendered via RuntimeShader.
//!
//! An SDF rounded-rect lens over the backdrop using the wcKSRD source mapping,
//! blur, edge light, saturation, adaptive exposure, tint, and dither.
//!
//! The wcKSRD optical program samples both sharp and blurred rays from one
//! captured backdrop so displacement never reveals a second scene layer.

use crate::{Color, RenderEffect, RuntimeShader};

/// Uniform slot containing wcKSRD-owned backdrop blur reach in physical pixels.
pub const GLASS_BLUR_RADIUS_UNIFORM: usize = 93;
/// Uniform slot containing the normalized wcKSRD ray-return exponent.
pub const GLASS_REFRACTION_CURVE_UNIFORM: usize = 94;
/// Uniform slot containing normalized wcKSRD spectral dispersion strength.
pub const GLASS_DISPERSION_UNIFORM: usize = 95;
/// Uniform slot controlling displacement of the transmitted backdrop path.
/// Reflected meniscus rays remain independent.
pub const GLASS_TRANSMISSION_REFRACTION_UNIFORM: usize = 96;
/// Uniform slot containing px-per-dp for cover-mode optical bands.
pub const GLASS_EFFECT_DENSITY_UNIFORM: usize = 99;
/// Uniform slot controlling energy absorbed by the meniscus transmission
/// path. Reflection and spectral return remain independent.
pub const GLASS_MENISCUS_ABSORPTION_UNIFORM: usize = 100;
/// Uniform slot containing the interactive rim-fold band depth in dp (the
/// shader resolves it against the live shape inradius; zero = fold off).
pub const GLASS_FOLD_DEPTH_UNIFORM: usize = 88;
/// Uniform slot containing the uniform face magnification ratio of a riding
/// lens (values <= 1 mean no zoom; the rim band keeps the wcKSRD mapping).
pub const GLASS_OPTICAL_ZOOM_UNIFORM: usize = 89;
/// Uniform slot (two floats) containing the optical-zoom axis offset from
/// the SDF center, in dp — a leaning lens magnifies about the content it
/// rides, not its shifted silhouette.
pub const GLASS_OPTICAL_ZOOM_ANCHOR_UNIFORM: usize = 128;
/// Uniform slot containing continuous optical activity (identity at zero).
pub const GLASS_ACTIVITY_UNIFORM: usize = 111;
/// Uniform slot containing the base surface tint that remains when optical
/// activity reaches zero. The four consecutive floats are RGBA.
pub const GLASS_RESTING_TINT_UNIFORM: usize = 113;

/// LiquidGlass WGSL shader source.
///
/// Bindings:
/// - group(0) binding(0): input_texture (the content behind the glass)
/// - group(0) binding(1): input_sampler
/// - group(1) binding(0): uniform array u[64 vec4s]
///
/// Uniform layout (float indices; sizes in dp, converted in-shader):
///   0,1: container size (width, height) dp
///   2,3: rect center (cx, cy) dp
///   4,5: rect size (w, h) dp
///   6: corner radius dp
///   9: wcKSRD refraction depth as a fraction of the shape inradius
///  94: wcKSRD refraction curve exponent (0.05..1.0)
///  95: wcKSRD spectral dispersion strength (0..1)
///  96: transmitted-path refraction strength (0 = fixed backdrop coordinates)
///  99: cover-mode px-per-dp for density-stable optical bands
/// 100: meniscus transmission absorption (0 = clear, 1 = full lens absorption)
///  11: highlight intensity
///  14,15,16,17: tint color (r,g,b,a)
///  18: saturation (1.0 = unchanged)
///  20: lift (−1..1; screen-blend toward white / multiply toward black)
///  21: dither amount (0..1, in 1/255 steps)
///  24: contrast (1.0 = neutral; ≤0 treated as 1.0)
///  80: loupe mode (>0.5 replaces the lens terms with the drop optic)
///  81,82: loupe focus offset from the shape center (dp)
///  83: loupe center magnification (m0)
///  90: loupe optical activity (0 = identity, 1 = fully raised drop)
///  93: wcKSRD blur reach in physical pixels
/// 111: continuous optical activity (0 = exact backdrop identity, 1 = full)
/// 113..116: resting surface tint RGBA (transparent = no resting surface)
/// 122,123: ambient light return direction (screen-space vector; zero =
///          unset -> light overhead, return glow at the bottom rim)
/// 124..126: ink recolor RGB — the lens recolors dark transmitted ink
/// 127: ink recolor strength (0 = off)
pub const LIQUID_GLASS_WGSL: &str = include_str!("../shaders/liquid_glass.wgsl");

/// Uniform slot of the ambient light return direction (x at 122, y at 123).
pub const GLASS_LIGHT_DIRECTION_UNIFORM: usize = 122;

/// Configuration for the LiquidGlass effect.
#[derive(Clone, Debug, PartialEq)]
pub struct LiquidGlassSpec {
    /// Corner radius of the glass rounded rect, in dp.
    pub corner_radius: f32,
    /// wcKSRD refraction depth as a fraction of the shape inradius.
    pub refraction_depth: f32,
    /// wcKSRD ray-return exponent. Lower values return to local sampling
    /// quickly; 1.0 preserves the mirrored fold across the full depth.
    pub refraction_curve: f32,
    /// Backdrop blur reach evaluated by wcKSRD.
    pub blur_radius: f32,
    /// Specular highlight intensity.
    pub highlight: f32,
    /// Saturation/vibrancy multiplier applied to the refracted backdrop.
    pub saturation: f32,
    /// Scheme lift: positive screen-blends toward white (light scheme),
    /// negative multiplies toward black (dark scheme). Screen keeps the
    /// backdrop ghosts colored, unlike an alpha mix.
    pub lift: f32,
    /// Contrast pivot around mid-gray (1.0 = neutral).
    pub contrast: f32,
    /// Energy absorbed from the transmitted ray at the meniscus. This does
    /// not reduce the reflected or spectrally separated light paths.
    pub meniscus_absorption: f32,
    /// Anti-banding dither amount (0..1, in 1/255 steps).
    pub dither: f32,
}

impl Default for LiquidGlassSpec {
    fn default() -> Self {
        Self {
            corner_radius: 28.0,
            refraction_depth: 0.34,
            refraction_curve: 0.25,
            blur_radius: 0.0,
            highlight: 0.7,
            saturation: 1.0,
            lift: 0.0,
            contrast: 1.0,
            meniscus_absorption: 1.0,
            dither: 0.5,
        }
    }
}

/// A rectangular region where the liquid glass effect is applied.
///
/// Coordinates are in dp relative to the effect area.
#[derive(Clone, Debug)]
pub struct LiquidGlassRect {
    /// Left edge in dp.
    pub left: f32,
    /// Top edge in dp.
    pub top: f32,
    /// Width in dp.
    pub width: f32,
    /// Height in dp.
    pub height: f32,
    /// Tint color applied to the glass.
    pub tint_color: Color,
}

/// Build a `RenderEffect` that applies the LiquidGlass shader to a single rect.
///
/// `area_width` and `area_height` are the total effect area size in dp.
pub fn liquid_glass_effect(
    rect: &LiquidGlassRect,
    spec: &LiquidGlassSpec,
    area_width: f32,
    area_height: f32,
) -> RenderEffect {
    let mut shader = RuntimeShader::new(LIQUID_GLASS_WGSL);

    // Compute center in dp
    let cx = rect.left + rect.width * 0.5;
    let cy = rect.top + rect.height * 0.5;

    // Uniform layout — see doc comment on LIQUID_GLASS_WGSL
    shader.set_float2(0, area_width, area_height); // container size
    shader.set_float2(2, cx, cy); // rect center
    shader.set_float2(4, rect.width, rect.height); // rect size
    shader.set_float(6, spec.corner_radius);
    shader.set_float(9, spec.refraction_depth.clamp(0.0, 2.0));
    shader.set_float(
        GLASS_REFRACTION_CURVE_UNIFORM,
        spec.refraction_curve.clamp(0.05, 1.0),
    );
    shader.set_float(11, spec.highlight);
    shader.set_float4(
        14,
        rect.tint_color.r(),
        rect.tint_color.g(),
        rect.tint_color.b(),
        rect.tint_color.a(),
    );
    shader.set_float(18, spec.saturation);
    shader.set_float(20, spec.lift);
    shader.set_float(21, spec.dither);
    shader.set_float(24, spec.contrast);
    shader.set_float(GLASS_BLUR_RADIUS_UNIFORM, spec.blur_radius.max(0.0));
    shader.set_float(GLASS_TRANSMISSION_REFRACTION_UNIFORM, 1.0);
    shader.set_float(GLASS_EFFECT_DENSITY_UNIFORM, 1.0);
    shader.set_float(
        GLASS_MENISCUS_ABSORPTION_UNIFORM,
        spec.meniscus_absorption.clamp(0.0, 1.0),
    );
    shader.set_float(GLASS_ACTIVITY_UNIFORM, 1.0);
    shader.set_input_padding(liquid_glass_input_padding(spec));

    RenderEffect::runtime_shader(shader)
}

/// How far the shader's refracted and internally reflected samples can reach
/// outside the effect rect.
fn liquid_glass_input_padding(spec: &LiquidGlassSpec) -> f32 {
    spec.blur_radius.max(2.0).ceil()
}

/// The text-drag loupe material: a solid glass drop magnifying an offset
/// focus (the grab point under the finger), displayed inside a capsule
/// floating above it. ONE continuous wcKSRD field (example/shaders.txt):
/// `sample = focus + p·lens_scale/m` — the magnified face, the rim's
/// descending-branch inversion and the rim line all come from the same
/// displacement mapping, with no band boundaries.
#[derive(Clone, Debug, PartialEq)]
pub struct LiquidLoupeSpec {
    /// Magnification (the reference loupe measures a uniform ~1.25×).
    pub magnification: f32,
    /// Focus offset from the bubble center, dp (the reference samples 75 dp
    /// below its center: content from under the finger, displayed above).
    pub focus_offset: (f32, f32),
    /// Spectral separation of the meniscus return.
    pub dispersion: f32,
    /// Specular rim intensity.
    pub highlight: f32,
    /// Continuous optical activity. Geometry is owned by the caller; this
    /// coordinate raises and lowers refraction, magnification, dispersion,
    /// fold return, and edge light without cross-fading sampled content.
    pub activity: f32,
    /// Corner radius in dp. The text loupe follows the smaller half-extent as
    /// it grows, producing a narrow capsule at birth and the full horizontal
    /// capsule at rest. Values <= 0 select that capsule radius automatically.
    pub corner_radius: f32,
}

impl Default for LiquidLoupeSpec {
    fn default() -> Self {
        Self {
            magnification: 1.25,
            focus_offset: (0.0, 75.0),
            dispersion: 0.36,
            // The rim is a distinct light path, but its gain stays low enough
            // that the transmitted face remains transparent and high-contrast.
            highlight: 0.42,
            activity: 1.0,
            corner_radius: 0.0,
        }
    }
}

/// Builds the loupe backdrop effect for a capsule node of `node_size` dp.
/// Explicit-rect mode: the container carries the node size in dp and the
/// shader derives px-per-dp from the renderer-injected pixel rect, so the
/// bubble lands correctly at ANY render scale (live density, robot captures
/// at 1.0, fractional desktop scales).
pub fn liquid_loupe_effect(node_size: (f32, f32), spec: &LiquidLoupeSpec) -> RenderEffect {
    let (w, h) = (node_size.0.max(1.0), node_size.1.max(1.0));
    let activity = spec.activity.clamp(0.0, 1.0);
    let mut shader = RuntimeShader::new(LIQUID_GLASS_WGSL);
    shader.set_float2(0, w, h); // container = node size dp
    shader.set_float2(2, w * 0.5, h * 0.5); // capsule centered in the node
    shader.set_float2(4, w, h);
    if spec.corner_radius > 0.0 {
        shader.set_float(6, spec.corner_radius.min(0.5 * h.min(w)));
    } else {
        shader.set_float(6, -1.0); // capsule radius sentinel
    }
    shader.set_float(9, 0.34 * activity);
    shader.set_float(GLASS_REFRACTION_CURVE_UNIFORM, 0.25);
    shader.set_float(
        GLASS_DISPERSION_UNIFORM,
        spec.dispersion.clamp(0.0, 1.0) * activity,
    );
    shader.set_float(GLASS_TRANSMISSION_REFRACTION_UNIFORM, 1.0);
    shader.set_float(GLASS_EFFECT_DENSITY_UNIFORM, 1.0);
    shader.set_float(GLASS_MENISCUS_ABSORPTION_UNIFORM, 1.0);
    shader.set_float(GLASS_ACTIVITY_UNIFORM, 1.0);
    shader.set_float(11, spec.highlight * activity);
    shader.set_float4(14, 1.0, 1.0, 1.0, 0.0); // no tint
    shader.set_float(18, 1.0); // saturation neutral
    shader.set_float(20, 0.0); // no lift
    shader.set_float(21, 0.5); // dither
    shader.set_float(24, 1.0); // contrast neutral
    shader.set_float(28, activity); // interactive-lens rim style
    shader.set_float(80, 1.0); // loupe mode
    shader.set_float2(81, spec.focus_offset.0, spec.focus_offset.1);
    shader.set_float(83, 1.0 + (spec.magnification.max(0.2) - 1.0) * activity);
    shader.set_float(90, activity);
    // The capture must cover the farthest sample: the single field never
    // reaches beyond the focus offset plus the node's own footprint.
    let focus_reach = (spec.focus_offset.0.powi(2) + spec.focus_offset.1.powi(2)).sqrt();
    shader.set_input_padding((focus_reach + 8.0).ceil());
    RenderEffect::runtime_shader(shader)
}

/// The text edit-menu material measured from the reference: a 44 dp glass
/// capsule of high transparency — weak backdrop blur (text behind stays
/// readable through the body), a whisper of dark tint, a ~2 px top rim
/// highlight and faint side rims. `progress` (0..1) materializes the
/// material: at 0 the glass is optically absent (the menu fades in as a
/// smudge that sharpens), at 1 it carries the full rim and tint.
/// `blur_radius_px` is the backdrop blur in physical px (density-scaled by
/// the caller; everything else is dp in explicit-rect mode).
pub fn liquid_menu_glass_effect(
    node_size: (f32, f32),
    blur_radius_px: f32,
    progress: f32,
) -> RenderEffect {
    let (w, h) = (node_size.0.max(1.0), node_size.1.max(1.0));
    let p = progress.clamp(0.0, 1.0);
    let mut shader = RuntimeShader::new(LIQUID_GLASS_WGSL);
    shader.set_float2(0, w, h); // container = node size dp
    shader.set_float2(2, w * 0.5, h * 0.5);
    shader.set_float2(4, w, h);
    shader.set_float(6, -1.0); // capsule
    shader.set_float(9, 0.10 * p);
    shader.set_float(GLASS_REFRACTION_CURVE_UNIFORM, 0.25);
    shader.set_float(GLASS_TRANSMISSION_REFRACTION_UNIFORM, 1.0);
    shader.set_float(GLASS_EFFECT_DENSITY_UNIFORM, 1.0);
    shader.set_float(GLASS_ACTIVITY_UNIFORM, 1.0);
    shader.set_float(11, 0.19 * p); // rim intensity (the reference settled
                                    // pill peaks ~x1.9 of its baseline on
                                    // BOTH long edges)
                                    // Settled material (measured on the reference still: white text behind
                                    // the pill reads ~242/255 through it, the dark card dims ~x0.78): a
                                    // WHISPER of dark tint plus a mild contrast pivot — not the heavy
                                    // dim+lift that flattened ghosts into an opaque-looking fill.
    shader.set_float4(14, 0.0, 0.0, 0.0, 0.04 * p);
    shader.set_float(18, 1.0 + 0.10 * p); // mild vibrancy
    shader.set_float(20, -0.06 * p);
    shader.set_float(24, 1.0 + 0.05 * p); // gentle contrast pivot
    shader.set_float(21, 0.5);
    // The settled reference capsule keeps a HEAVY backdrop blur: the
    // "Styles" pill behind it reads as an illegible ~10%-contrast smudge
    // (menu-materialize c_072). The old (1-p) ramp drained the blur to
    // ~1px at settle, so backdrop text interleaved sharply with the menu
    // labels. Materialize still starts at full smudge and relaxes a
    // little as the labels sharpen.
    let requested_blur = if blur_radius_px > 0.5 {
        blur_radius_px * (1.0 - 0.4 * p)
    } else {
        0.0
    };
    // Split the blur exactly like the morph-glass material path: the
    // wcKSRD optical blur is a 9x9 footprint, so spreading it over a large
    // radius quantizes into a visible GRID (the "lines instead of blur"
    // on the edit menu). Cap the optical tap at the safe radius and route
    // everything heavier through the smooth Gaussian pass.
    const WCKSRD_OPTICAL_BLUR_RADIUS_PX: f32 = 2.0;
    let wcksrd_blur = requested_blur.min(WCKSRD_OPTICAL_BLUR_RADIUS_PX);
    let gaussian_blur = (requested_blur - wcksrd_blur).max(0.0);
    shader.set_float(GLASS_BLUR_RADIUS_UNIFORM, wcksrd_blur);
    shader.set_input_padding(12.0 + requested_blur);
    let optical = RenderEffect::runtime_shader(shader);
    if gaussian_blur > f32::EPSILON {
        RenderEffect::blur_with_edge_treatment(gaussian_blur, crate::TileMode::Mirror).then(optical)
    } else {
        optical
    }
}

/// Build a chained `RenderEffect` for multiple liquid glass rects.
///
/// Each rect is applied as a separate shader pass chained together.
pub fn liquid_glass_effect_multi(
    rects: &[LiquidGlassRect],
    spec: &LiquidGlassSpec,
    area_width: f32,
    area_height: f32,
) -> Option<RenderEffect> {
    let mut result: Option<RenderEffect> = None;
    for rect in rects {
        let effect = liquid_glass_effect(rect, spec, area_width, area_height);
        result = Some(match result {
            Some(existing) => existing.then(effect),
            None => effect,
        });
    }
    result
}

#[cfg(test)]
mod tests {
    use super::*;

    fn rect() -> LiquidGlassRect {
        LiquidGlassRect {
            left: 100.0,
            top: 50.0,
            width: 200.0,
            height: 100.0,
            tint_color: Color(0.5, 0.5, 1.0, 0.1),
        }
    }

    #[test]
    fn liquid_glass_spec_defaults_match_wcksrd() {
        let spec = LiquidGlassSpec::default();
        assert_eq!(spec.corner_radius, 28.0);
        assert_eq!(spec.refraction_depth, 0.34);
        assert_eq!(spec.refraction_curve, 0.25);
        assert_eq!(spec.blur_radius, 0.0);
        assert_eq!(spec.saturation, 1.0);
        assert_eq!(spec.lift, 0.0);
        assert_eq!(spec.contrast, 1.0);
        assert_eq!(spec.meniscus_absorption, 1.0);
    }

    #[test]
    fn liquid_glass_effect_packs_the_single_optical_program() {
        let spec = LiquidGlassSpec {
            refraction_depth: 0.72,
            refraction_curve: 0.8,
            blur_radius: 6.0,
            saturation: 1.6,
            lift: 0.12,
            contrast: 1.05,
            meniscus_absorption: 0.3,
            dither: 1.0,
            ..LiquidGlassSpec::default()
        };
        let RenderEffect::Shader { shader } = liquid_glass_effect(&rect(), &spec, 800.0, 600.0)
        else {
            panic!("liquid glass must be one runtime shader");
        };
        let uniforms = shader.uniforms();
        assert_eq!(&uniforms[0..6], &[800.0, 600.0, 200.0, 100.0, 200.0, 100.0]);
        assert_eq!(uniforms[9], 0.72);
        assert_eq!(uniforms[GLASS_REFRACTION_CURVE_UNIFORM], 0.8);
        assert_eq!(uniforms[GLASS_TRANSMISSION_REFRACTION_UNIFORM], 1.0);
        assert_eq!(uniforms[GLASS_EFFECT_DENSITY_UNIFORM], 1.0);
        assert_eq!(uniforms[GLASS_MENISCUS_ABSORPTION_UNIFORM], 0.3);
        assert_eq!(uniforms[18], 1.6);
        assert_eq!(uniforms[20], 0.12);
        assert_eq!(uniforms[21], 1.0);
        assert_eq!(uniforms[24], 1.05);
        assert_eq!(uniforms[GLASS_BLUR_RADIUS_UNIFORM], 6.0);
        assert_eq!(shader.input_padding(), 6.0);
    }

    #[test]
    fn refraction_depth_is_clamped_at_the_shader_boundary() {
        for (input, expected) in [(-1.0, 0.0), (0.8, 0.8), (3.0, 2.0)] {
            let spec = LiquidGlassSpec {
                refraction_depth: input,
                ..LiquidGlassSpec::default()
            };
            let RenderEffect::Shader { shader } = liquid_glass_effect(&rect(), &spec, 800.0, 600.0)
            else {
                panic!("liquid glass must be one runtime shader");
            };
            assert_eq!(shader.uniforms()[9], expected);
        }
    }

    #[test]
    fn refraction_curve_is_clamped_at_the_shader_boundary() {
        for (input, expected) in [(-1.0, 0.05), (0.8, 0.8), (3.0, 1.0)] {
            let spec = LiquidGlassSpec {
                refraction_curve: input,
                ..LiquidGlassSpec::default()
            };
            let RenderEffect::Shader { shader } = liquid_glass_effect(&rect(), &spec, 800.0, 600.0)
            else {
                panic!("liquid glass must be one runtime shader");
            };
            assert_eq!(shader.uniforms()[GLASS_REFRACTION_CURVE_UNIFORM], expected);
        }
    }

    #[test]
    fn loupe_and_menu_use_the_same_wcksrd_program() {
        let loupe_spec = LiquidLoupeSpec::default();
        let RenderEffect::Shader { shader: loupe } =
            liquid_loupe_effect((117.0, 82.0), &loupe_spec)
        else {
            panic!("loupe must use the shared runtime shader");
        };
        assert_eq!(loupe.uniforms()[9], 0.34);
        assert_eq!(loupe.uniforms()[GLASS_REFRACTION_CURVE_UNIFORM], 0.25);
        assert_eq!(
            loupe.uniforms()[GLASS_DISPERSION_UNIFORM],
            loupe_spec.dispersion
        );
        assert_eq!(loupe.uniforms()[80], 1.0);
        assert!(loupe.input_padding() >= 75.0);

        // Settled blur stays heavy (reference c_072: backdrop text is an
        // illegible smudge through the settled capsule) — and heavy blur
        // routes through a Gaussian pass chained INTO the optical shader:
        // the wcKSRD 9x9 tap caps at its safe radius, so the remainder
        // never quantizes into the grid the edit menu showed.
        let RenderEffect::Chain { first, second } =
            liquid_menu_glass_effect((240.0, 44.0), 8.0, 1.0)
        else {
            panic!("a heavy settled blur must chain a Gaussian into the shader");
        };
        let RenderEffect::Blur { radius_x, .. } = *first else {
            panic!("the chain's first stage is the Gaussian remainder");
        };
        assert!(radius_x > 0.0);
        let RenderEffect::Shader { shader: menu } = *second else {
            panic!("the chain's second stage is the wcKSRD program");
        };
        assert_eq!(menu.uniforms()[9], 0.10);
        assert_eq!(menu.uniforms()[GLASS_REFRACTION_CURVE_UNIFORM], 0.25);
        assert!(menu.uniforms()[GLASS_BLUR_RADIUS_UNIFORM] <= 2.0 + 1.0e-6);
    }

    #[test]
    fn liquid_glass_effect_multi_handles_empty_and_multiple_rects() {
        let spec = LiquidGlassSpec::default();
        assert!(liquid_glass_effect_multi(&[], &spec, 800.0, 600.0).is_none());
        let rects = [rect(), rect()];
        assert!(matches!(
            liquid_glass_effect_multi(&rects, &spec, 800.0, 600.0),
            Some(RenderEffect::Chain { .. })
        ));
    }
}