summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-28 16:30:57 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:15 -0300
commit1ed34e1538f45daecc2c8a551dc0fb7aba5f3f54 (patch)
treeeddcf21a1e5b35f7871b521c747e851b1134f512
parentbe09d1ec7abd71f4e52f05942a941d76b6d420f2 (diff)
downloadpardes-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/*.
-rw-r--r--docs/render-pipeline.md8
-rw-r--r--shaders/post/crt.glsl40
-rw-r--r--shaders/post/glitch.glsl36
-rw-r--r--shaders/post/prefix.glsl11
-rw-r--r--shaders/post/ripple.glsl23
-rw-r--r--shaders/prebuilt/post-crt.frag.glsl51
-rw-r--r--shaders/prebuilt/post-crt.frag.spvbin9480 -> 12424 bytes
-rw-r--r--shaders/prebuilt/post-glitch.frag.glsl47
-rw-r--r--shaders/prebuilt/post-glitch.frag.spvbin8308 -> 10764 bytes
-rw-r--r--shaders/prebuilt/post-ripple.frag.glsl34
-rw-r--r--shaders/prebuilt/post-ripple.frag.spvbin7180 -> 9096 bytes
-rw-r--r--src/config.zig75
-rw-r--r--src/gui/Post.zig6
-rw-r--r--src/ninep/ctl.zig2
-rw-r--r--test/output.zig3
15 files changed, 227 insertions, 109 deletions
diff --git a/docs/render-pipeline.md b/docs/render-pipeline.md
index d991a1ce..2fd6045b 100644
--- a/docs/render-pipeline.md
+++ b/docs/render-pipeline.md
@@ -507,7 +507,13 @@ Mirror ghostty 1.3.2 (`zig-pkg/ghostty-*/src/renderer/shadertoy.zig`,
the shell redraws its retained Surface (3.1), never a core tick or render.
- **Existing crt/ripple/glitch** become bundled Shadertoy files in
`shaders/post/` selected by the same builtins (decision 2: kept, polished);
- `scene_effects` and `crt.frag.glsl`/`crt.zig` are deleted. The chain is
+ `scene_effects` and `crt.frag.glsl`/`crt.zig` are deleted. Each bundled pass
+ takes a level, `Crt 0..3` (0 off, `on` the default 2, `off` and bare still
+ work), passed as `pardesLevel`: 2 is the polished rewrite, 3 at least as
+ strong as the old effects (pixels changed by more than 8 in a channel,
+ against a plain frame: Crt 18.3% vs 17.4% old, Ripple 11.1% vs 9.5%, Glitch
+ 9.3% a frame vs 8.1%); a Glitch level raises how often it slips as well as
+ how hard. The chain is
`Crt`, `Ripple`, `Glitch` and `Shader <path>` in the order they were put in
(`Shader off` empties it of files), `ShaderAnimation off|on|always`
(default on). The core keeps no clock for it: level A redraws are the
diff --git a/shaders/post/crt.glsl b/shaders/post/crt.glsl
index 16a5cdd9..768157ef 100644
--- a/shaders/post/crt.glsl
+++ b/shaders/post/crt.glsl
@@ -7,19 +7,23 @@
// Shadertoy file: pardes puts its prefix before it (shaders/post/prefix.glsl).
const float TAU = 6.28318530718;
-const float CHROMA_PX = 0.35; // red and blue apart, at the corners
-const float BLOOM_RADIUS_PX = 1.75;
-const float BLOOM_THRESHOLD = 0.60; // linear-light channel peak
+// Level 3 glows wider and from dimmer ink.
+float bloomRadiusPx() { return pardesByLevel(1.75, 1.75, 3.0); }
+float bloomThreshold() { return pardesByLevel(0.6, 0.6, 0.3); } // linear-light channel peak
const float BLOOM_SOFTNESS = 0.25;
-const float BLOOM_STRENGTH = 0.05;
const float SCAN_PERIOD_PX = 3.0;
-const float SCAN_STRENGTH = 0.07;
const float MASK_PERIOD_PX = 3.0;
-const float MASK_STRENGTH = 0.018;
-const float VIGNETTE_STRENGTH = 0.12; // at the far corners only
-const float HUM_STRENGTH = 0.004;
const float HUM_HZ = 0.11;
-const float EXPOSURE = 1.015;
+
+// Each strength at levels 1, 2 and 3 (`Crt 1`..`Crt 3`): 2 is the default,
+// 3 as strong as the old barrel CRT looked.
+float chromaPx() { return pardesByLevel(0.2, 0.35, 2.2); } // red and blue apart, at the corners
+float bloomStrength() { return pardesByLevel(0.03, 0.05, 0.3); }
+float scanStrength() { return pardesByLevel(0.035, 0.07, 0.42); }
+float maskStrength() { return pardesByLevel(0.01, 0.018, 0.12); }
+float vignetteStrength() { return pardesByLevel(0.06, 0.12, 0.42); } // at the far corners only
+float humStrength() { return pardesByLevel(0.002, 0.004, 0.012); }
+float exposure() { return pardesByLevel(1.008, 1.015, 1.1); }
vec3 toLinear(vec3 c) {
return mix(pow((c + 0.055) / 1.055, vec3(2.4)), c / 12.92, lessThanEqual(c, vec3(0.04045)));
@@ -37,7 +41,7 @@ vec3 scene(vec2 uv) {
vec3 brightPass(vec2 uv) {
vec3 c = scene(uv);
float peak = max(c.r, max(c.g, c.b));
- return c * smoothstep(BLOOM_THRESHOLD, BLOOM_THRESHOLD + BLOOM_SOFTNESS, peak);
+ return c * smoothstep(bloomThreshold(), bloomThreshold() + BLOOM_SOFTNESS, peak);
}
// Interleaved gradient noise: a dither with no visible pattern.
@@ -54,24 +58,24 @@ void mainImage(out vec4 fragColor, in vec2 fragCoord) {
// The beam converges least at the corners: red and blue drift apart
// there, by a third of a pixel.
- vec2 chroma = cc * (CHROMA_PX * r2 * 0.5) * texel;
+ vec2 chroma = cc * (chromaPx() * r2 * 0.5) * texel;
vec3 col = vec3(scene(uv + chroma).r, scene(uv).g, scene(uv - chroma).b);
- vec2 b = texel * BLOOM_RADIUS_PX;
+ vec2 b = texel * bloomRadiusPx();
vec3 bloom = brightPass(uv + vec2(b.x, 0.0)) + brightPass(uv - vec2(b.x, 0.0)) +
brightPass(uv + vec2(0.0, b.y)) + brightPass(uv - vec2(0.0, b.y));
- col += bloom * (0.25 * BLOOM_STRENGTH);
+ col += bloom * (0.25 * bloomStrength());
// A beam is brightest on its line and falls off between lines; the
// mask is three phosphor stripes a triad. Both average to one, so the
// theme keeps its brightness.
float line = 0.5 + 0.5 * cos(fragCoord.y * TAU / SCAN_PERIOD_PX);
- col *= 1.0 - SCAN_STRENGTH * (line * line - 0.375) / 0.625;
- col *= 1.0 + MASK_STRENGTH * cos(fragCoord.x * TAU / MASK_PERIOD_PX + vec3(0.0, TAU / 3.0, 2.0 * TAU / 3.0));
+ col *= 1.0 - scanStrength() * (line * line - 0.375) / 0.625;
+ col *= 1.0 + maskStrength() * cos(fragCoord.x * TAU / MASK_PERIOD_PX + vec3(0.0, TAU / 3.0, 2.0 * TAU / 3.0));
- float vignette = 1.0 - VIGNETTE_STRENGTH * pow(clamp(r2 * 0.5, 0.0, 1.0), 1.6);
- float hum = 1.0 + HUM_STRENGTH * sin((uv.y * 1.35 - iTime * HUM_HZ) * TAU);
- col *= vignette * hum * EXPOSURE;
+ float vignette = 1.0 - vignetteStrength() * pow(clamp(r2 * 0.5, 0.0, 1.0), 1.6);
+ float hum = 1.0 + humStrength() * sin((uv.y * 1.35 - iTime * HUM_HZ) * TAU);
+ col *= vignette * hum * exposure();
vec3 srgb = toSrgb(col);
srgb += (ign(fragCoord + float(iFrame % 64) * vec2(5.588238, 5.588238)) - 0.5) / 255.0;
diff --git a/shaders/post/glitch.glsl b/shaders/post/glitch.glsl
index ff9ebcb8..8f420d9c 100644
--- a/shaders/post/glitch.glsl
+++ b/shaders/post/glitch.glsl
@@ -1,4 +1,5 @@
-// 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,
@@ -7,12 +8,15 @@
// 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);
@@ -34,27 +38,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);
}
diff --git a/shaders/post/prefix.glsl b/shaders/post/prefix.glsl
index efa49483..e718a98f 100644
--- a/shaders/post/prefix.glsl
+++ b/shaders/post/prefix.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
diff --git a/shaders/post/ripple.glsl b/shaders/post/ripple.glsl
index ffecbf70..3236d339 100644
--- a/shaders/post/ripple.glsl
+++ b/shaders/post/ripple.glsl
@@ -1,18 +1,21 @@
// Ripple: the page as a still pool a slow swell crosses. Rings travel out
// from the middle of the window at a fixed speed in pixels, so they look
-// the same at any size and frame rate; the displacement is at most a couple
-// of pixels, so text stays readable, and it eases in over its first half
+// the same at any size and frame rate; at the default level the displacement
+// is at most a couple of pixels, so text stays readable, and it eases in over its first half
// second instead of snapping on. Each ring catches the light a little on its
// rising side, in linear light, and the result is dithered so the shading
// never bands. It is a Shadertoy file: pardes puts its prefix before it.
const float TAU = 6.28318530718;
-const float WAVELENGTH_PX = 150.0;
-const float SPEED_PX = 55.0; // outward, per second
-const float AMPLITUDE_PX = 2.2;
-const float SHADE = 0.035; // light on a slope, linear
const float EASE_IN = 0.5; // seconds
+// Each at levels 1, 2 and 3 (`Ripple 1`..`Ripple 3`); 2 is the default.
+float wavelengthPx() { return pardesByLevel(170.0, 150.0, 120.0); }
+float speedPx() { return pardesByLevel(40.0, 55.0, 80.0); } // outward, per second
+float amplitudePx() { return pardesByLevel(1.2, 2.2, 5.0); }
+float shade() { return pardesByLevel(0.02, 0.035, 0.09); } // light on a slope, linear
+float reachEnd() { return pardesByLevel(0.85, 0.95, 1.3); } // how far out it dies away
+
vec3 toLinear(vec3 c) {
return mix(pow((c + 0.055) / 1.055, vec3(2.4)), c / 12.92, lessThanEqual(c, vec3(0.04045)));
}
@@ -34,16 +37,16 @@ void mainImage(out vec4 fragColor, in vec2 fragCoord) {
float reach = 0.5 * length(size);
// Strongest a third of the way out, fading to nothing at the middle
// and at the edges, so the window's frame never wobbles.
- float envelope = smoothstep(0.0, 0.18, radius / reach) * (1.0 - smoothstep(0.35, 0.95, radius / reach));
+ float envelope = smoothstep(0.0, 0.18, radius / reach) * (1.0 - smoothstep(0.35, reachEnd(), radius / reach));
float ease = smoothstep(0.0, EASE_IN, iTime);
- float phase = (radius - iTime * SPEED_PX) * TAU / WAVELENGTH_PX;
+ float phase = (radius - iTime * speedPx()) * TAU / wavelengthPx();
float height = sin(phase);
float slope = cos(phase);
vec2 dir = offset / max(radius, 1e-3);
- vec2 moved = fragCoord + dir * height * AMPLITUDE_PX * envelope * ease;
+ vec2 moved = fragCoord + dir * height * amplitudePx() * envelope * ease;
vec4 s = texture(iChannel0, moved / size);
- vec3 col = toLinear(s.rgb) * (1.0 + SHADE * slope * envelope * ease);
+ vec3 col = toLinear(s.rgb) * (1.0 + shade() * slope * envelope * ease);
vec3 srgb = toSrgb(col) + (ign(fragCoord + float(iFrame % 64) * 5.588238) - 0.5) / 255.0;
fragColor = vec4(clamp(srgb, 0.0, 1.0), s.a);
}
diff --git a/shaders/prebuilt/post-crt.frag.glsl b/shaders/prebuilt/post-crt.frag.glsl
index 11b95272..c2cadfa2 100644
--- a/shaders/prebuilt/post-crt.frag.glsl
+++ b/shaders/prebuilt/post-crt.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
@@ -74,19 +81,23 @@ void main() {
// Shadertoy file: pardes puts its prefix before it (shaders/post/prefix.glsl).
const float TAU = 6.28318530718;
-const float CHROMA_PX = 0.35; // red and blue apart, at the corners
-const float BLOOM_RADIUS_PX = 1.75;
-const float BLOOM_THRESHOLD = 0.60; // linear-light channel peak
+// Level 3 glows wider and from dimmer ink.
+float bloomRadiusPx() { return pardesByLevel(1.75, 1.75, 3.0); }
+float bloomThreshold() { return pardesByLevel(0.6, 0.6, 0.3); } // linear-light channel peak
const float BLOOM_SOFTNESS = 0.25;
-const float BLOOM_STRENGTH = 0.05;
const float SCAN_PERIOD_PX = 3.0;
-const float SCAN_STRENGTH = 0.07;
const float MASK_PERIOD_PX = 3.0;
-const float MASK_STRENGTH = 0.018;
-const float VIGNETTE_STRENGTH = 0.12; // at the far corners only
-const float HUM_STRENGTH = 0.004;
const float HUM_HZ = 0.11;
-const float EXPOSURE = 1.015;
+
+// Each strength at levels 1, 2 and 3 (`Crt 1`..`Crt 3`): 2 is the default,
+// 3 as strong as the old barrel CRT looked.
+float chromaPx() { return pardesByLevel(0.2, 0.35, 2.2); } // red and blue apart, at the corners
+float bloomStrength() { return pardesByLevel(0.03, 0.05, 0.3); }
+float scanStrength() { return pardesByLevel(0.035, 0.07, 0.42); }
+float maskStrength() { return pardesByLevel(0.01, 0.018, 0.12); }
+float vignetteStrength() { return pardesByLevel(0.06, 0.12, 0.42); } // at the far corners only
+float humStrength() { return pardesByLevel(0.002, 0.004, 0.012); }
+float exposure() { return pardesByLevel(1.008, 1.015, 1.1); }
vec3 toLinear(vec3 c) {
return mix(pow((c + 0.055) / 1.055, vec3(2.4)), c / 12.92, lessThanEqual(c, vec3(0.04045)));
@@ -104,7 +115,7 @@ vec3 scene(vec2 uv) {
vec3 brightPass(vec2 uv) {
vec3 c = scene(uv);
float peak = max(c.r, max(c.g, c.b));
- return c * smoothstep(BLOOM_THRESHOLD, BLOOM_THRESHOLD + BLOOM_SOFTNESS, peak);
+ return c * smoothstep(bloomThreshold(), bloomThreshold() + BLOOM_SOFTNESS, peak);
}
// Interleaved gradient noise: a dither with no visible pattern.
@@ -121,24 +132,24 @@ void mainImage(out vec4 fragColor, in vec2 fragCoord) {
// The beam converges least at the corners: red and blue drift apart
// there, by a third of a pixel.
- vec2 chroma = cc * (CHROMA_PX * r2 * 0.5) * texel;
+ vec2 chroma = cc * (chromaPx() * r2 * 0.5) * texel;
vec3 col = vec3(scene(uv + chroma).r, scene(uv).g, scene(uv - chroma).b);
- vec2 b = texel * BLOOM_RADIUS_PX;
+ vec2 b = texel * bloomRadiusPx();
vec3 bloom = brightPass(uv + vec2(b.x, 0.0)) + brightPass(uv - vec2(b.x, 0.0)) +
brightPass(uv + vec2(0.0, b.y)) + brightPass(uv - vec2(0.0, b.y));
- col += bloom * (0.25 * BLOOM_STRENGTH);
+ col += bloom * (0.25 * bloomStrength());
// A beam is brightest on its line and falls off between lines; the
// mask is three phosphor stripes a triad. Both average to one, so the
// theme keeps its brightness.
float line = 0.5 + 0.5 * cos(fragCoord.y * TAU / SCAN_PERIOD_PX);
- col *= 1.0 - SCAN_STRENGTH * (line * line - 0.375) / 0.625;
- col *= 1.0 + MASK_STRENGTH * cos(fragCoord.x * TAU / MASK_PERIOD_PX + vec3(0.0, TAU / 3.0, 2.0 * TAU / 3.0));
+ col *= 1.0 - scanStrength() * (line * line - 0.375) / 0.625;
+ col *= 1.0 + maskStrength() * cos(fragCoord.x * TAU / MASK_PERIOD_PX + vec3(0.0, TAU / 3.0, 2.0 * TAU / 3.0));
- float vignette = 1.0 - VIGNETTE_STRENGTH * pow(clamp(r2 * 0.5, 0.0, 1.0), 1.6);
- float hum = 1.0 + HUM_STRENGTH * sin((uv.y * 1.35 - iTime * HUM_HZ) * TAU);
- col *= vignette * hum * EXPOSURE;
+ float vignette = 1.0 - vignetteStrength() * pow(clamp(r2 * 0.5, 0.0, 1.0), 1.6);
+ float hum = 1.0 + humStrength() * sin((uv.y * 1.35 - iTime * HUM_HZ) * TAU);
+ col *= vignette * hum * exposure();
vec3 srgb = toSrgb(col);
srgb += (ign(fragCoord + float(iFrame % 64) * vec2(5.588238, 5.588238)) - 0.5) / 255.0;
diff --git a/shaders/prebuilt/post-crt.frag.spv b/shaders/prebuilt/post-crt.frag.spv
index e4d98138..6599abd9 100644
--- a/shaders/prebuilt/post-crt.frag.spv
+++ b/shaders/prebuilt/post-crt.frag.spv
Binary files differ
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);
}
diff --git a/shaders/prebuilt/post-glitch.frag.spv b/shaders/prebuilt/post-glitch.frag.spv
index 8a224958..619616a8 100644
--- a/shaders/prebuilt/post-glitch.frag.spv
+++ b/shaders/prebuilt/post-glitch.frag.spv
Binary files differ
diff --git a/shaders/prebuilt/post-ripple.frag.glsl b/shaders/prebuilt/post-ripple.frag.glsl
index 28059def..d29a4c22 100644
--- a/shaders/prebuilt/post-ripple.frag.glsl
+++ b/shaders/prebuilt/post-ripple.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
@@ -67,19 +74,22 @@ void main() {
#line 1
// Ripple: the page as a still pool a slow swell crosses. Rings travel out
// from the middle of the window at a fixed speed in pixels, so they look
-// the same at any size and frame rate; the displacement is at most a couple
-// of pixels, so text stays readable, and it eases in over its first half
+// the same at any size and frame rate; at the default level the displacement
+// is at most a couple of pixels, so text stays readable, and it eases in over its first half
// second instead of snapping on. Each ring catches the light a little on its
// rising side, in linear light, and the result is dithered so the shading
// never bands. It is a Shadertoy file: pardes puts its prefix before it.
const float TAU = 6.28318530718;
-const float WAVELENGTH_PX = 150.0;
-const float SPEED_PX = 55.0; // outward, per second
-const float AMPLITUDE_PX = 2.2;
-const float SHADE = 0.035; // light on a slope, linear
const float EASE_IN = 0.5; // seconds
+// Each at levels 1, 2 and 3 (`Ripple 1`..`Ripple 3`); 2 is the default.
+float wavelengthPx() { return pardesByLevel(170.0, 150.0, 120.0); }
+float speedPx() { return pardesByLevel(40.0, 55.0, 80.0); } // outward, per second
+float amplitudePx() { return pardesByLevel(1.2, 2.2, 5.0); }
+float shade() { return pardesByLevel(0.02, 0.035, 0.09); } // light on a slope, linear
+float reachEnd() { return pardesByLevel(0.85, 0.95, 1.3); } // how far out it dies away
+
vec3 toLinear(vec3 c) {
return mix(pow((c + 0.055) / 1.055, vec3(2.4)), c / 12.92, lessThanEqual(c, vec3(0.04045)));
}
@@ -101,16 +111,16 @@ void mainImage(out vec4 fragColor, in vec2 fragCoord) {
float reach = 0.5 * length(size);
// Strongest a third of the way out, fading to nothing at the middle
// and at the edges, so the window's frame never wobbles.
- float envelope = smoothstep(0.0, 0.18, radius / reach) * (1.0 - smoothstep(0.35, 0.95, radius / reach));
+ float envelope = smoothstep(0.0, 0.18, radius / reach) * (1.0 - smoothstep(0.35, reachEnd(), radius / reach));
float ease = smoothstep(0.0, EASE_IN, iTime);
- float phase = (radius - iTime * SPEED_PX) * TAU / WAVELENGTH_PX;
+ float phase = (radius - iTime * speedPx()) * TAU / wavelengthPx();
float height = sin(phase);
float slope = cos(phase);
vec2 dir = offset / max(radius, 1e-3);
- vec2 moved = fragCoord + dir * height * AMPLITUDE_PX * envelope * ease;
+ vec2 moved = fragCoord + dir * height * amplitudePx() * envelope * ease;
vec4 s = texture(iChannel0, moved / size);
- vec3 col = toLinear(s.rgb) * (1.0 + SHADE * slope * envelope * ease);
+ vec3 col = toLinear(s.rgb) * (1.0 + shade() * slope * envelope * ease);
vec3 srgb = toSrgb(col) + (ign(fragCoord + float(iFrame % 64) * 5.588238) - 0.5) / 255.0;
fragColor = vec4(clamp(srgb, 0.0, 1.0), s.a);
}
diff --git a/shaders/prebuilt/post-ripple.frag.spv b/shaders/prebuilt/post-ripple.frag.spv
index 1a105a33..5f05f9f3 100644
--- a/shaders/prebuilt/post-ripple.frag.spv
+++ b/shaders/prebuilt/post-ripple.frag.spv
Binary files differ
diff --git a/src/config.zig b/src/config.zig
index 1d4043ab..e8c5a705 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -628,7 +628,12 @@ pub const Runtime = struct {
pub const Entry = struct {
scene: ?Scene = null,
path: Text(limits.host_path_cap) = .{},
+ /// A bundled pass's strength, 1 to `max_level`; 0 for a file.
+ level: u8 = 0,
};
+ pub const max_level = 3;
+ /// What `on` and a bare word turn a bundled pass on at.
+ pub const default_level = 2;
entries: [max]Entry = @splat(.{}),
len: u8 = 0,
/// Bumped on every change: a shell compiles the chain again when it
@@ -640,8 +645,28 @@ pub const Runtime = struct {
}
pub fn has(post: *const Post, scene: Scene) bool {
- for (post.list()) |entry| if (entry.scene == scene) return true;
- return false;
+ return post.level(scene) != 0;
+ }
+
+ /// A bundled pass's level; 0 when it is not in the chain.
+ pub fn level(post: *const Post, scene: Scene) u8 {
+ for (post.list()) |entry| if (entry.scene == scene) return entry.level;
+ return 0;
+ }
+
+ /// Sets a bundled pass's level: 0 takes it out, anything else puts it
+ /// in at the end or changes it where it is.
+ pub fn setLevel(post: *Post, scene: Scene, to: u8) bool {
+ std.debug.assert(to <= max_level);
+ if (to == 0) return post.set(scene, "", false);
+ for (post.entries[0..post.len]) |*entry| if (entry.scene == scene) {
+ if (entry.level != to) post.generation +%= 1;
+ entry.level = to;
+ return true;
+ };
+ if (!post.set(scene, "", true)) return false;
+ post.entries[post.len - 1].level = to;
+ return true;
}
/// Puts the pass in the chain, at its end, or takes it out; `want`
@@ -949,8 +974,19 @@ pub const Runtime = struct {
}
},
.scene => |effect| {
- const want = switchedTo(argument) catch return false;
- return state.post.set(effect, "", want);
+ // A level, 0 (off) to 3; `on` is the default level, `off` 0,
+ // and bare flips between the two.
+ const text = std.mem.trim(u8, argument orelse "", " \t\r\n");
+ const to: u8 = if (text.len == 0)
+ (if (state.post.has(effect)) 0 else Post.default_level)
+ else if (std.mem.eql(u8, text, "on"))
+ Post.default_level
+ else if (std.mem.eql(u8, text, "off"))
+ 0
+ else
+ std.fmt.parseInt(u8, text, 10) catch return false;
+ if (to > Post.max_level) return false;
+ return state.post.setLevel(effect, to);
},
.shader => {
const path = std.mem.trim(u8, argument orelse return false, " \t\r\n");
@@ -1119,7 +1155,8 @@ pub const Runtime = struct {
try out.print("{s} unsupported\n", .{setting.word});
continue;
}
- try out.print("{s} {s}\n", .{ setting.word, onOff(state.post.has(effect)) });
+ const level = state.post.level(effect);
+ if (level == 0) try out.print("{s} off\n", .{setting.word}) else try out.print("{s} {d}\n", .{ setting.word, level });
},
.shader => {
if (!setting.enabled(context.capabilities)) {
@@ -1246,6 +1283,28 @@ pub const Runtime = struct {
try std.testing.expect(!apply(&state, find("ShaderAnimation").?, "sometimes"));
}
+ test "a bundled pass takes a level: on is the default, 0 and off take it out, and the old words still flip" {
+ var state: Runtime = .{};
+ const crt = find("Crt").?;
+ try std.testing.expect(apply(&state, crt, "on"));
+ try std.testing.expectEqual(@as(u8, Post.default_level), state.post.level(.crt));
+ try std.testing.expect(apply(&state, find("Glitch").?, "1"));
+ const moved = state.post.generation;
+ try std.testing.expect(apply(&state, crt, "3"));
+ try std.testing.expectEqual(@as(u8, 3), state.post.level(.crt));
+ // A new level keeps its place in the chain.
+ try std.testing.expectEqual(Scene.crt, state.post.list()[0].scene.?);
+ try std.testing.expect(state.post.generation != moved);
+ try std.testing.expect(!apply(&state, crt, "4"));
+ try std.testing.expect(!apply(&state, crt, "loud"));
+ try std.testing.expect(apply(&state, crt, "0"));
+ try std.testing.expect(!state.post.has(.crt));
+ try std.testing.expect(apply(&state, crt, null));
+ try std.testing.expectEqual(@as(u8, Post.default_level), state.post.level(.crt));
+ try std.testing.expect(apply(&state, crt, "off"));
+ try std.testing.expectEqual(@as(u8, 0), state.post.level(.crt));
+ }
+
test "tagline size validates before mutating live state" {
const setting = find("TaglineSize").?;
var state: Runtime = .{};
@@ -1412,9 +1471,9 @@ pub const Runtime = struct {
.typewriter => "Panel transition PanelType\n",
},
.scene => |effect| switch (effect) {
- .crt => "Crt on\n",
- .ripple => "Ripple on\n",
- .glitch => "Glitch on\n",
+ .crt => "Crt 2\n",
+ .ripple => "Ripple 2\n",
+ .glitch => "Glitch 2\n",
},
.shader => "Shader ~/crt.glsl\n",
.shader_animation => "ShaderAnimation always\n",
diff --git a/src/gui/Post.zig b/src/gui/Post.zig
index c529efc0..d9d3d53e 100644
--- a/src/gui/Post.zig
+++ b/src/gui/Post.zig
@@ -69,6 +69,8 @@ pub const Uniforms = extern struct {
pub const Pass = struct {
scene: ?Scene = null,
+ /// A bundled pass's strength (pardesLevel); 0 for a file.
+ level: u8 = 0,
/// A user's file, owned; empty for a bundled pass.
path: []u8 = &.{},
pipeline: ?*Pipeline = null,
@@ -117,7 +119,7 @@ pub fn sync(post: *Post, gpa: std.mem.Allocator, io: std.Io, device: *c.SDL_GPUD
for (chain.list(), 0..) |entry, i| {
if (entry.scene) |scene| {
if (post.bundled.get(scene) == null) post.bundled.set(scene, makePipeline(device, format, bundled_spv.get(scene)) catch null);
- next[i] = .{ .scene = scene, .pipeline = post.bundled.get(scene) };
+ next[i] = .{ .scene = scene, .level = entry.level, .pipeline = post.bundled.get(scene) };
continue;
}
// A file already in the chain keeps its pipeline and its path.
@@ -405,7 +407,6 @@ pub fn draw(post: *Post, device: *c.SDL_GPUDevice, cmd: *c.SDL_GPUCommandBuffer,
const day = epoch.getEpochDay().calculateYearDay();
const month = day.calculateMonthDay();
u.date = .{ @floatFromInt(day.year), @floatFromInt(month.month.numeric() - 1), @floatFromInt(month.day_index + 1), @floatFromInt(epoch.getDaySeconds().secs) };
- const own: [4]f32 = .{ @floatFromInt(@intFromBool(opaque_window)), 0, 0, 0 };
var input = source;
var index: usize = 0;
@@ -423,6 +424,7 @@ pub fn draw(post: *Post, device: *c.SDL_GPUDevice, cmd: *c.SDL_GPUCommandBuffer,
const binding = c.SDL_GPUTextureSamplerBinding{ .texture = input, .sampler = sampler };
c.SDL_BindGPUFragmentSamplers(pass_rp, 0, &binding, 1);
c.SDL_PushGPUFragmentUniformData(cmd, 0, u, @sizeOf(Uniforms));
+ const own: [4]f32 = .{ @floatFromInt(@intFromBool(opaque_window)), @floatFromInt(pass.level), 0, 0 };
c.SDL_PushGPUFragmentUniformData(cmd, 1, &own, @sizeOf(@TypeOf(own)));
c.SDL_DrawGPUPrimitives(pass_rp, 3, 1, 0, 0);
c.SDL_EndGPURenderPass(pass_rp);
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index ed10dd70..cd327d03 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -263,7 +263,7 @@ fn writeSettings(p: *Pardes, w: *std.Io.Writer) !void {
// Bare, it names the default directory.
.dump_dir => if (s.dump_dir.len > 0) try w.print("{s} {s}\n", .{ word, s.dump_dir.get() }) else try w.print("{s}\n", .{word}),
.transition => |effect| try w.print("{s} {s}\n", .{ word, if (s.panel_transition == effect) "on" else "off" }),
- .scene => |effect| try w.print("{s} {s}\n", .{ word, if (s.post.has(effect)) "on" else "off" }),
+ .scene => |effect| if (s.post.level(effect) == 0) try w.print("{s} off\n", .{word}) else try w.print("{s} {d}\n", .{ word, s.post.level(effect) }),
.shader => for (s.post.list()) |entry| if (entry.scene == null) try w.print("{s} {s}\n", .{ word, entry.path.get() }),
.shader_animation => try w.print("{s} {s}\n", .{ word, @tagName(s.shader_animation) }),
}
diff --git a/test/output.zig b/test/output.zig
index 400e9508..0fdd9f4d 100644
--- a/test/output.zig
+++ b/test/output.zig
@@ -667,7 +667,8 @@ test "every enabled setting builtin mutates the State Config reports" {
else
"Panel transition unsupported\n";
try std.testing.expect(std.mem.indexOf(u8, report, transition) != null);
- const scene_status = if (builtins.capabilities.scene_shaders) "on" else "unsupported";
+ // A bare word turns a bundled pass on at its default level.
+ const scene_status = if (builtins.capabilities.scene_shaders) "2" else "unsupported";
for ([_][]const u8{ "Crt", "Ripple", "Glitch" }) |name| {
const line = try std.fmt.bufPrint(&buf, "{s} {s}\n", .{ name, scene_status });
try std.testing.expect(std.mem.indexOf(u8, report, line) != null);