summaryrefslogtreecommitdiff
path: root/shaders
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-29 07:41:35 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:16 -0300
commit411d0b6059192b75853e220e1242b694ae461a3e (patch)
tree50f8bb207f3cdda497bdd84658a2d3ea74b4bc2b /shaders
parentda920ca49e3f5d1649e811bbdc3ddba482c6aae4 (diff)
parent5526c68beec454cfe607a579723b97b4848e7d3a (diff)
downloadpardes-411d0b6059192b75853e220e1242b694ae461a3e.tar.gz
pardes-411d0b6059192b75853e220e1242b694ae461a3e.zip
Merge: 9P rounds 9-17 + render DPI, dark tints, G4-G10
Diffstat (limited to 'shaders')
-rw-r--r--shaders/bloom-down.frag.glsl39
-rw-r--r--shaders/bloom-up.frag.glsl26
-rw-r--r--shaders/decor.frag.glsl13
-rw-r--r--shaders/post/bloom.glsl40
-rw-r--r--shaders/post/crt.glsl6
-rw-r--r--shaders/post/grain.glsl32
-rw-r--r--shaders/post/prefix.glsl31
-rw-r--r--shaders/post/vignette.glsl38
-rw-r--r--shaders/prebuilt/bloom-down.frag.glsl39
-rw-r--r--shaders/prebuilt/bloom-down.frag.spvbin0 -> 3876 bytes
-rw-r--r--shaders/prebuilt/bloom-up.frag.glsl26
-rw-r--r--shaders/prebuilt/bloom-up.frag.spvbin0 -> 3504 bytes
-rw-r--r--shaders/prebuilt/decor.frag.glsl73
-rw-r--r--shaders/prebuilt/decor.frag.spvbin2100 -> 7852 bytes
-rw-r--r--shaders/prebuilt/post-bloom.frag.glsl141
-rw-r--r--shaders/prebuilt/post-bloom.frag.spvbin0 -> 8500 bytes
-rw-r--r--shaders/prebuilt/post-crt.frag.glsl37
-rw-r--r--shaders/prebuilt/post-crt.frag.spvbin12424 -> 13092 bytes
-rw-r--r--shaders/prebuilt/post-grain.frag.glsl133
-rw-r--r--shaders/prebuilt/post-grain.frag.spvbin0 -> 8236 bytes
-rw-r--r--shaders/prebuilt/post-vignette.frag.glsl139
-rw-r--r--shaders/prebuilt/post-vignette.frag.spvbin0 -> 8652 bytes
-rw-r--r--shaders/prebuilt/ui.frag.glsl49
-rw-r--r--shaders/prebuilt/ui.frag.spvbin5700 -> 8176 bytes
-rw-r--r--shaders/prebuilt/ui.vert.glsl10
-rw-r--r--shaders/prebuilt/ui.vert.spvbin5612 -> 5612 bytes
-rw-r--r--shaders/ui.frag.glsl49
-rw-r--r--shaders/ui.vert.glsl10
28 files changed, 892 insertions, 39 deletions
diff --git a/shaders/bloom-down.frag.glsl b/shaders/bloom-down.frag.glsl
new file mode 100644
index 00000000..3465926d
--- /dev/null
+++ b/shaders/bloom-down.frag.glsl
@@ -0,0 +1,39 @@
+#version 450
+
+// Bloom, down (docs/effects.md G4): one step of a dual Kawase filter, a
+// source half as big again sampled at five points, the first step over the
+// frame through a bright pass in linear light. Written to a float target.
+
+layout(set = 2, binding = 0) uniform sampler2D source;
+layout(std140, set = 3, binding = 0) uniform BloomStep {
+ // xy: a source texel; zw: a target texel.
+ vec4 texels;
+ // x: the bright pass's threshold on a channel's linear peak (above the
+ // page's own), 0 for none (a later step); y: its soft knee.
+ vec4 pass;
+} u;
+
+layout(location = 0) out vec4 o_col;
+
+vec3 toLinear(vec3 c) {
+ return mix(pow((c + 0.055) / 1.055, vec3(2.4)), c / 12.92, lessThanEqual(c, vec3(0.04045)));
+}
+
+vec3 tap(vec2 uv) {
+ vec3 c = texture(source, uv).rgb;
+ if (u.pass.x <= 0.0) return c;
+ c = toLinear(c);
+ float peak = max(c.r, max(c.g, c.b));
+ return c * smoothstep(u.pass.x, u.pass.x + u.pass.y, peak);
+}
+
+void main() {
+ vec2 uv = gl_FragCoord.xy * u.texels.zw;
+ vec2 h = 0.5 * u.texels.xy;
+ vec3 sum = tap(uv) * 4.0;
+ sum += tap(uv - h);
+ sum += tap(uv + h);
+ sum += tap(uv + vec2(h.x, -h.y));
+ sum += tap(uv - vec2(h.x, -h.y));
+ o_col = vec4(sum / 8.0, 1.0);
+}
diff --git a/shaders/bloom-up.frag.glsl b/shaders/bloom-up.frag.glsl
new file mode 100644
index 00000000..368076ed
--- /dev/null
+++ b/shaders/bloom-up.frag.glsl
@@ -0,0 +1,26 @@
+#version 450
+
+// Bloom, up (docs/effects.md G4): one step of a dual Kawase filter back up,
+// a tent of eight points over the smaller level. Float target.
+
+layout(set = 2, binding = 0) uniform sampler2D source;
+layout(std140, set = 3, binding = 0) uniform BloomStep {
+ vec4 texels;
+ vec4 pass;
+} u;
+
+layout(location = 0) out vec4 o_col;
+
+void main() {
+ vec2 uv = gl_FragCoord.xy * u.texels.zw;
+ vec2 h = 0.5 * u.texels.xy;
+ vec3 sum = texture(source, uv + vec2(-2.0 * h.x, 0.0)).rgb;
+ sum += texture(source, uv + vec2(-h.x, h.y)).rgb * 2.0;
+ sum += texture(source, uv + vec2(0.0, 2.0 * h.y)).rgb;
+ sum += texture(source, uv + vec2(h.x, h.y)).rgb * 2.0;
+ sum += texture(source, uv + vec2(2.0 * h.x, 0.0)).rgb;
+ sum += texture(source, uv + vec2(h.x, -h.y)).rgb * 2.0;
+ sum += texture(source, uv + vec2(0.0, -2.0 * h.y)).rgb;
+ sum += texture(source, uv + vec2(-h.x, -h.y)).rgb * 2.0;
+ o_col = vec4(sum / 12.0, 1.0);
+}
diff --git a/shaders/decor.frag.glsl b/shaders/decor.frag.glsl
index 3e2c286f..bb1ef0d6 100644
--- a/shaders/decor.frag.glsl
+++ b/shaders/decor.frag.glsl
@@ -8,6 +8,8 @@
// colour rides in the cell's ground (a_bg), its coverage in a_fg.r, so the
// result is the overlay pipeline's exactly.
//
+// Checker (flag 0x08000000): two colours in squares, or in stripes, see main.
+//
// Soft (flag 0x10000000): a rectangle's shadow, rim or glow 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
@@ -51,6 +53,17 @@ 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;
float opacity = clamp(u_ui.background_opacity, 0.0, 1.0);
+ // Checker (flag 0x08000000): squares of v_uv.x pixels from the quad's
+ // own corner, so it moves with its rail, in the ground's colour and the
+ // ink's (lapis's scroll track).
+ vec2 in_quad = v_cell_uv / max(vec2(dFdx(v_cell_uv.x), dFdy(v_cell_uv.y)), vec2(1e-6));
+ if ((v_effect.x & 0x08000000u) != 0u) {
+ ivec2 q = ivec2(floor(in_quad / max(v_uv.x, 1.0)));
+ // v_uv.y set: stripes across the quad (lapis's title bar), not squares.
+ int k = v_uv.y > 0.5 ? q.y : q.x + q.y;
+ o_col = vec4(((k & 1) == 0 ? v_bg : v_fg) * opacity, 1.0);
+ return;
+ }
if ((v_effect.x & 0x10000000u) == 0u) {
o_col = vec4(v_bg * opacity, v_fg.r);
return;
diff --git a/shaders/post/bloom.glsl b/shaders/post/bloom.glsl
new file mode 100644
index 00000000..d54a0aac
--- /dev/null
+++ b/shaders/post/bloom.glsl
@@ -0,0 +1,40 @@
+// Bloom: the brightest ink glows, a little. The glow itself is made by the
+// shell at half resolution and below (bloom-down, bloom-up: a dual Kawase
+// filter over a bright pass, in linear light) and arrives here in
+// pardesBloom; this pass adds it to the frame. Only true highlights pass
+// the threshold, and the strength stays in §8.2's budget (at most 5%) and
+// under pardesCap, so no text or selection loses contrast below its own or
+// 4.5. Tags, grips, notices and the cursor are left alone (pardesSpare).
+// It is a Shadertoy file: pardes puts its prefix before it.
+
+layout(set = 2, binding = 1) uniform sampler2D pardesBloom;
+
+float strength() { return min(pardesByLevel(0.02, 0.035, 0.05), pardesCap); }
+
+vec3 toLinear(vec3 c) {
+ return mix(pow((c + 0.055) / 1.055, vec3(2.4)), c / 12.92, lessThanEqual(c, vec3(0.04045)));
+}
+
+vec3 toSrgb(vec3 c) {
+ c = max(c, vec3(0.0));
+ return mix(1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055, c * 12.92, lessThanEqual(c, vec3(0.0031308)));
+}
+
+float ign(vec2 p) {
+ return fract(52.9829189 * fract(dot(p, vec2(0.06711056, 0.00583715))));
+}
+
+void mainImage(out vec4 fragColor, in vec2 fragCoord) {
+ vec2 uv = fragCoord / iResolution.xy;
+ vec4 frame = texture(iChannel0, uv);
+ if (pardesSpared(fragCoord)) {
+ fragColor = frame;
+ return;
+ }
+ vec3 glow = texture(pardesBloom, uv).rgb;
+ vec3 col = toLinear(frame.rgb) + glow * strength();
+ vec3 srgb = toSrgb(col);
+ // Dithered: a glow's long falloff never bands.
+ srgb += (ign(fragCoord) - 0.5) / 255.0 * step(1e-4, dot(glow, vec3(1.0)));
+ fragColor = vec4(clamp(srgb, 0.0, 1.0), frame.a);
+}
diff --git a/shaders/post/crt.glsl b/shaders/post/crt.glsl
index 768157ef..970d61ee 100644
--- a/shaders/post/crt.glsl
+++ b/shaders/post/crt.glsl
@@ -69,9 +69,11 @@ void mainImage(out vec4 fragColor, in vec2 fragCoord) {
// 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);
+ // Periods in logical pixels: the same look at any density.
+ float density = max(1.0, pardesScale);
+ float line = 0.5 + 0.5 * cos(fragCoord.y * TAU / (SCAN_PERIOD_PX * density));
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));
+ col *= 1.0 + maskStrength() * cos(fragCoord.x * TAU / (MASK_PERIOD_PX * density) + vec3(0.0, TAU / 3.0, 2.0 * TAU / 3.0));
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);
diff --git a/shaders/post/grain.glsl b/shaders/post/grain.glsl
new file mode 100644
index 00000000..61c51492
--- /dev/null
+++ b/shaders/post/grain.glsl
@@ -0,0 +1,32 @@
+// Grain: the page's own ground takes a fine, still grain, like paper. Only
+// pixels of the page's colour (iBackgroundColor) are grained: no glyph, no
+// selection, no tag or rule, and nothing in pardesSpare. The grain averages
+// to the page, is a logical pixel big (pardesScale), and never moves, so it
+// costs no frames. At most 1.5, 3 and 5 of 255 at levels 1 to 3, and never
+// more than pardesCap, which keeps the text on it at its own contrast or 4.5.
+// It is a Shadertoy file: pardes puts its prefix before it.
+
+float amplitude() { return min(pardesByLevel(1.5, 3.0, 5.0) / 255.0, pardesCap); }
+
+// An integer hash of the grain cell: white, with no pattern to see.
+float hash(uvec2 p) {
+ uint h = p.x * 1664525u + p.y * 1013904223u;
+ h ^= h >> 16;
+ h *= 2246822519u;
+ h ^= h >> 13;
+ h *= 3266489917u;
+ h ^= h >> 16;
+ return float(h) / 4294967295.0;
+}
+
+void mainImage(out vec4 fragColor, in vec2 fragCoord) {
+ vec2 uv = fragCoord / iResolution.xy;
+ vec4 frame = texture(iChannel0, uv);
+ fragColor = frame;
+ vec3 page = iBackgroundColor.rgb;
+ if (any(greaterThan(abs(frame.rgb - page), vec3(0.75 / 255.0))) || pardesSpared(fragCoord)) return;
+ uvec2 cell = uvec2(fragCoord / max(1.0, pardesScale));
+ // Two hashes summed: a triangular spread, softer than a flat one.
+ float n = hash(cell) + hash(cell + uvec2(7919u, 104729u)) - 1.0;
+ fragColor = vec4(clamp(page + n * amplitude(), 0.0, 1.0), frame.a);
+}
diff --git a/shaders/post/prefix.glsl b/shaders/post/prefix.glsl
index e718a98f..44c5e0f8 100644
--- a/shaders/post/prefix.glsl
+++ b/shaders/post/prefix.glsl
@@ -30,7 +30,14 @@ layout(set = 3, binding = 0, std140) uniform Globals {
uniform float iTimeCursorChange;
uniform float iTimeFocus;
uniform int iFocus;
+};
+// ghostty's one block, cut in three: SDL GPU binds at most 4 KiB of a
+// uniform block (Vulkan), and the palette alone is 4 KiB. The names and
+// their order are ghostty's; each block is a slice of the same memory.
+layout(set = 3, binding = 1, std140) uniform Palette {
uniform vec3 iPalette[256];
+};
+layout(set = 3, binding = 2, std140) uniform Colors {
uniform vec3 iBackgroundColor;
uniform vec3 iForegroundColor;
uniform vec3 iCursorColor;
@@ -41,12 +48,32 @@ layout(set = 3, binding = 0, std140) uniform Globals {
// 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 {
+// pass's strength, 1 to 3 (`Crt 3`), and 0 for a user's file; pardesScale
+// is the display's density (2 on a 2x screen), for a pass whose pattern is
+// in logical pixels. iResolution, fragCoord and iMouse stay in the display's
+// pixels, as ghostty's do. pardesCap is the most a bundled pass may do on
+// this theme and still leave its text, and its selection's, at their own
+// contrast or 4.5 (docs/effects.md); pardesSpare holds pardesSpareCount
+// rectangles (x0, y0, x1, y1 in fragCoord's pixels) a bundled pass leaves
+// alone: every tag, grip and notice, and the cursor, so no pass ever touches
+// a focus indicator.
+layout(set = 3, binding = 3, std140) uniform PardesPost {
float pardesOpaque;
float pardesLevel;
+ float pardesScale;
+ float pardesCap;
+ float pardesSpareCount;
+ vec4 pardesSpare[32];
};
+bool pardesSpared(vec2 p) {
+ for (int i = 0; i < int(pardesSpareCount); i++) {
+ vec4 r = pardesSpare[i];
+ if (p.x >= r.x && p.y >= r.y && p.x < r.z && p.y < r.w) return true;
+ }
+ return false;
+}
+
// 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);
diff --git a/shaders/post/vignette.glsl b/shaders/post/vignette.glsl
new file mode 100644
index 00000000..30dc2e0f
--- /dev/null
+++ b/shaders/post/vignette.glsl
@@ -0,0 +1,38 @@
+// Vignette: the window's corners fall a little into shade, in linear light,
+// so the eye settles on the middle. Round, whatever the window's shape;
+// nothing within half the way to a corner is touched. At most 28% at the
+// far corners (level 3), and never more than pardesCap, so text and its
+// selection keep their own contrast or 4.5. Tags, grips, notices and the
+// cursor are left alone (pardesSpare): the focus indicators never darken.
+// It is a Shadertoy file: pardes puts its prefix before it.
+
+float strength() { return min(pardesByLevel(0.10, 0.18, 0.28), pardesCap); }
+
+vec3 toLinear(vec3 c) {
+ return mix(pow((c + 0.055) / 1.055, vec3(2.4)), c / 12.92, lessThanEqual(c, vec3(0.04045)));
+}
+
+vec3 toSrgb(vec3 c) {
+ c = max(c, vec3(0.0));
+ return mix(1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055, c * 12.92, lessThanEqual(c, vec3(0.0031308)));
+}
+
+float ign(vec2 p) {
+ return fract(52.9829189 * fract(dot(p, vec2(0.06711056, 0.00583715))));
+}
+
+void mainImage(out vec4 fragColor, in vec2 fragCoord) {
+ vec2 uv = fragCoord / iResolution.xy;
+ vec4 frame = texture(iChannel0, uv);
+ if (pardesSpared(fragCoord)) {
+ fragColor = frame;
+ return;
+ }
+ // 0 at the middle, 1 at a corner, on a circle's measure.
+ vec2 half_size = 0.5 * iResolution.xy;
+ float r = length(fragCoord - half_size) / length(half_size);
+ float shade = strength() * pow(smoothstep(0.5, 1.0, r), 1.5);
+ vec3 srgb = toSrgb(toLinear(frame.rgb) * (1.0 - shade));
+ srgb += (ign(fragCoord) - 0.5) / 255.0 * step(1e-4, shade);
+ fragColor = vec4(clamp(srgb, 0.0, 1.0), frame.a);
+}
diff --git a/shaders/prebuilt/bloom-down.frag.glsl b/shaders/prebuilt/bloom-down.frag.glsl
new file mode 100644
index 00000000..3465926d
--- /dev/null
+++ b/shaders/prebuilt/bloom-down.frag.glsl
@@ -0,0 +1,39 @@
+#version 450
+
+// Bloom, down (docs/effects.md G4): one step of a dual Kawase filter, a
+// source half as big again sampled at five points, the first step over the
+// frame through a bright pass in linear light. Written to a float target.
+
+layout(set = 2, binding = 0) uniform sampler2D source;
+layout(std140, set = 3, binding = 0) uniform BloomStep {
+ // xy: a source texel; zw: a target texel.
+ vec4 texels;
+ // x: the bright pass's threshold on a channel's linear peak (above the
+ // page's own), 0 for none (a later step); y: its soft knee.
+ vec4 pass;
+} u;
+
+layout(location = 0) out vec4 o_col;
+
+vec3 toLinear(vec3 c) {
+ return mix(pow((c + 0.055) / 1.055, vec3(2.4)), c / 12.92, lessThanEqual(c, vec3(0.04045)));
+}
+
+vec3 tap(vec2 uv) {
+ vec3 c = texture(source, uv).rgb;
+ if (u.pass.x <= 0.0) return c;
+ c = toLinear(c);
+ float peak = max(c.r, max(c.g, c.b));
+ return c * smoothstep(u.pass.x, u.pass.x + u.pass.y, peak);
+}
+
+void main() {
+ vec2 uv = gl_FragCoord.xy * u.texels.zw;
+ vec2 h = 0.5 * u.texels.xy;
+ vec3 sum = tap(uv) * 4.0;
+ sum += tap(uv - h);
+ sum += tap(uv + h);
+ sum += tap(uv + vec2(h.x, -h.y));
+ sum += tap(uv - vec2(h.x, -h.y));
+ o_col = vec4(sum / 8.0, 1.0);
+}
diff --git a/shaders/prebuilt/bloom-down.frag.spv b/shaders/prebuilt/bloom-down.frag.spv
new file mode 100644
index 00000000..5ca327fe
--- /dev/null
+++ b/shaders/prebuilt/bloom-down.frag.spv
Binary files differ
diff --git a/shaders/prebuilt/bloom-up.frag.glsl b/shaders/prebuilt/bloom-up.frag.glsl
new file mode 100644
index 00000000..368076ed
--- /dev/null
+++ b/shaders/prebuilt/bloom-up.frag.glsl
@@ -0,0 +1,26 @@
+#version 450
+
+// Bloom, up (docs/effects.md G4): one step of a dual Kawase filter back up,
+// a tent of eight points over the smaller level. Float target.
+
+layout(set = 2, binding = 0) uniform sampler2D source;
+layout(std140, set = 3, binding = 0) uniform BloomStep {
+ vec4 texels;
+ vec4 pass;
+} u;
+
+layout(location = 0) out vec4 o_col;
+
+void main() {
+ vec2 uv = gl_FragCoord.xy * u.texels.zw;
+ vec2 h = 0.5 * u.texels.xy;
+ vec3 sum = texture(source, uv + vec2(-2.0 * h.x, 0.0)).rgb;
+ sum += texture(source, uv + vec2(-h.x, h.y)).rgb * 2.0;
+ sum += texture(source, uv + vec2(0.0, 2.0 * h.y)).rgb;
+ sum += texture(source, uv + vec2(h.x, h.y)).rgb * 2.0;
+ sum += texture(source, uv + vec2(2.0 * h.x, 0.0)).rgb;
+ sum += texture(source, uv + vec2(h.x, -h.y)).rgb * 2.0;
+ sum += texture(source, uv + vec2(0.0, -2.0 * h.y)).rgb;
+ sum += texture(source, uv + vec2(-h.x, -h.y)).rgb * 2.0;
+ o_col = vec4(sum / 12.0, 1.0);
+}
diff --git a/shaders/prebuilt/bloom-up.frag.spv b/shaders/prebuilt/bloom-up.frag.spv
new file mode 100644
index 00000000..b2c64b80
--- /dev/null
+++ b/shaders/prebuilt/bloom-up.frag.spv
Binary files differ
diff --git a/shaders/prebuilt/decor.frag.glsl b/shaders/prebuilt/decor.frag.glsl
index 4c2bd6d8..bb1ef0d6 100644
--- a/shaders/prebuilt/decor.frag.glsl
+++ b/shaders/prebuilt/decor.frag.glsl
@@ -1,24 +1,83 @@
#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.
+//
+// Checker (flag 0x08000000): two colours in squares, or in stripes, see main.
+//
+// Soft (flag 0x10000000): a rectangle's shadow, rim or glow 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);
+ // Checker (flag 0x08000000): squares of v_uv.x pixels from the quad's
+ // own corner, so it moves with its rail, in the ground's colour and the
+ // ink's (lapis's scroll track).
+ vec2 in_quad = v_cell_uv / max(vec2(dFdx(v_cell_uv.x), dFdy(v_cell_uv.y)), vec2(1e-6));
+ if ((v_effect.x & 0x08000000u) != 0u) {
+ ivec2 q = ivec2(floor(in_quad / max(v_uv.x, 1.0)));
+ // v_uv.y set: stripes across the quad (lapis's title bar), not squares.
+ int k = v_uv.y > 0.5 ? q.y : q.x + q.y;
+ o_col = vec4(((k & 1) == 0 ? v_bg : v_fg) * opacity, 1.0);
+ return;
+ }
+ 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);
+ // Black darkens in linear light; a light colour (a rim, a glow) is laid
+ // on as it is, within §8.2's 25%.
+ if (all(equal(v_bg, vec3(0.0)))) 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);
}
diff --git a/shaders/prebuilt/decor.frag.spv b/shaders/prebuilt/decor.frag.spv
index 7e162f5a..bd565d03 100644
--- a/shaders/prebuilt/decor.frag.spv
+++ b/shaders/prebuilt/decor.frag.spv
Binary files differ
diff --git a/shaders/prebuilt/post-bloom.frag.glsl b/shaders/prebuilt/post-bloom.frag.glsl
new file mode 100644
index 00000000..a84cf88a
--- /dev/null
+++ b/shaders/prebuilt/post-bloom.frag.glsl
@@ -0,0 +1,141 @@
+#version 450
+// pardes's Shadertoy prefix (docs/render-pipeline.md §6), put before every
+// post pass: a bundled one in shaders/post/ at build time, a user's file at
+// run time. The uniform names, types and std140 order are ghostty 1.3.2's
+// (src/renderer/shaders/shadertoy_prefix.glsl), so a shader written for
+// ghostty runs here; only the bindings are SDL GPU's (a fragment shader's
+// textures in set 2, its uniform blocks in set 3). Y is down everywhere, as
+// on ghostty's Metal renderer: fragCoord, iChannel0's uv and the cursor
+// rectangles share one top-left space, and iCurrentCursor is (left x,
+// BOTTOM-edge y, width, height) in framebuffer pixels.
+
+layout(set = 3, binding = 0, std140) uniform Globals {
+ uniform vec3 iResolution;
+ uniform float iTime;
+ uniform float iTimeDelta;
+ uniform float iFrameRate;
+ uniform int iFrame;
+ uniform float iChannelTime[4];
+ uniform vec3 iChannelResolution[4];
+ uniform vec4 iMouse;
+ uniform vec4 iDate;
+ uniform float iSampleRate;
+ uniform vec4 iCurrentCursor;
+ uniform vec4 iPreviousCursor;
+ uniform vec4 iCurrentCursorColor;
+ uniform vec4 iPreviousCursorColor;
+ uniform int iCurrentCursorStyle;
+ uniform int iPreviousCursorStyle;
+ uniform int iCursorVisible;
+ uniform float iTimeCursorChange;
+ uniform float iTimeFocus;
+ uniform int iFocus;
+};
+// ghostty's one block, cut in three: SDL GPU binds at most 4 KiB of a
+// uniform block (Vulkan), and the palette alone is 4 KiB. The names and
+// their order are ghostty's; each block is a slice of the same memory.
+layout(set = 3, binding = 1, std140) uniform Palette {
+ uniform vec3 iPalette[256];
+};
+layout(set = 3, binding = 2, std140) uniform Colors {
+ uniform vec3 iBackgroundColor;
+ uniform vec3 iForegroundColor;
+ uniform vec3 iCursorColor;
+ uniform vec3 iCursorText;
+ uniform vec3 iSelectionForegroundColor;
+ uniform vec3 iSelectionBackgroundColor;
+};
+
+// 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; pardesScale
+// is the display's density (2 on a 2x screen), for a pass whose pattern is
+// in logical pixels. iResolution, fragCoord and iMouse stay in the display's
+// pixels, as ghostty's do. pardesCap is the most a bundled pass may do on
+// this theme and still leave its text, and its selection's, at their own
+// contrast or 4.5 (docs/effects.md); pardesSpare holds pardesSpareCount
+// rectangles (x0, y0, x1, y1 in fragCoord's pixels) a bundled pass leaves
+// alone: every tag, grip and notice, and the cursor, so no pass ever touches
+// a focus indicator.
+layout(set = 3, binding = 3, std140) uniform PardesPost {
+ float pardesOpaque;
+ float pardesLevel;
+ float pardesScale;
+ float pardesCap;
+ float pardesSpareCount;
+ vec4 pardesSpare[32];
+};
+
+bool pardesSpared(vec2 p) {
+ for (int i = 0; i < int(pardesSpareCount); i++) {
+ vec4 r = pardesSpare[i];
+ if (p.x >= r.x && p.y >= r.y && p.x < r.z && p.y < r.w) return true;
+ }
+ return false;
+}
+
+// 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
+#define CURSORSTYLE_UNDERLINE 3
+#define CURSORSTYLE_LOCK 4
+
+layout(set = 2, binding = 0) uniform sampler2D iChannel0;
+
+layout(location = 0) out vec4 _fragColor;
+
+#define texture2D texture
+
+void mainImage(out vec4 fragColor, in vec2 fragCoord);
+void main() {
+ mainImage(_fragColor, gl_FragCoord.xy);
+ if (pardesOpaque > 0.5) _fragColor.a = 1.0;
+}
+
+// The shader's own lines count from 1, so glslc's errors name them.
+#line 1
+// Bloom: the brightest ink glows, a little. The glow itself is made by the
+// shell at half resolution and below (bloom-down, bloom-up: a dual Kawase
+// filter over a bright pass, in linear light) and arrives here in
+// pardesBloom; this pass adds it to the frame. Only true highlights pass
+// the threshold, and the strength stays in §8.2's budget (at most 5%) and
+// under pardesCap, so no text or selection loses contrast below its own or
+// 4.5. Tags, grips, notices and the cursor are left alone (pardesSpare).
+// It is a Shadertoy file: pardes puts its prefix before it.
+
+layout(set = 2, binding = 1) uniform sampler2D pardesBloom;
+
+float strength() { return min(pardesByLevel(0.02, 0.035, 0.05), pardesCap); }
+
+vec3 toLinear(vec3 c) {
+ return mix(pow((c + 0.055) / 1.055, vec3(2.4)), c / 12.92, lessThanEqual(c, vec3(0.04045)));
+}
+
+vec3 toSrgb(vec3 c) {
+ c = max(c, vec3(0.0));
+ return mix(1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055, c * 12.92, lessThanEqual(c, vec3(0.0031308)));
+}
+
+float ign(vec2 p) {
+ return fract(52.9829189 * fract(dot(p, vec2(0.06711056, 0.00583715))));
+}
+
+void mainImage(out vec4 fragColor, in vec2 fragCoord) {
+ vec2 uv = fragCoord / iResolution.xy;
+ vec4 frame = texture(iChannel0, uv);
+ if (pardesSpared(fragCoord)) {
+ fragColor = frame;
+ return;
+ }
+ vec3 glow = texture(pardesBloom, uv).rgb;
+ vec3 col = toLinear(frame.rgb) + glow * strength();
+ vec3 srgb = toSrgb(col);
+ // Dithered: a glow's long falloff never bands.
+ srgb += (ign(fragCoord) - 0.5) / 255.0 * step(1e-4, dot(glow, vec3(1.0)));
+ fragColor = vec4(clamp(srgb, 0.0, 1.0), frame.a);
+}
diff --git a/shaders/prebuilt/post-bloom.frag.spv b/shaders/prebuilt/post-bloom.frag.spv
new file mode 100644
index 00000000..7b71dbdd
--- /dev/null
+++ b/shaders/prebuilt/post-bloom.frag.spv
Binary files differ
diff --git a/shaders/prebuilt/post-crt.frag.glsl b/shaders/prebuilt/post-crt.frag.glsl
index c2cadfa2..ca44d014 100644
--- a/shaders/prebuilt/post-crt.frag.glsl
+++ b/shaders/prebuilt/post-crt.frag.glsl
@@ -30,7 +30,14 @@ layout(set = 3, binding = 0, std140) uniform Globals {
uniform float iTimeCursorChange;
uniform float iTimeFocus;
uniform int iFocus;
+};
+// ghostty's one block, cut in three: SDL GPU binds at most 4 KiB of a
+// uniform block (Vulkan), and the palette alone is 4 KiB. The names and
+// their order are ghostty's; each block is a slice of the same memory.
+layout(set = 3, binding = 1, std140) uniform Palette {
uniform vec3 iPalette[256];
+};
+layout(set = 3, binding = 2, std140) uniform Colors {
uniform vec3 iBackgroundColor;
uniform vec3 iForegroundColor;
uniform vec3 iCursorColor;
@@ -41,12 +48,32 @@ layout(set = 3, binding = 0, std140) uniform Globals {
// 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 {
+// pass's strength, 1 to 3 (`Crt 3`), and 0 for a user's file; pardesScale
+// is the display's density (2 on a 2x screen), for a pass whose pattern is
+// in logical pixels. iResolution, fragCoord and iMouse stay in the display's
+// pixels, as ghostty's do. pardesCap is the most a bundled pass may do on
+// this theme and still leave its text, and its selection's, at their own
+// contrast or 4.5 (docs/effects.md); pardesSpare holds pardesSpareCount
+// rectangles (x0, y0, x1, y1 in fragCoord's pixels) a bundled pass leaves
+// alone: every tag, grip and notice, and the cursor, so no pass ever touches
+// a focus indicator.
+layout(set = 3, binding = 3, std140) uniform PardesPost {
float pardesOpaque;
float pardesLevel;
+ float pardesScale;
+ float pardesCap;
+ float pardesSpareCount;
+ vec4 pardesSpare[32];
};
+bool pardesSpared(vec2 p) {
+ for (int i = 0; i < int(pardesSpareCount); i++) {
+ vec4 r = pardesSpare[i];
+ if (p.x >= r.x && p.y >= r.y && p.x < r.z && p.y < r.w) return true;
+ }
+ return false;
+}
+
// 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);
@@ -143,9 +170,11 @@ void mainImage(out vec4 fragColor, in vec2 fragCoord) {
// 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);
+ // Periods in logical pixels: the same look at any density.
+ float density = max(1.0, pardesScale);
+ float line = 0.5 + 0.5 * cos(fragCoord.y * TAU / (SCAN_PERIOD_PX * density));
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));
+ col *= 1.0 + maskStrength() * cos(fragCoord.x * TAU / (MASK_PERIOD_PX * density) + vec3(0.0, TAU / 3.0, 2.0 * TAU / 3.0));
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);
diff --git a/shaders/prebuilt/post-crt.frag.spv b/shaders/prebuilt/post-crt.frag.spv
index 6599abd9..fe2c3edb 100644
--- a/shaders/prebuilt/post-crt.frag.spv
+++ b/shaders/prebuilt/post-crt.frag.spv
Binary files differ
diff --git a/shaders/prebuilt/post-grain.frag.glsl b/shaders/prebuilt/post-grain.frag.glsl
new file mode 100644
index 00000000..a4a02e99
--- /dev/null
+++ b/shaders/prebuilt/post-grain.frag.glsl
@@ -0,0 +1,133 @@
+#version 450
+// pardes's Shadertoy prefix (docs/render-pipeline.md §6), put before every
+// post pass: a bundled one in shaders/post/ at build time, a user's file at
+// run time. The uniform names, types and std140 order are ghostty 1.3.2's
+// (src/renderer/shaders/shadertoy_prefix.glsl), so a shader written for
+// ghostty runs here; only the bindings are SDL GPU's (a fragment shader's
+// textures in set 2, its uniform blocks in set 3). Y is down everywhere, as
+// on ghostty's Metal renderer: fragCoord, iChannel0's uv and the cursor
+// rectangles share one top-left space, and iCurrentCursor is (left x,
+// BOTTOM-edge y, width, height) in framebuffer pixels.
+
+layout(set = 3, binding = 0, std140) uniform Globals {
+ uniform vec3 iResolution;
+ uniform float iTime;
+ uniform float iTimeDelta;
+ uniform float iFrameRate;
+ uniform int iFrame;
+ uniform float iChannelTime[4];
+ uniform vec3 iChannelResolution[4];
+ uniform vec4 iMouse;
+ uniform vec4 iDate;
+ uniform float iSampleRate;
+ uniform vec4 iCurrentCursor;
+ uniform vec4 iPreviousCursor;
+ uniform vec4 iCurrentCursorColor;
+ uniform vec4 iPreviousCursorColor;
+ uniform int iCurrentCursorStyle;
+ uniform int iPreviousCursorStyle;
+ uniform int iCursorVisible;
+ uniform float iTimeCursorChange;
+ uniform float iTimeFocus;
+ uniform int iFocus;
+};
+// ghostty's one block, cut in three: SDL GPU binds at most 4 KiB of a
+// uniform block (Vulkan), and the palette alone is 4 KiB. The names and
+// their order are ghostty's; each block is a slice of the same memory.
+layout(set = 3, binding = 1, std140) uniform Palette {
+ uniform vec3 iPalette[256];
+};
+layout(set = 3, binding = 2, std140) uniform Colors {
+ uniform vec3 iBackgroundColor;
+ uniform vec3 iForegroundColor;
+ uniform vec3 iCursorColor;
+ uniform vec3 iCursorText;
+ uniform vec3 iSelectionForegroundColor;
+ uniform vec3 iSelectionBackgroundColor;
+};
+
+// 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; pardesScale
+// is the display's density (2 on a 2x screen), for a pass whose pattern is
+// in logical pixels. iResolution, fragCoord and iMouse stay in the display's
+// pixels, as ghostty's do. pardesCap is the most a bundled pass may do on
+// this theme and still leave its text, and its selection's, at their own
+// contrast or 4.5 (docs/effects.md); pardesSpare holds pardesSpareCount
+// rectangles (x0, y0, x1, y1 in fragCoord's pixels) a bundled pass leaves
+// alone: every tag, grip and notice, and the cursor, so no pass ever touches
+// a focus indicator.
+layout(set = 3, binding = 3, std140) uniform PardesPost {
+ float pardesOpaque;
+ float pardesLevel;
+ float pardesScale;
+ float pardesCap;
+ float pardesSpareCount;
+ vec4 pardesSpare[32];
+};
+
+bool pardesSpared(vec2 p) {
+ for (int i = 0; i < int(pardesSpareCount); i++) {
+ vec4 r = pardesSpare[i];
+ if (p.x >= r.x && p.y >= r.y && p.x < r.z && p.y < r.w) return true;
+ }
+ return false;
+}
+
+// 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
+#define CURSORSTYLE_UNDERLINE 3
+#define CURSORSTYLE_LOCK 4
+
+layout(set = 2, binding = 0) uniform sampler2D iChannel0;
+
+layout(location = 0) out vec4 _fragColor;
+
+#define texture2D texture
+
+void mainImage(out vec4 fragColor, in vec2 fragCoord);
+void main() {
+ mainImage(_fragColor, gl_FragCoord.xy);
+ if (pardesOpaque > 0.5) _fragColor.a = 1.0;
+}
+
+// The shader's own lines count from 1, so glslc's errors name them.
+#line 1
+// Grain: the page's own ground takes a fine, still grain, like paper. Only
+// pixels of the page's colour (iBackgroundColor) are grained: no glyph, no
+// selection, no tag or rule, and nothing in pardesSpare. The grain averages
+// to the page, is a logical pixel big (pardesScale), and never moves, so it
+// costs no frames. At most 1.5, 3 and 5 of 255 at levels 1 to 3, and never
+// more than pardesCap, which keeps the text on it at its own contrast or 4.5.
+// It is a Shadertoy file: pardes puts its prefix before it.
+
+float amplitude() { return min(pardesByLevel(1.5, 3.0, 5.0) / 255.0, pardesCap); }
+
+// An integer hash of the grain cell: white, with no pattern to see.
+float hash(uvec2 p) {
+ uint h = p.x * 1664525u + p.y * 1013904223u;
+ h ^= h >> 16;
+ h *= 2246822519u;
+ h ^= h >> 13;
+ h *= 3266489917u;
+ h ^= h >> 16;
+ return float(h) / 4294967295.0;
+}
+
+void mainImage(out vec4 fragColor, in vec2 fragCoord) {
+ vec2 uv = fragCoord / iResolution.xy;
+ vec4 frame = texture(iChannel0, uv);
+ fragColor = frame;
+ vec3 page = iBackgroundColor.rgb;
+ if (any(greaterThan(abs(frame.rgb - page), vec3(0.75 / 255.0))) || pardesSpared(fragCoord)) return;
+ uvec2 cell = uvec2(fragCoord / max(1.0, pardesScale));
+ // Two hashes summed: a triangular spread, softer than a flat one.
+ float n = hash(cell) + hash(cell + uvec2(7919u, 104729u)) - 1.0;
+ fragColor = vec4(clamp(page + n * amplitude(), 0.0, 1.0), frame.a);
+}
diff --git a/shaders/prebuilt/post-grain.frag.spv b/shaders/prebuilt/post-grain.frag.spv
new file mode 100644
index 00000000..e4c893af
--- /dev/null
+++ b/shaders/prebuilt/post-grain.frag.spv
Binary files differ
diff --git a/shaders/prebuilt/post-vignette.frag.glsl b/shaders/prebuilt/post-vignette.frag.glsl
new file mode 100644
index 00000000..d5737901
--- /dev/null
+++ b/shaders/prebuilt/post-vignette.frag.glsl
@@ -0,0 +1,139 @@
+#version 450
+// pardes's Shadertoy prefix (docs/render-pipeline.md §6), put before every
+// post pass: a bundled one in shaders/post/ at build time, a user's file at
+// run time. The uniform names, types and std140 order are ghostty 1.3.2's
+// (src/renderer/shaders/shadertoy_prefix.glsl), so a shader written for
+// ghostty runs here; only the bindings are SDL GPU's (a fragment shader's
+// textures in set 2, its uniform blocks in set 3). Y is down everywhere, as
+// on ghostty's Metal renderer: fragCoord, iChannel0's uv and the cursor
+// rectangles share one top-left space, and iCurrentCursor is (left x,
+// BOTTOM-edge y, width, height) in framebuffer pixels.
+
+layout(set = 3, binding = 0, std140) uniform Globals {
+ uniform vec3 iResolution;
+ uniform float iTime;
+ uniform float iTimeDelta;
+ uniform float iFrameRate;
+ uniform int iFrame;
+ uniform float iChannelTime[4];
+ uniform vec3 iChannelResolution[4];
+ uniform vec4 iMouse;
+ uniform vec4 iDate;
+ uniform float iSampleRate;
+ uniform vec4 iCurrentCursor;
+ uniform vec4 iPreviousCursor;
+ uniform vec4 iCurrentCursorColor;
+ uniform vec4 iPreviousCursorColor;
+ uniform int iCurrentCursorStyle;
+ uniform int iPreviousCursorStyle;
+ uniform int iCursorVisible;
+ uniform float iTimeCursorChange;
+ uniform float iTimeFocus;
+ uniform int iFocus;
+};
+// ghostty's one block, cut in three: SDL GPU binds at most 4 KiB of a
+// uniform block (Vulkan), and the palette alone is 4 KiB. The names and
+// their order are ghostty's; each block is a slice of the same memory.
+layout(set = 3, binding = 1, std140) uniform Palette {
+ uniform vec3 iPalette[256];
+};
+layout(set = 3, binding = 2, std140) uniform Colors {
+ uniform vec3 iBackgroundColor;
+ uniform vec3 iForegroundColor;
+ uniform vec3 iCursorColor;
+ uniform vec3 iCursorText;
+ uniform vec3 iSelectionForegroundColor;
+ uniform vec3 iSelectionBackgroundColor;
+};
+
+// 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; pardesScale
+// is the display's density (2 on a 2x screen), for a pass whose pattern is
+// in logical pixels. iResolution, fragCoord and iMouse stay in the display's
+// pixels, as ghostty's do. pardesCap is the most a bundled pass may do on
+// this theme and still leave its text, and its selection's, at their own
+// contrast or 4.5 (docs/effects.md); pardesSpare holds pardesSpareCount
+// rectangles (x0, y0, x1, y1 in fragCoord's pixels) a bundled pass leaves
+// alone: every tag, grip and notice, and the cursor, so no pass ever touches
+// a focus indicator.
+layout(set = 3, binding = 3, std140) uniform PardesPost {
+ float pardesOpaque;
+ float pardesLevel;
+ float pardesScale;
+ float pardesCap;
+ float pardesSpareCount;
+ vec4 pardesSpare[32];
+};
+
+bool pardesSpared(vec2 p) {
+ for (int i = 0; i < int(pardesSpareCount); i++) {
+ vec4 r = pardesSpare[i];
+ if (p.x >= r.x && p.y >= r.y && p.x < r.z && p.y < r.w) return true;
+ }
+ return false;
+}
+
+// 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
+#define CURSORSTYLE_UNDERLINE 3
+#define CURSORSTYLE_LOCK 4
+
+layout(set = 2, binding = 0) uniform sampler2D iChannel0;
+
+layout(location = 0) out vec4 _fragColor;
+
+#define texture2D texture
+
+void mainImage(out vec4 fragColor, in vec2 fragCoord);
+void main() {
+ mainImage(_fragColor, gl_FragCoord.xy);
+ if (pardesOpaque > 0.5) _fragColor.a = 1.0;
+}
+
+// The shader's own lines count from 1, so glslc's errors name them.
+#line 1
+// Vignette: the window's corners fall a little into shade, in linear light,
+// so the eye settles on the middle. Round, whatever the window's shape;
+// nothing within half the way to a corner is touched. At most 28% at the
+// far corners (level 3), and never more than pardesCap, so text and its
+// selection keep their own contrast or 4.5. Tags, grips, notices and the
+// cursor are left alone (pardesSpare): the focus indicators never darken.
+// It is a Shadertoy file: pardes puts its prefix before it.
+
+float strength() { return min(pardesByLevel(0.10, 0.18, 0.28), pardesCap); }
+
+vec3 toLinear(vec3 c) {
+ return mix(pow((c + 0.055) / 1.055, vec3(2.4)), c / 12.92, lessThanEqual(c, vec3(0.04045)));
+}
+
+vec3 toSrgb(vec3 c) {
+ c = max(c, vec3(0.0));
+ return mix(1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055, c * 12.92, lessThanEqual(c, vec3(0.0031308)));
+}
+
+float ign(vec2 p) {
+ return fract(52.9829189 * fract(dot(p, vec2(0.06711056, 0.00583715))));
+}
+
+void mainImage(out vec4 fragColor, in vec2 fragCoord) {
+ vec2 uv = fragCoord / iResolution.xy;
+ vec4 frame = texture(iChannel0, uv);
+ if (pardesSpared(fragCoord)) {
+ fragColor = frame;
+ return;
+ }
+ // 0 at the middle, 1 at a corner, on a circle's measure.
+ vec2 half_size = 0.5 * iResolution.xy;
+ float r = length(fragCoord - half_size) / length(half_size);
+ float shade = strength() * pow(smoothstep(0.5, 1.0, r), 1.5);
+ vec3 srgb = toSrgb(toLinear(frame.rgb) * (1.0 - shade));
+ srgb += (ign(fragCoord) - 0.5) / 255.0 * step(1e-4, shade);
+ fragColor = vec4(clamp(srgb, 0.0, 1.0), frame.a);
+}
diff --git a/shaders/prebuilt/post-vignette.frag.spv b/shaders/prebuilt/post-vignette.frag.spv
new file mode 100644
index 00000000..4dfb6125
--- /dev/null
+++ b/shaders/prebuilt/post-vignette.frag.spv
Binary files differ
diff --git a/shaders/prebuilt/ui.frag.glsl b/shaders/prebuilt/ui.frag.glsl
index 0b099db3..cb38fff1 100644
--- a/shaders/prebuilt/ui.frag.glsl
+++ b/shaders/prebuilt/ui.frag.glsl
@@ -10,6 +10,12 @@
layout(set = 2, binding = 0) uniform sampler2D u_atlas;
layout(std140, set = 3, binding = 0) uniform UiUniforms {
float background_opacity;
+ // A theme's ornament (colors.Decor): the page's dots (rgb, strength),
+ // their geometry (period, solid radius, faded radius, in pixels), and a
+ // file name's shadow (rgb, offset in pixels).
+ vec4 decor_dots;
+ vec4 decor_dot_geom;
+ vec4 decor_shadow;
} u_ui;
layout(location = 0) in vec2 v_uv;
@@ -43,7 +49,7 @@ void main() {
float bgA = (v_effect.x & 0x20000000u) != 0u ? 1.0
: (v_effect.x & 0x40000000u) != 0u ? 0.0
: clamp(u_ui.background_opacity, 0.0, 1.0);
- uint effect = v_effect.x & 0x1fffffffu;
+ uint effect = v_effect.x & 0x07ffffffu;
float progress = clamp(uintBitsToFloat(v_effect.y), 0.0, 1.0);
uint cellCol = v_effect.w & 0xffffu;
uint cellRow = v_effect.w >> 16;
@@ -52,15 +58,42 @@ void main() {
// Ink over ground, both premultiplied: v_fg*a + (v_bg*bgA)*(1-a), which is
// mix() with the ground already premultiplied. At bgA = 1 that is exactly
// the mix(v_bg, v_fg, a) at alpha 1 this shader always wrote.
- vec4 cell = vec4(mix(v_bg * bgA, v_fg, a), mix(bgA, 1.0, a));
+ vec3 ground = v_bg;
+ // 0x10000000: the page's ground under a pane body, dotted (lapis): a
+ // dot every period pixels, fixed to the window, under the text.
+ if ((v_effect.x & 0x10000000u) != 0u) {
+ float period = u_ui.decor_dot_geom.x;
+ vec2 d = mod(gl_FragCoord.xy, period) - 0.5 * period;
+ float dot_a = 1.0 - smoothstep(u_ui.decor_dot_geom.y, u_ui.decor_dot_geom.z, length(d));
+ ground = mix(ground, u_ui.decor_dots.rgb, u_ui.decor_dots.a * dot_a);
+ }
+ vec4 under = vec4(ground * bgA, bgA);
+ // Derivatives outside any branch: a pixel's step in the atlas and in
+ // the cell, for the shadow's offset.
+ vec2 step_uv = vec2(dFdx(v_uv.x), dFdy(v_uv.y)) * u_ui.decor_shadow.a;
+ vec2 step_cell = vec2(dFdx(v_cell_uv.x), dFdy(v_cell_uv.y)) * u_ui.decor_shadow.a;
+ // 0x08000000: a file name's letters cast a shadow down and right onto
+ // their own cell's ground (lapis), under the ink; what would fall past
+ // the cell's edge is not drawn.
+ if ((v_effect.x & 0x08000000u) != 0u) {
+ vec2 from = v_cell_uv - step_cell;
+ float s = all(greaterThanEqual(from, vec2(0.0))) ? texture(u_atlas, v_uv - step_uv).r : 0.0;
+ under = mix(under, vec4(u_ui.decor_shadow.rgb, 1.0), s);
+ }
+ vec4 cell = vec4(mix(under.rgb, v_fg, a), mix(under.a, 1.0, a));
- // 3 = data dissolve. Changed cells retain the frozen old cell until their
- // stable threshold, then atomically become the new cell. Exact endpoints
- // mirror panel_animation.dissolveRevealed, including the zero hash.
+ // 3 = dissolve, a crossfade (G7): a changed cell's new form is drawn
+ // first, whole, and its frozen old one over it at 1 - progress,
+ // premultiplied (the frame's cells blend over, pipeline_over), so the
+ // old fades out as the new comes in; at the ends, exactly one of them.
+ // The tty keeps its per-cell swap (panel_animation.dissolveRevealed).
if (effect == 3u) {
- bool reveal = progress >= 1.0 || (progress > 0.0 && noise < progress);
- if (oldLayer ? reveal : !reveal) discard;
- o_col = cell;
+ if (!oldLayer) {
+ o_col = cell;
+ return;
+ }
+ if (progress >= 1.0) discard;
+ o_col = cell * (1.0 - progress);
return;
}
diff --git a/shaders/prebuilt/ui.frag.spv b/shaders/prebuilt/ui.frag.spv
index 033c10ab..15318214 100644
--- a/shaders/prebuilt/ui.frag.spv
+++ b/shaders/prebuilt/ui.frag.spv
Binary files differ
diff --git a/shaders/prebuilt/ui.vert.glsl b/shaders/prebuilt/ui.vert.glsl
index c1779add..de22adee 100644
--- a/shaders/prebuilt/ui.vert.glsl
+++ b/shaders/prebuilt/ui.vert.glsl
@@ -14,9 +14,11 @@ layout(location = 3) in vec3 a_bg;
layout(location = 4) in vec4 a_panel_rect;
layout(location = 5) in vec4 a_present_rect;
// effect id, eased-progress float bits, pane serial, local row/column packed
-// into one uint. The THREE high effect bits are flags — the frozen-old cell
-// layer, a see-through cell background and an opaque block-cursor fill — so
-// the id is what is left below them; integer transport preserves the exact
+// into one uint. The FIVE high effect bits are flags — the frozen-old cell
+// layer, a see-through cell background, an opaque block-cursor fill, a soft
+// shadow (decor.frag.glsl) or dotted page ground (ui.frag.glsl), and a
+// checker (decor) or a file name's shadow (ui) — so the id is what is left
+// below them; integer transport preserves the exact
// cross-backend hash.
layout(location = 6) in uvec4 a_effect;
// A clip rectangle in target pixels (x0, y0, x1, y1): the fragment shader
@@ -61,7 +63,7 @@ void main() {
v_cell_uv = vec2(0.0, 1.0);
}
- uint effect = a_effect.x & 0x1fffffffu;
+ uint effect = a_effect.x & 0x07ffffffu;
if (effect == 1u || effect == 2u || effect == 5u) {
// NDC y points up, so a top-left/bottom-right box has a NEGATIVE y
// delta. Preserve that sign or every local y is mirrored/outside.
diff --git a/shaders/prebuilt/ui.vert.spv b/shaders/prebuilt/ui.vert.spv
index 619a9690..af5b0738 100644
--- a/shaders/prebuilt/ui.vert.spv
+++ b/shaders/prebuilt/ui.vert.spv
Binary files differ
diff --git a/shaders/ui.frag.glsl b/shaders/ui.frag.glsl
index dca224ba..cb38fff1 100644
--- a/shaders/ui.frag.glsl
+++ b/shaders/ui.frag.glsl
@@ -10,6 +10,12 @@
layout(set = 2, binding = 0) uniform sampler2D u_atlas;
layout(std140, set = 3, binding = 0) uniform UiUniforms {
float background_opacity;
+ // A theme's ornament (colors.Decor): the page's dots (rgb, strength),
+ // their geometry (period, solid radius, faded radius, in pixels), and a
+ // file name's shadow (rgb, offset in pixels).
+ vec4 decor_dots;
+ vec4 decor_dot_geom;
+ vec4 decor_shadow;
} u_ui;
layout(location = 0) in vec2 v_uv;
@@ -43,7 +49,7 @@ void main() {
float bgA = (v_effect.x & 0x20000000u) != 0u ? 1.0
: (v_effect.x & 0x40000000u) != 0u ? 0.0
: clamp(u_ui.background_opacity, 0.0, 1.0);
- uint effect = v_effect.x & 0x0fffffffu;
+ uint effect = v_effect.x & 0x07ffffffu;
float progress = clamp(uintBitsToFloat(v_effect.y), 0.0, 1.0);
uint cellCol = v_effect.w & 0xffffu;
uint cellRow = v_effect.w >> 16;
@@ -52,15 +58,42 @@ void main() {
// Ink over ground, both premultiplied: v_fg*a + (v_bg*bgA)*(1-a), which is
// mix() with the ground already premultiplied. At bgA = 1 that is exactly
// the mix(v_bg, v_fg, a) at alpha 1 this shader always wrote.
- vec4 cell = vec4(mix(v_bg * bgA, v_fg, a), mix(bgA, 1.0, a));
+ vec3 ground = v_bg;
+ // 0x10000000: the page's ground under a pane body, dotted (lapis): a
+ // dot every period pixels, fixed to the window, under the text.
+ if ((v_effect.x & 0x10000000u) != 0u) {
+ float period = u_ui.decor_dot_geom.x;
+ vec2 d = mod(gl_FragCoord.xy, period) - 0.5 * period;
+ float dot_a = 1.0 - smoothstep(u_ui.decor_dot_geom.y, u_ui.decor_dot_geom.z, length(d));
+ ground = mix(ground, u_ui.decor_dots.rgb, u_ui.decor_dots.a * dot_a);
+ }
+ vec4 under = vec4(ground * bgA, bgA);
+ // Derivatives outside any branch: a pixel's step in the atlas and in
+ // the cell, for the shadow's offset.
+ vec2 step_uv = vec2(dFdx(v_uv.x), dFdy(v_uv.y)) * u_ui.decor_shadow.a;
+ vec2 step_cell = vec2(dFdx(v_cell_uv.x), dFdy(v_cell_uv.y)) * u_ui.decor_shadow.a;
+ // 0x08000000: a file name's letters cast a shadow down and right onto
+ // their own cell's ground (lapis), under the ink; what would fall past
+ // the cell's edge is not drawn.
+ if ((v_effect.x & 0x08000000u) != 0u) {
+ vec2 from = v_cell_uv - step_cell;
+ float s = all(greaterThanEqual(from, vec2(0.0))) ? texture(u_atlas, v_uv - step_uv).r : 0.0;
+ under = mix(under, vec4(u_ui.decor_shadow.rgb, 1.0), s);
+ }
+ vec4 cell = vec4(mix(under.rgb, v_fg, a), mix(under.a, 1.0, a));
- // 3 = data dissolve. Changed cells retain the frozen old cell until their
- // stable threshold, then atomically become the new cell. Exact endpoints
- // mirror panel_animation.dissolveRevealed, including the zero hash.
+ // 3 = dissolve, a crossfade (G7): a changed cell's new form is drawn
+ // first, whole, and its frozen old one over it at 1 - progress,
+ // premultiplied (the frame's cells blend over, pipeline_over), so the
+ // old fades out as the new comes in; at the ends, exactly one of them.
+ // The tty keeps its per-cell swap (panel_animation.dissolveRevealed).
if (effect == 3u) {
- bool reveal = progress >= 1.0 || (progress > 0.0 && noise < progress);
- if (oldLayer ? reveal : !reveal) discard;
- o_col = cell;
+ if (!oldLayer) {
+ o_col = cell;
+ return;
+ }
+ if (progress >= 1.0) discard;
+ o_col = cell * (1.0 - progress);
return;
}
diff --git a/shaders/ui.vert.glsl b/shaders/ui.vert.glsl
index 5551f3f1..de22adee 100644
--- a/shaders/ui.vert.glsl
+++ b/shaders/ui.vert.glsl
@@ -14,9 +14,11 @@ layout(location = 3) in vec3 a_bg;
layout(location = 4) in vec4 a_panel_rect;
layout(location = 5) in vec4 a_present_rect;
// effect id, eased-progress float bits, pane serial, local row/column packed
-// into one uint. The FOUR high effect bits are flags — the frozen-old cell
-// layer, a see-through cell background, an opaque block-cursor fill and a
-// soft shadow (decor.frag.glsl) — so the id is what is left below them; integer transport preserves the exact
+// into one uint. The FIVE high effect bits are flags — the frozen-old cell
+// layer, a see-through cell background, an opaque block-cursor fill, a soft
+// shadow (decor.frag.glsl) or dotted page ground (ui.frag.glsl), and a
+// checker (decor) or a file name's shadow (ui) — so the id is what is left
+// below them; integer transport preserves the exact
// cross-backend hash.
layout(location = 6) in uvec4 a_effect;
// A clip rectangle in target pixels (x0, y0, x1, y1): the fragment shader
@@ -61,7 +63,7 @@ void main() {
v_cell_uv = vec2(0.0, 1.0);
}
- uint effect = a_effect.x & 0x0fffffffu;
+ uint effect = a_effect.x & 0x07ffffffu;
if (effect == 1u || effect == 2u || effect == 5u) {
// NDC y points up, so a top-left/bottom-right box has a NEGATIVE y
// delta. Preserve that sign or every local y is mirrored/outside.