summaryrefslogtreecommitdiff
path: root/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'shaders')
-rw-r--r--shaders/post/crt.glsl6
-rw-r--r--shaders/post/prefix.glsl6
-rw-r--r--shaders/prebuilt/decor.frag.glsl60
-rw-r--r--shaders/prebuilt/decor.frag.spvbin2100 -> 6560 bytes
-rw-r--r--shaders/prebuilt/post-crt.frag.glsl12
-rw-r--r--shaders/prebuilt/post-crt.frag.spvbin12424 -> 12668 bytes
-rw-r--r--shaders/prebuilt/ui.frag.glsl2
-rw-r--r--shaders/prebuilt/ui.frag.spvbin5700 -> 5700 bytes
-rw-r--r--shaders/prebuilt/ui.vert.glsl8
-rw-r--r--shaders/prebuilt/ui.vert.spvbin5612 -> 5612 bytes
10 files changed, 76 insertions, 18 deletions
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/prefix.glsl b/shaders/post/prefix.glsl
index e718a98f..7a50936e 100644
--- a/shaders/post/prefix.glsl
+++ b/shaders/post/prefix.glsl
@@ -41,10 +41,14 @@ 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.
+// 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.
layout(set = 3, binding = 1, std140) uniform PardesPost {
float pardesOpaque;
float pardesLevel;
+ float pardesScale;
};
// A bundled pass's constant at levels 1, 2 and 3.
diff --git a/shaders/prebuilt/decor.frag.glsl b/shaders/prebuilt/decor.frag.glsl
index 4c2bd6d8..3e2c286f 100644
--- a/shaders/prebuilt/decor.frag.glsl
+++ b/shaders/prebuilt/decor.frag.glsl
@@ -1,24 +1,70 @@
#version 450
-// Decor: a flat, hard-edged fill (a rule, a rail, a grip mark, a bar cursor)
-// that ui.vert.glsl places like a cell, its track's transition included. Its
-// colour rides in the cell's ground (a_bg) and its coverage in a_fg.r. The
-// pipeline blends it as the overlay pipeline does (backgroundLayerBlend), so
-// a fading rule shows through, and the result is that pipeline's exactly.
-// Ink (a cursor) is drawn with the opacity uniform at 1.
+// Decor, drawn by ui.vert.glsl like a cell, its track's transition included,
+// and blended as the overlay pipeline blends (backgroundLayerBlend). Ink (a
+// cursor) is drawn with the opacity uniform at 1.
+//
+// Flat: a hard-edged fill (a rule, a rail, a grip mark, a bar cursor). Its
+// colour rides in the cell's ground (a_bg), its coverage in a_fg.r, so the
+// result is the overlay pipeline's exactly.
+//
+// Soft (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);
+ 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..3256f2b1 100644
--- a/shaders/prebuilt/decor.frag.spv
+++ b/shaders/prebuilt/decor.frag.spv
Binary files differ
diff --git a/shaders/prebuilt/post-crt.frag.glsl b/shaders/prebuilt/post-crt.frag.glsl
index c2cadfa2..7d2266c0 100644
--- a/shaders/prebuilt/post-crt.frag.glsl
+++ b/shaders/prebuilt/post-crt.frag.glsl
@@ -41,10 +41,14 @@ 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.
+// 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.
layout(set = 3, binding = 1, std140) uniform PardesPost {
float pardesOpaque;
float pardesLevel;
+ float pardesScale;
};
// A bundled pass's constant at levels 1, 2 and 3.
@@ -143,9 +147,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..d6cc6c37 100644
--- a/shaders/prebuilt/post-crt.frag.spv
+++ b/shaders/prebuilt/post-crt.frag.spv
Binary files differ
diff --git a/shaders/prebuilt/ui.frag.glsl b/shaders/prebuilt/ui.frag.glsl
index 0b099db3..dca224ba 100644
--- a/shaders/prebuilt/ui.frag.glsl
+++ b/shaders/prebuilt/ui.frag.glsl
@@ -43,7 +43,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 & 0x0fffffffu;
float progress = clamp(uintBitsToFloat(v_effect.y), 0.0, 1.0);
uint cellCol = v_effect.w & 0xffffu;
uint cellRow = v_effect.w >> 16;
diff --git a/shaders/prebuilt/ui.frag.spv b/shaders/prebuilt/ui.frag.spv
index 033c10ab..c8ee1604 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..5551f3f1 100644
--- a/shaders/prebuilt/ui.vert.glsl
+++ b/shaders/prebuilt/ui.vert.glsl
@@ -14,9 +14,9 @@ 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 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
// 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 +61,7 @@ void main() {
v_cell_uv = vec2(0.0, 1.0);
}
- uint effect = a_effect.x & 0x1fffffffu;
+ uint effect = a_effect.x & 0x0fffffffu;
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..b1e87ec1 100644
--- a/shaders/prebuilt/ui.vert.spv
+++ b/shaders/prebuilt/ui.vert.spv
Binary files differ