diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-28 16:44:51 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:15 -0300 |
| commit | deeb8ac54f71d4322a778336db9a7aec411c23ce (patch) | |
| tree | a1ccddd6dc7acf31a88a0d27153848b053ac10d1 /shaders/decor.frag.glsl | |
| parent | 3267d276ab2553adb412183eb92390ed579b494f (diff) | |
| download | pardes-deeb8ac54f71d4322a778336db9a7aec411c23ce.tar.gz pardes-deeb8ac54f71d4322a778336db9a7aec411c23ce.zip | |
G1: Lift, soft elevation shadows (off by default)
`Lift` (a GUI toggle, capability lift) lifts the focused pane on a
critically damped spring (animation.Spring: closed form, about 240 ms to
settle, velocity kept across retargets, settled = no frames) and floats
notices. The core puts the lift on the regions (Region.lift, on the wire);
the GUI casts from it: a soft shadow is decor, an erf rectangle on one
quad grown by 3 sigma (decor.frag, flag 0x10000000), in the quad's own
space so a track's transform carries it; darken-only, the caster's rect
left alone, alpha pre-warped for linear light and IGN-dithered. Cast last
in its group, so a neighbour's rails and rules darken with its text; a
notice's before its rule. Strength is capped per theme so text over the
darkest shadow keeps min(its contrast, 4.5) (test over the native themes).
Opt-in until the focus lift/dim default is decided. Feel review material:
docs/effects.md. Test-mode PARDES_TEST_SERIES keeps every captured frame.
Shared files touched: pardes.zig (two fields, one nextWake line),
detached/wire.zig (lift on the region), config.zig, builtins.zig
(capability), gui.zig. Not touched: Messages.zig, mouse.zig, tty,
host_io.
Diffstat (limited to 'shaders/decor.frag.glsl')
| -rw-r--r-- | shaders/decor.frag.glsl | 58 |
1 files changed, 51 insertions, 7 deletions
diff --git a/shaders/decor.frag.glsl b/shaders/decor.frag.glsl index 4c2bd6d8..77f9c95e 100644 --- a/shaders/decor.frag.glsl +++ b/shaders/decor.frag.glsl @@ -1,24 +1,68 @@ #version 450 -// Decor: a flat, hard-edged fill (a rule, a rail, a grip mark, a bar cursor) -// that ui.vert.glsl places like a cell, its track's transition included. Its -// colour rides in the cell's ground (a_bg) and its coverage in a_fg.r. The -// pipeline blends it as the overlay pipeline does (backgroundLayerBlend), so -// a fading rule shows through, and the result is that pipeline's exactly. -// Ink (a cursor) is drawn with the opacity uniform at 1. +// Decor, drawn by ui.vert.glsl like a cell, its track's transition included, +// and blended as the overlay pipeline blends (backgroundLayerBlend). Ink (a +// cursor) is drawn with the opacity uniform at 1. +// +// Flat: a hard-edged fill (a rule, a rail, a grip mark, a bar cursor). Its +// colour rides in the cell's ground (a_bg), its coverage in a_fg.r, so the +// result is the overlay pipeline's exactly. +// +// Soft shadow (flag 0x10000000): a rectangle's shadow blurred by a Gaussian, +// in closed form (the product of two erf edges), on one quad grown by 3 +// sigma: no blur pass. Everything is in the quad's own 0..1 space, so a +// track's transform carries it: sigma per axis in the uv, the caster's +// offset from its shadow in fg.gb, the strength in fg.r. The caster's own +// rectangle is left alone (it is drawn already), and the alpha is pre-warped +// so black darkens in linear light, then dithered so it never bands. layout(std140, set = 3, binding = 0) uniform UiUniforms { float background_opacity; } u_ui; +layout(location = 0) in vec2 v_uv; layout(location = 1) in vec3 v_fg; layout(location = 2) in vec3 v_bg; +layout(location = 3) in vec2 v_cell_uv; +layout(location = 4) flat in uvec4 v_effect; layout(location = 5) flat in vec4 v_clip; layout(location = 0) out vec4 o_col; +// erf to about 4e-4 (Winitzki's approximation): smooth, cheap, odd. +float erfApprox(float x) { + float x2 = x * x; + const float a = 0.147; + float e = sqrt(1.0 - exp(-x2 * (1.2732395 + a * x2) / (1.0 + a * x2))); + return x < 0.0 ? -e : e; +} + +// How much of [lo, hi] a Gaussian of sigma s centred at x covers. +float edge(float x, float lo, float hi, float s) { + float k = 0.70710678 / s; + return 0.5 * (erfApprox((x - lo) * k) - erfApprox((x - hi) * k)); +} + +float ign(vec2 p) { + return fract(52.9829189 * fract(dot(p, vec2(0.06711056, 0.00583715)))); +} + void main() { if (v_clip.z >= v_clip.x && (gl_FragCoord.x < v_clip.x || gl_FragCoord.x >= v_clip.z || gl_FragCoord.y < v_clip.y || gl_FragCoord.y >= v_clip.w)) discard; - o_col = vec4(v_bg * clamp(u_ui.background_opacity, 0.0, 1.0), v_fg.r); + float opacity = clamp(u_ui.background_opacity, 0.0, 1.0); + if ((v_effect.x & 0x10000000u) == 0u) { + o_col = vec4(v_bg * opacity, v_fg.r); + return; + } + vec2 s = v_uv; + vec2 m = 3.0 * s; + vec2 p = v_cell_uv; + vec2 caster0 = m - v_fg.gb; + vec2 caster1 = 1.0 - m - v_fg.gb; + if (all(greaterThanEqual(p, caster0)) && all(lessThan(p, caster1))) discard; + float a = v_fg.r * edge(p.x, m.x, 1.0 - m.x, s.x) * edge(p.y, m.y, 1.0 - m.y, s.y); + a = 1.0 - pow(max(1.0 - a, 0.0), 1.0 / 2.2); + a = clamp(a + (ign(gl_FragCoord.xy) - 0.5) / 255.0, 0.0, 1.0); + o_col = vec4(v_bg * opacity, a); } |
