diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-28 16:30:57 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:15 -0300 |
| commit | 1ed34e1538f45daecc2c8a551dc0fb7aba5f3f54 (patch) | |
| tree | eddcf21a1e5b35f7871b521c747e851b1134f512 /shaders/prebuilt/post-glitch.frag.glsl | |
| parent | be09d1ec7abd71f4e52f05942a941d76b6d420f2 (diff) | |
| download | pardes-1ed34e1538f45daecc2c8a551dc0fb7aba5f3f54.tar.gz pardes-1ed34e1538f45daecc2c8a551dc0fb7aba5f3f54.zip | |
Crt, Ripple and Glitch take a level, 0 to 3, tunable at run time
Coordinator's request: `Crt 0..3` (likewise Ripple, Glitch), 0 off, `on`
the default level 2 (the polished rewrite), `off` and a bare word as
before. The level is one uniform (pardesLevel, beside pardesOpaque in the
prefix's own block); each pass picks its constants by it. Level 3 is at
least as strong as the old effects, measured as pixels changed by more
than 8 in a channel against a plain frame: Crt 18.3% (old 17.4%), Ripple
11.1% (9.5%), Glitch 9.3% a frame (8.1%); Glitch's level raises how often
it bursts as well as how hard. Config and ctl report `Crt 2` / `Crt off`.
Shared files touched: ninep/ctl.zig (the report line). Not touched:
pardes.zig, Messages.zig, mouse.zig, gui.zig, detached/*.
Diffstat (limited to 'shaders/prebuilt/post-glitch.frag.glsl')
| -rw-r--r-- | shaders/prebuilt/post-glitch.frag.glsl | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/shaders/prebuilt/post-glitch.frag.glsl b/shaders/prebuilt/post-glitch.frag.glsl index 46538452..7b288237 100644 --- a/shaders/prebuilt/post-glitch.frag.glsl +++ b/shaders/prebuilt/post-glitch.frag.glsl @@ -39,12 +39,19 @@ layout(set = 3, binding = 0, std140) uniform Globals { uniform vec3 iSelectionBackgroundColor; }; -// pardes's own: 1 when the window is opaque, so a pass cannot punch holes -// in it through its alpha. +// pardes's own: pardesOpaque is 1 when the window is opaque, so a pass +// cannot punch holes in it through its alpha; pardesLevel is a bundled +// pass's strength, 1 to 3 (`Crt 3`), and 0 for a user's file. layout(set = 3, binding = 1, std140) uniform PardesPost { float pardesOpaque; + float pardesLevel; }; +// A bundled pass's constant at levels 1, 2 and 3. +float pardesByLevel(float one, float two, float three) { + return pardesLevel < 1.5 ? one : (pardesLevel < 2.5 ? two : three); +} + #define CURSORSTYLE_BLOCK 0 #define CURSORSTYLE_BLOCK_HOLLOW 1 #define CURSORSTYLE_BAR 2 @@ -65,7 +72,8 @@ void main() { // The shader's own lines count from 1, so glslc's errors name them. #line 1 -// Glitch: now and then the signal slips. Every couple of seconds a short +// Glitch: now and then the signal slips. At the default level, every couple +// of seconds a short // burst tears a few horizontal bands sideways and pulls their red and blue // apart; the bands are sized in pixels and the burst eases in and out over // a fraction of a second, so it reads as one event rather than a flicker, @@ -74,12 +82,15 @@ void main() { // A torn band's brightness dips in linear light. It is a Shadertoy file: // pardes puts its prefix before it. -const float PERIOD = 2.4; // seconds between bursts, on average -const float BURST = 0.28; // seconds a burst lasts -const float STEP_HZ = 24.0; // how often a burst re-tears -const float SHIFT_PX = 14.0; -const float SPLIT_PX = 2.5; -const float DIP = 0.12; +// Each at levels 1, 2 and 3 (`Glitch 1`..`Glitch 3`); 2 is the default. A +// higher level slips more often and harder. +float period() { return pardesByLevel(4.5, 2.4, 0.55); } // seconds between bursts, on average +float burst() { return pardesByLevel(0.2, 0.28, 0.5); } // seconds a burst lasts +float stepHz() { return pardesByLevel(20.0, 24.0, 30.0); } // how often a burst re-tears +float shiftPx() { return pardesByLevel(8.0, 14.0, 34.0); } +float splitPx() { return pardesByLevel(1.5, 2.5, 6.0); } +float dip() { return pardesByLevel(0.08, 0.12, 0.22); } +float tearFrom() { return pardesByLevel(0.8, 0.72, 0.35); } // how few bands tear float hash(vec2 p) { vec3 q = fract(vec3(p.xyx) * 0.1031); @@ -101,27 +112,27 @@ void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 uv = fragCoord / size; // Which burst window this is, when in it the burst starts, and how far // into the burst we are: 0 outside one. - float window = floor(iTime / PERIOD); - float start = window * PERIOD + hash(vec2(window, 7.0)) * (PERIOD - BURST); - float t = (iTime - start) / BURST; + float window = floor(iTime / period()); + float start = window * period() + hash(vec2(window, 7.0)) * (period() - burst()); + float t = (iTime - start) / burst(); float live = step(0.0, t) * step(t, 1.0); float envelope = live * sin(3.14159265 * clamp(t, 0.0, 1.0)); if (envelope <= 0.0) { fragColor = texture(iChannel0, uv); return; } - // Bands of 6 to 40 px, re-cut at STEP_HZ during the burst; about one + // Bands of 6 to 40 px, re-cut at stepHz() during the burst; about one // band in four tears. - float tick = floor(iTime * STEP_HZ); + float tick = floor(iTime * stepHz()); float band_px = mix(6.0, 40.0, hash(vec2(tick, 3.0))); float band = floor(fragCoord.y / band_px); float roll = hash(vec2(band, tick)); - float tear = smoothstep(0.72, 0.9, roll) * envelope; - float shift = (hash(vec2(tick, band + 11.0)) - 0.5) * 2.0 * SHIFT_PX * tear; + float tear = smoothstep(tearFrom(), tearFrom() + 0.18, roll) * envelope; + float shift = (hash(vec2(tick, band + 11.0)) - 0.5) * 2.0 * shiftPx() * tear; vec2 at = vec2(fragCoord.x + shift, fragCoord.y); - vec2 split = vec2(SPLIT_PX * tear, 0.0); + vec2 split = vec2(splitPx() * tear, 0.0); vec4 center = texture(iChannel0, at / size); vec3 col = vec3(texture(iChannel0, (at + split) / size).r, center.g, texture(iChannel0, (at - split) / size).b); - col = toSrgb(toLinear(col) * (1.0 - DIP * tear)); + col = toSrgb(toLinear(col) * (1.0 - dip() * tear)); fragColor = vec4(col, center.a); } |
