summaryrefslogtreecommitdiff
path: root/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'shaders')
-rw-r--r--shaders/crt.ci.metal75
-rw-r--r--shaders/crt.frag.glsl175
-rw-r--r--shaders/crt.vert.glsl9
-rw-r--r--shaders/decor.frag.glsl24
-rw-r--r--shaders/post.vert.glsl10
-rw-r--r--shaders/post/crt.glsl83
-rw-r--r--shaders/post/prefix.glsl74
-rw-r--r--shaders/prebuilt/crt.frag.glsl175
-rw-r--r--shaders/prebuilt/crt.frag.spvbin13832 -> 0 bytes
-rw-r--r--shaders/prebuilt/crt.vert.glsl9
-rw-r--r--shaders/prebuilt/decor.frag.glsl24
-rw-r--r--shaders/prebuilt/decor.frag.spvbin0 -> 2100 bytes
-rw-r--r--shaders/prebuilt/post-crt.frag.glsl157
-rw-r--r--shaders/prebuilt/post-crt.frag.spvbin0 -> 12424 bytes
-rw-r--r--shaders/prebuilt/post.vert.glsl10
-rw-r--r--shaders/prebuilt/post.vert.spv (renamed from shaders/prebuilt/crt.vert.spv)bin1208 -> 1208 bytes
-rw-r--r--shaders/prebuilt/ui.frag.glsl3
-rw-r--r--shaders/prebuilt/ui.frag.spvbin4668 -> 5700 bytes
-rw-r--r--shaders/prebuilt/ui.vert.glsl6
-rw-r--r--shaders/prebuilt/ui.vert.spvbin5468 -> 5612 bytes
-rw-r--r--shaders/ui.frag.glsl3
-rw-r--r--shaders/ui.vert.glsl6
22 files changed, 409 insertions, 434 deletions
diff --git a/shaders/crt.ci.metal b/shaders/crt.ci.metal
index c7e91a7e..9159af18 100644
--- a/shaders/crt.ci.metal
+++ b/shaders/crt.ci.metal
@@ -1,7 +1,6 @@
// Native macOS panel and scene postprocess. Panel kernels consume the core's
-// plain tracks; the final full-window kernel ports crt.frag.glsl and combines
-// CRT, ripple and glitch. Scene constants and sampling geometry stay in step
-// with GLSL, while panel easing/noise stays in step with panel_animation.zig.
+// plain tracks; the final full-window kernel is the CRT. Panel easing/noise
+// stays in step with panel_animation.zig.
//
// The three entry points are `extern "C" [[stitchable]]`. Both halves are
// load-bearing: this source is compiled at runtime by
@@ -38,24 +37,6 @@ float pardesCellNoise(float2 serialParts, float colValue, float rowValue) {
return float(x & 0xffffu) / 65535.0;
}
-float2 pardesSceneUV(float2 uv, float timeSeconds, float rippleOn, float glitchOn) {
- if (rippleOn > 0.5) {
- float2 centered = uv - 0.5;
- float radius = length(centered);
- // Reversed smoothstep edges are undefined in GLSL and Metal alike.
- float envelope = 1.0 - smoothstep(0.04, 0.72, radius);
- float wave = sin(radius * 42.0 - timeSeconds * 5.2);
- uv += centered / max(radius, 0.00001) * wave * envelope * 0.0032;
- }
- if (glitchOn > 0.5) {
- float band = floor(uv.y * 96.0);
- float seed = pardesNoise(float2(band, floor(timeSeconds * 13.0)));
- float tear = smoothstep(0.955, 1.0, seed);
- uv.x += (pardesNoise(float2(seed, band)) - 0.5) * tear * 0.020;
- }
- return uv;
-}
-
float4 pardesSceneSample(
coreimage::sampler source,
float2 origin,
@@ -66,42 +47,13 @@ float4 pardesSceneSample(
source.sample(source.transform(origin + uv * size)));
}
-// Keep this ordering identical to crt.frag.glsl's sceneSrgb: every caller
-// supplies its own pre-warp coordinate, then ripple/glitch move that sample,
-// then glitch splits its red/blue channels around the moved center.
-float4 pardesSceneSrgb(
- coreimage::sampler source,
- float2 origin,
- float2 size,
- float2 uv,
- float timeSeconds,
- float rippleOn,
- float glitchOn
-) {
- float2 warped = pardesSceneUV(uv, timeSeconds, rippleOn, glitchOn);
- float4 center = pardesSceneSample(source, origin, size, warped);
- if (glitchOn <= 0.5) return center;
-
- float band = floor(warped.y * 96.0);
- float seed = pardesNoise(float2(band, floor(timeSeconds * 13.0)));
- float tear = smoothstep(0.955, 1.0, seed);
- float2 chroma = float2((0.35 + 1.25 * tear) / size.x, 0.0);
- float4 red = pardesSceneSample(source, origin, size, warped + chroma);
- float4 blue = pardesSceneSample(source, origin, size, warped - chroma);
- return float4(red.r, center.g, blue.b, center.a);
-}
-
float3 pardesSceneLinear(
coreimage::sampler source,
float2 origin,
float2 size,
- float2 uv,
- float timeSeconds,
- float rippleOn,
- float glitchOn
+ float2 uv
) {
- return coreimage::srgb_to_linear(pardesSceneSrgb(
- source, origin, size, uv, timeSeconds, rippleOn, glitchOn).rgb);
+ return coreimage::srgb_to_linear(pardesSceneSample(source, origin, size, uv).rgb);
}
bool pardesInside(float2 p, float4 box) {
@@ -242,8 +194,6 @@ extern "C" [[stitchable]] float4 pardesScene(
float timeSeconds,
float frame,
float crtOn,
- float rippleOn,
- float glitchOn,
float2 sceneSize,
float2 sceneOrigin,
coreimage::destination destination
@@ -277,24 +227,18 @@ extern "C" [[stitchable]] float4 pardesScene(
// transparent theme.
if (crtOn > 0.5 && edge <= 0.0) return float4(0.0, 0.0, 0.0, 1.0);
- float4 center = pardesSceneSrgb(
- source, origin, size, uv, timeSeconds, rippleOn, glitchOn);
+ float4 center = pardesSceneSample(source, origin, size, uv);
float3 scene = center.rgb;
- // Ripple/glitch alone are coordinate effects. Returning the sampled sRGB
- // values directly keeps exact theme colors exact.
+ // Without the CRT the scene passes through, exact.
if (crtOn <= 0.5) {
return coreimage::premultiply(float4(clamp(scene, 0.0, 1.0), center.a));
}
float3 centerLinear = coreimage::srgb_to_linear(scene);
float2 radialChroma = cc * (chromaPx * r2) * texel;
- float3 redSample = pardesSceneLinear(
- source, origin, size, uv + radialChroma,
- timeSeconds, rippleOn, glitchOn);
- float3 blueSample = pardesSceneLinear(
- source, origin, size, uv - radialChroma,
- timeSeconds, rippleOn, glitchOn);
+ float3 redSample = pardesSceneLinear(source, origin, size, uv + radialChroma);
+ float3 blueSample = pardesSceneLinear(source, origin, size, uv - radialChroma);
float3 col = float3(
redSample.r,
centerLinear.g,
@@ -308,8 +252,7 @@ extern "C" [[stitchable]] float4 pardesScene(
float2(0.0, bloom.y), float2(0.0, -bloom.y)
};
for (uint i = 0; i < 4; i++) {
- // Deliberately raw, like GLSL brightPass: bloom belongs to the source
- // image and does not recursively warp through the scene effects.
+ // Deliberately raw, like GLSL brightPass.
float4 sampleValue = pardesSceneSample(
source, origin, size, uv + bloomOffsets[i]);
float3 linearValue = coreimage::srgb_to_linear(sampleValue.rgb);
diff --git a/shaders/crt.frag.glsl b/shaders/crt.frag.glsl
deleted file mode 100644
index b0b0b93b..00000000
--- a/shaders/crt.frag.glsl
+++ /dev/null
@@ -1,175 +0,0 @@
-#version 450
-
-// The Crt builtin's post-process. Screen point cc shows the scene at
-// uv' = cc*(1 + BARREL*r2), and src/gui/crt.zig maps mouse input through that
-// same transform — keep them equal or clicks drift near the edges.
-
-layout(set = 2, binding = 0) uniform sampler2D u_scene;
-layout(std140, set = 3, binding = 0) uniform CrtUniforms {
- float time_seconds;
- float frame;
- vec2 viewport;
- // x = CRT, y = ripple, z = glitch. One scene pass can combine them.
- vec4 effects;
-} u_crt;
-
-layout(location = 0) out vec4 o_col;
-
-const float TAU = 6.28318530718;
-const float BARREL = 0.016; // MUST match src/gui/crt.zig barrel
-const float EDGE_SOFTNESS_PX = 3.5;
-const float CHROMA_PX = 0.28; // radial R/B separation in physical pixels at r2=1
-const float BLOOM_RADIUS_PX = 1.75;
-const float BLOOM_THRESHOLD = 0.60; // linear-light channel peak
-const float BLOOM_SOFTNESS = 0.25;
-const float BLOOM_STRENGTH = 0.045;
-const float SCAN_PERIOD_PX = 3.0;
-const float SCAN_STRENGTH = 0.055;
-const float MASK_PERIOD_PX = 3.0;
-const float MASK_STRENGTH = 0.015;
-const float VIGNETTE_STRENGTH = 0.11; // 11% only at the extreme corners
-const float HUM_STRENGTH = 0.0025;
-const float NOISE_STRENGTH = 0.0020;
-const float EXPOSURE = 1.012;
-
-vec3 srgbToLinear(vec3 c) {
- vec3 low = c / 12.92;
- vec3 high = pow((c + 0.055) / 1.055, vec3(2.4));
- return mix(high, low, lessThanEqual(c, vec3(0.04045)));
-}
-
-vec3 linearToSrgb(vec3 c) {
- c = max(c, vec3(0.0));
- vec3 low = c * 12.92;
- vec3 high = 1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055;
- return mix(high, low, lessThanEqual(c, vec3(0.0031308)));
-}
-
-vec3 sceneLinear(vec2 uv) {
- return srgbToLinear(texture(u_scene, uv).rgb);
-}
-
-vec3 brightPass(vec2 uv) {
- vec3 c = sceneLinear(uv);
- float peak = max(c.r, max(c.g, c.b));
- return c * smoothstep(BLOOM_THRESHOLD, BLOOM_THRESHOLD + BLOOM_SOFTNESS, peak);
-}
-
-float noiseAt(vec2 p) {
- vec3 q = fract(vec3(p.xyx) * 0.1031);
- q += dot(q, q.yzx + 33.33);
- return fract((q.x + q.y) * q.z);
-}
-
-// The non-CRT scene effects deliberately distort the source coordinates,
-// rather than remapping the final colors. Themes retain their palette and the
-// effects remain composable with the linear-light CRT treatment below.
-vec2 sceneUv(vec2 uv) {
- if (u_crt.effects.y > 0.5) {
- vec2 centered = uv - 0.5;
- float radius = length(centered);
- float envelope = 1.0 - smoothstep(0.04, 0.72, radius);
- float wave = sin(radius * 42.0 - u_crt.time_seconds * 5.2);
- uv += centered / max(radius, 0.00001) * wave * envelope * 0.0032;
- }
- if (u_crt.effects.z > 0.5) {
- float band = floor(uv.y * 96.0);
- float seed = noiseAt(vec2(band, floor(u_crt.time_seconds * 13.0)));
- float tear = smoothstep(0.955, 1.0, seed);
- uv.x += (noiseAt(vec2(seed, band)) - 0.5) * tear * 0.020;
- }
- return uv;
-}
-
-// The scene, ALPHA INCLUDED: with a see-through ground the grid arrives
-// premultiplied and partly empty, and a pass that dropped .a would turn the
-// desktop behind a `*_transparent` theme into opaque black the moment Crt,
-// Ripple or Glitch came on.
-vec4 sceneSrgb(vec2 uv) {
- vec2 warped = sceneUv(uv);
- vec4 center = texture(u_scene, warped);
- if (u_crt.effects.z <= 0.5) return center;
-
- float band = floor(warped.y * 96.0);
- float seed = noiseAt(vec2(band, floor(u_crt.time_seconds * 13.0)));
- float tear = smoothstep(0.955, 1.0, seed);
- vec2 chroma = vec2((0.35 + 1.25 * tear) / u_crt.viewport.x, 0.0);
- return vec4(
- texture(u_scene, warped + chroma).r,
- center.g,
- texture(u_scene, warped - chroma).b,
- center.a
- );
-}
-
-vec3 effectSceneLinear(vec2 uv) {
- return srgbToLinear(sceneSrgb(uv).rgb);
-}
-
-void main() {
- vec2 size = u_crt.viewport;
- vec2 texel = 1.0 / size;
- vec2 cc = gl_FragCoord.xy / size * 2.0 - 1.0;
- float r2 = dot(cc, cc);
- vec2 uv = cc * (1.0 + BARREL * r2 * u_crt.effects.x) * 0.5 + 0.5;
-
- // Ripple and glitch are useful without the CRT. They only move samples;
- // skip every tube-specific light/mask/exposure adjustment.
- if (u_crt.effects.x <= 0.5) {
- // The scene texture is already sRGB. Avoid a needless transfer-curve
- // round trip so a coordinate-only effect preserves theme bytes.
- vec4 s = sceneSrgb(uv);
- o_col = vec4(clamp(s.rgb, 0.0, 1.0), clamp(s.a, 0.0, 1.0));
- return;
- }
-
- vec3 col = vec3(0.0);
- // Outside the tube nothing is drawn, so nothing is covered either: the
- // old opaque black there would have punched a rectangle out of the
- // compositor's backdrop.
- float alpha = 0.0;
- float edge = min(min(uv.x, uv.y), min(1.0 - uv.x, 1.0 - uv.y));
- if (edge > 0.0) {
- vec3 center = effectSceneLinear(uv);
- vec2 chroma = cc * (CHROMA_PX * r2) * texel;
- // Each radial sample follows the same ripple/glitch path from its own
- // pre-warp coordinate. This is also how the Metal kernel composes the
- // effects; sampling a once-warped center here made combined effects
- // diverge between the two GUI backends.
- col = vec3(
- effectSceneLinear(uv + chroma).r,
- center.g,
- effectSceneLinear(uv - chroma).b
- );
-
- vec2 bloom_px = texel * BLOOM_RADIUS_PX;
- vec3 bloom = brightPass(uv + vec2(bloom_px.x, 0.0)) +
- brightPass(uv - vec2(bloom_px.x, 0.0)) +
- brightPass(uv + vec2(0.0, bloom_px.y)) +
- brightPass(uv - vec2(0.0, bloom_px.y));
- col += bloom * (0.25 * BLOOM_STRENGTH);
-
- // The mask has unit mean and the scan loss stays small; neither needs
- // the old global lift that remapped every theme toward white.
- float scan_wave = 0.5 + 0.5 * cos(gl_FragCoord.y * TAU / SCAN_PERIOD_PX);
- col *= 1.0 - SCAN_STRENGTH * scan_wave * scan_wave;
- vec3 mask = 1.0 + MASK_STRENGTH * cos(
- gl_FragCoord.x * TAU / MASK_PERIOD_PX + vec3(0.0, TAU / 3.0, 2.0 * TAU / 3.0)
- );
- col *= mask;
-
- vec2 edge_px = min(uv, 1.0 - uv) * size;
- float tube = smoothstep(0.0, EDGE_SOFTNESS_PX, min(edge_px.x, edge_px.y));
- 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 - u_crt.time_seconds * 0.11) * TAU);
- col *= tube * vignette * hum * EXPOSURE;
- // The tube's edge falloff dims coverage as well as colour; everything
- // else here is a light adjustment and leaves it alone.
- alpha = sceneSrgb(uv).a * tube;
-
- float luma = dot(col, vec3(0.2126, 0.7152, 0.0722));
- vec2 noise_seed = gl_FragCoord.xy + vec2(u_crt.frame * 17.0, u_crt.frame * 59.0);
- col += (noiseAt(noise_seed) - 0.5) * NOISE_STRENGTH * (0.15 + 0.85 * clamp(luma, 0.0, 1.0));
- }
- o_col = vec4(linearToSrgb(clamp(col, 0.0, 1.0)), clamp(alpha, 0.0, 1.0));
-}
diff --git a/shaders/crt.vert.glsl b/shaders/crt.vert.glsl
deleted file mode 100644
index 4e15fcdf..00000000
--- a/shaders/crt.vert.glsl
+++ /dev/null
@@ -1,9 +0,0 @@
-#version 450
-
-// CRT post-process pass: one fullscreen triangle from gl_VertexIndex, no
-// vertex buffer. The fragment shader derives uv from gl_FragCoord.
-
-void main() {
- vec2 p = vec2(float((gl_VertexIndex << 1) & 2), float(gl_VertexIndex & 2));
- gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
-}
diff --git a/shaders/decor.frag.glsl b/shaders/decor.frag.glsl
new file mode 100644
index 00000000..4c2bd6d8
--- /dev/null
+++ b/shaders/decor.frag.glsl
@@ -0,0 +1,24 @@
+#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.
+
+layout(std140, set = 3, binding = 0) uniform UiUniforms {
+ float background_opacity;
+} u_ui;
+
+layout(location = 1) in vec3 v_fg;
+layout(location = 2) in vec3 v_bg;
+layout(location = 5) flat in vec4 v_clip;
+
+layout(location = 0) out vec4 o_col;
+
+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);
+}
diff --git a/shaders/post.vert.glsl b/shaders/post.vert.glsl
new file mode 100644
index 00000000..86739a65
--- /dev/null
+++ b/shaders/post.vert.glsl
@@ -0,0 +1,10 @@
+#version 450
+
+// A post pass (docs/render-pipeline.md §6): one fullscreen triangle from
+// gl_VertexIndex, no vertex buffer. The Shadertoy fragment shader works from
+// gl_FragCoord, y down, as its fragCoord.
+
+void main() {
+ vec2 p = vec2(float((gl_VertexIndex << 1) & 2), float(gl_VertexIndex & 2));
+ gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
+}
diff --git a/shaders/post/crt.glsl b/shaders/post/crt.glsl
new file mode 100644
index 00000000..768157ef
--- /dev/null
+++ b/shaders/post/crt.glsl
@@ -0,0 +1,83 @@
+// Crt: a slot-mask tube's light, with nothing that moves a pixel. There is
+// no barrel: every click lands where it is drawn, rails and grips at the
+// window's edges included. What is left is light: a beam profile for the
+// scanlines, an aperture mask, a soft bloom of the brightest ink, a faint
+// vignette and the hum of a live tube. Everything is worked out in linear
+// light and dithered back into 8 bits, so the vignette never bands. It is a
+// Shadertoy file: pardes puts its prefix before it (shaders/post/prefix.glsl).
+
+const float TAU = 6.28318530718;
+// 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 SCAN_PERIOD_PX = 3.0;
+const float MASK_PERIOD_PX = 3.0;
+const float HUM_HZ = 0.11;
+
+// 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)));
+}
+
+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)));
+}
+
+vec3 scene(vec2 uv) {
+ return toLinear(texture(iChannel0, uv).rgb);
+}
+
+vec3 brightPass(vec2 uv) {
+ vec3 c = scene(uv);
+ float peak = max(c.r, max(c.g, c.b));
+ return c * smoothstep(bloomThreshold(), bloomThreshold() + BLOOM_SOFTNESS, peak);
+}
+
+// Interleaved gradient noise: a dither with no visible pattern.
+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 size = iResolution.xy;
+ vec2 texel = 1.0 / size;
+ vec2 uv = fragCoord / size;
+ vec2 cc = uv * 2.0 - 1.0;
+ float r2 = dot(cc, cc);
+
+ // The beam converges least at the corners: red and blue drift apart
+ // there, by a third of a pixel.
+ 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 * 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 * 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 - 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 - 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;
+ fragColor = vec4(clamp(srgb, 0.0, 1.0), texture(iChannel0, uv).a);
+}
diff --git a/shaders/post/prefix.glsl b/shaders/post/prefix.glsl
new file mode 100644
index 00000000..e718a98f
--- /dev/null
+++ b/shaders/post/prefix.glsl
@@ -0,0 +1,74 @@
+#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;
+ uniform vec3 iPalette[256];
+ 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.
+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
+#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
diff --git a/shaders/prebuilt/crt.frag.glsl b/shaders/prebuilt/crt.frag.glsl
deleted file mode 100644
index b0b0b93b..00000000
--- a/shaders/prebuilt/crt.frag.glsl
+++ /dev/null
@@ -1,175 +0,0 @@
-#version 450
-
-// The Crt builtin's post-process. Screen point cc shows the scene at
-// uv' = cc*(1 + BARREL*r2), and src/gui/crt.zig maps mouse input through that
-// same transform — keep them equal or clicks drift near the edges.
-
-layout(set = 2, binding = 0) uniform sampler2D u_scene;
-layout(std140, set = 3, binding = 0) uniform CrtUniforms {
- float time_seconds;
- float frame;
- vec2 viewport;
- // x = CRT, y = ripple, z = glitch. One scene pass can combine them.
- vec4 effects;
-} u_crt;
-
-layout(location = 0) out vec4 o_col;
-
-const float TAU = 6.28318530718;
-const float BARREL = 0.016; // MUST match src/gui/crt.zig barrel
-const float EDGE_SOFTNESS_PX = 3.5;
-const float CHROMA_PX = 0.28; // radial R/B separation in physical pixels at r2=1
-const float BLOOM_RADIUS_PX = 1.75;
-const float BLOOM_THRESHOLD = 0.60; // linear-light channel peak
-const float BLOOM_SOFTNESS = 0.25;
-const float BLOOM_STRENGTH = 0.045;
-const float SCAN_PERIOD_PX = 3.0;
-const float SCAN_STRENGTH = 0.055;
-const float MASK_PERIOD_PX = 3.0;
-const float MASK_STRENGTH = 0.015;
-const float VIGNETTE_STRENGTH = 0.11; // 11% only at the extreme corners
-const float HUM_STRENGTH = 0.0025;
-const float NOISE_STRENGTH = 0.0020;
-const float EXPOSURE = 1.012;
-
-vec3 srgbToLinear(vec3 c) {
- vec3 low = c / 12.92;
- vec3 high = pow((c + 0.055) / 1.055, vec3(2.4));
- return mix(high, low, lessThanEqual(c, vec3(0.04045)));
-}
-
-vec3 linearToSrgb(vec3 c) {
- c = max(c, vec3(0.0));
- vec3 low = c * 12.92;
- vec3 high = 1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055;
- return mix(high, low, lessThanEqual(c, vec3(0.0031308)));
-}
-
-vec3 sceneLinear(vec2 uv) {
- return srgbToLinear(texture(u_scene, uv).rgb);
-}
-
-vec3 brightPass(vec2 uv) {
- vec3 c = sceneLinear(uv);
- float peak = max(c.r, max(c.g, c.b));
- return c * smoothstep(BLOOM_THRESHOLD, BLOOM_THRESHOLD + BLOOM_SOFTNESS, peak);
-}
-
-float noiseAt(vec2 p) {
- vec3 q = fract(vec3(p.xyx) * 0.1031);
- q += dot(q, q.yzx + 33.33);
- return fract((q.x + q.y) * q.z);
-}
-
-// The non-CRT scene effects deliberately distort the source coordinates,
-// rather than remapping the final colors. Themes retain their palette and the
-// effects remain composable with the linear-light CRT treatment below.
-vec2 sceneUv(vec2 uv) {
- if (u_crt.effects.y > 0.5) {
- vec2 centered = uv - 0.5;
- float radius = length(centered);
- float envelope = 1.0 - smoothstep(0.04, 0.72, radius);
- float wave = sin(radius * 42.0 - u_crt.time_seconds * 5.2);
- uv += centered / max(radius, 0.00001) * wave * envelope * 0.0032;
- }
- if (u_crt.effects.z > 0.5) {
- float band = floor(uv.y * 96.0);
- float seed = noiseAt(vec2(band, floor(u_crt.time_seconds * 13.0)));
- float tear = smoothstep(0.955, 1.0, seed);
- uv.x += (noiseAt(vec2(seed, band)) - 0.5) * tear * 0.020;
- }
- return uv;
-}
-
-// The scene, ALPHA INCLUDED: with a see-through ground the grid arrives
-// premultiplied and partly empty, and a pass that dropped .a would turn the
-// desktop behind a `*_transparent` theme into opaque black the moment Crt,
-// Ripple or Glitch came on.
-vec4 sceneSrgb(vec2 uv) {
- vec2 warped = sceneUv(uv);
- vec4 center = texture(u_scene, warped);
- if (u_crt.effects.z <= 0.5) return center;
-
- float band = floor(warped.y * 96.0);
- float seed = noiseAt(vec2(band, floor(u_crt.time_seconds * 13.0)));
- float tear = smoothstep(0.955, 1.0, seed);
- vec2 chroma = vec2((0.35 + 1.25 * tear) / u_crt.viewport.x, 0.0);
- return vec4(
- texture(u_scene, warped + chroma).r,
- center.g,
- texture(u_scene, warped - chroma).b,
- center.a
- );
-}
-
-vec3 effectSceneLinear(vec2 uv) {
- return srgbToLinear(sceneSrgb(uv).rgb);
-}
-
-void main() {
- vec2 size = u_crt.viewport;
- vec2 texel = 1.0 / size;
- vec2 cc = gl_FragCoord.xy / size * 2.0 - 1.0;
- float r2 = dot(cc, cc);
- vec2 uv = cc * (1.0 + BARREL * r2 * u_crt.effects.x) * 0.5 + 0.5;
-
- // Ripple and glitch are useful without the CRT. They only move samples;
- // skip every tube-specific light/mask/exposure adjustment.
- if (u_crt.effects.x <= 0.5) {
- // The scene texture is already sRGB. Avoid a needless transfer-curve
- // round trip so a coordinate-only effect preserves theme bytes.
- vec4 s = sceneSrgb(uv);
- o_col = vec4(clamp(s.rgb, 0.0, 1.0), clamp(s.a, 0.0, 1.0));
- return;
- }
-
- vec3 col = vec3(0.0);
- // Outside the tube nothing is drawn, so nothing is covered either: the
- // old opaque black there would have punched a rectangle out of the
- // compositor's backdrop.
- float alpha = 0.0;
- float edge = min(min(uv.x, uv.y), min(1.0 - uv.x, 1.0 - uv.y));
- if (edge > 0.0) {
- vec3 center = effectSceneLinear(uv);
- vec2 chroma = cc * (CHROMA_PX * r2) * texel;
- // Each radial sample follows the same ripple/glitch path from its own
- // pre-warp coordinate. This is also how the Metal kernel composes the
- // effects; sampling a once-warped center here made combined effects
- // diverge between the two GUI backends.
- col = vec3(
- effectSceneLinear(uv + chroma).r,
- center.g,
- effectSceneLinear(uv - chroma).b
- );
-
- vec2 bloom_px = texel * BLOOM_RADIUS_PX;
- vec3 bloom = brightPass(uv + vec2(bloom_px.x, 0.0)) +
- brightPass(uv - vec2(bloom_px.x, 0.0)) +
- brightPass(uv + vec2(0.0, bloom_px.y)) +
- brightPass(uv - vec2(0.0, bloom_px.y));
- col += bloom * (0.25 * BLOOM_STRENGTH);
-
- // The mask has unit mean and the scan loss stays small; neither needs
- // the old global lift that remapped every theme toward white.
- float scan_wave = 0.5 + 0.5 * cos(gl_FragCoord.y * TAU / SCAN_PERIOD_PX);
- col *= 1.0 - SCAN_STRENGTH * scan_wave * scan_wave;
- vec3 mask = 1.0 + MASK_STRENGTH * cos(
- gl_FragCoord.x * TAU / MASK_PERIOD_PX + vec3(0.0, TAU / 3.0, 2.0 * TAU / 3.0)
- );
- col *= mask;
-
- vec2 edge_px = min(uv, 1.0 - uv) * size;
- float tube = smoothstep(0.0, EDGE_SOFTNESS_PX, min(edge_px.x, edge_px.y));
- 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 - u_crt.time_seconds * 0.11) * TAU);
- col *= tube * vignette * hum * EXPOSURE;
- // The tube's edge falloff dims coverage as well as colour; everything
- // else here is a light adjustment and leaves it alone.
- alpha = sceneSrgb(uv).a * tube;
-
- float luma = dot(col, vec3(0.2126, 0.7152, 0.0722));
- vec2 noise_seed = gl_FragCoord.xy + vec2(u_crt.frame * 17.0, u_crt.frame * 59.0);
- col += (noiseAt(noise_seed) - 0.5) * NOISE_STRENGTH * (0.15 + 0.85 * clamp(luma, 0.0, 1.0));
- }
- o_col = vec4(linearToSrgb(clamp(col, 0.0, 1.0)), clamp(alpha, 0.0, 1.0));
-}
diff --git a/shaders/prebuilt/crt.frag.spv b/shaders/prebuilt/crt.frag.spv
deleted file mode 100644
index f0e14627..00000000
--- a/shaders/prebuilt/crt.frag.spv
+++ /dev/null
Binary files differ
diff --git a/shaders/prebuilt/crt.vert.glsl b/shaders/prebuilt/crt.vert.glsl
deleted file mode 100644
index 4e15fcdf..00000000
--- a/shaders/prebuilt/crt.vert.glsl
+++ /dev/null
@@ -1,9 +0,0 @@
-#version 450
-
-// CRT post-process pass: one fullscreen triangle from gl_VertexIndex, no
-// vertex buffer. The fragment shader derives uv from gl_FragCoord.
-
-void main() {
- vec2 p = vec2(float((gl_VertexIndex << 1) & 2), float(gl_VertexIndex & 2));
- gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
-}
diff --git a/shaders/prebuilt/decor.frag.glsl b/shaders/prebuilt/decor.frag.glsl
new file mode 100644
index 00000000..4c2bd6d8
--- /dev/null
+++ b/shaders/prebuilt/decor.frag.glsl
@@ -0,0 +1,24 @@
+#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.
+
+layout(std140, set = 3, binding = 0) uniform UiUniforms {
+ float background_opacity;
+} u_ui;
+
+layout(location = 1) in vec3 v_fg;
+layout(location = 2) in vec3 v_bg;
+layout(location = 5) flat in vec4 v_clip;
+
+layout(location = 0) out vec4 o_col;
+
+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);
+}
diff --git a/shaders/prebuilt/decor.frag.spv b/shaders/prebuilt/decor.frag.spv
new file mode 100644
index 00000000..7e162f5a
--- /dev/null
+++ 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
new file mode 100644
index 00000000..c2cadfa2
--- /dev/null
+++ b/shaders/prebuilt/post-crt.frag.glsl
@@ -0,0 +1,157 @@
+#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;
+ uniform vec3 iPalette[256];
+ 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.
+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
+#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
+// Crt: a slot-mask tube's light, with nothing that moves a pixel. There is
+// no barrel: every click lands where it is drawn, rails and grips at the
+// window's edges included. What is left is light: a beam profile for the
+// scanlines, an aperture mask, a soft bloom of the brightest ink, a faint
+// vignette and the hum of a live tube. Everything is worked out in linear
+// light and dithered back into 8 bits, so the vignette never bands. It is a
+// Shadertoy file: pardes puts its prefix before it (shaders/post/prefix.glsl).
+
+const float TAU = 6.28318530718;
+// 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 SCAN_PERIOD_PX = 3.0;
+const float MASK_PERIOD_PX = 3.0;
+const float HUM_HZ = 0.11;
+
+// 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)));
+}
+
+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)));
+}
+
+vec3 scene(vec2 uv) {
+ return toLinear(texture(iChannel0, uv).rgb);
+}
+
+vec3 brightPass(vec2 uv) {
+ vec3 c = scene(uv);
+ float peak = max(c.r, max(c.g, c.b));
+ return c * smoothstep(bloomThreshold(), bloomThreshold() + BLOOM_SOFTNESS, peak);
+}
+
+// Interleaved gradient noise: a dither with no visible pattern.
+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 size = iResolution.xy;
+ vec2 texel = 1.0 / size;
+ vec2 uv = fragCoord / size;
+ vec2 cc = uv * 2.0 - 1.0;
+ float r2 = dot(cc, cc);
+
+ // The beam converges least at the corners: red and blue drift apart
+ // there, by a third of a pixel.
+ 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 * 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 * 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 - 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 - 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;
+ fragColor = vec4(clamp(srgb, 0.0, 1.0), texture(iChannel0, uv).a);
+}
diff --git a/shaders/prebuilt/post-crt.frag.spv b/shaders/prebuilt/post-crt.frag.spv
new file mode 100644
index 00000000..6599abd9
--- /dev/null
+++ b/shaders/prebuilt/post-crt.frag.spv
Binary files differ
diff --git a/shaders/prebuilt/post.vert.glsl b/shaders/prebuilt/post.vert.glsl
new file mode 100644
index 00000000..86739a65
--- /dev/null
+++ b/shaders/prebuilt/post.vert.glsl
@@ -0,0 +1,10 @@
+#version 450
+
+// A post pass (docs/render-pipeline.md §6): one fullscreen triangle from
+// gl_VertexIndex, no vertex buffer. The Shadertoy fragment shader works from
+// gl_FragCoord, y down, as its fragCoord.
+
+void main() {
+ vec2 p = vec2(float((gl_VertexIndex << 1) & 2), float(gl_VertexIndex & 2));
+ gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
+}
diff --git a/shaders/prebuilt/crt.vert.spv b/shaders/prebuilt/post.vert.spv
index 8a75ebb3..8a75ebb3 100644
--- a/shaders/prebuilt/crt.vert.spv
+++ b/shaders/prebuilt/post.vert.spv
Binary files differ
diff --git a/shaders/prebuilt/ui.frag.glsl b/shaders/prebuilt/ui.frag.glsl
index 3c366602..0b099db3 100644
--- a/shaders/prebuilt/ui.frag.glsl
+++ b/shaders/prebuilt/ui.frag.glsl
@@ -17,6 +17,7 @@ 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;
@@ -31,6 +32,8 @@ float cellNoise(uint serial, uint col, uint row) {
}
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 a = texture(u_atlas, v_uv).r;
bool oldLayer = (v_effect.x & 0x80000000u) != 0u;
// A block cursor is foreground chrome even though its fill occupies the
diff --git a/shaders/prebuilt/ui.frag.spv b/shaders/prebuilt/ui.frag.spv
index 120438e7..033c10ab 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 d23b609c..c1779add 100644
--- a/shaders/prebuilt/ui.vert.glsl
+++ b/shaders/prebuilt/ui.vert.glsl
@@ -19,12 +19,17 @@ layout(location = 5) in vec4 a_present_rect;
// 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
+// drops what lies outside it. x1 < x0 is none. A vertical transition clips
+// its pane's instances to the box the pane is growing into.
+layout(location = 7) in vec4 a_clip;
layout(location = 0) out vec2 v_uv;
layout(location = 1) out vec3 v_fg;
layout(location = 2) out vec3 v_bg;
layout(location = 3) out vec2 v_cell_uv;
layout(location = 4) flat out uvec4 v_effect;
+layout(location = 5) flat out vec4 v_clip;
void main() {
vec2 pos;
@@ -70,5 +75,6 @@ void main() {
v_fg = a_fg;
v_bg = a_bg;
v_effect = a_effect;
+ v_clip = a_clip;
gl_Position = vec4(pos, 0.0, 1.0);
}
diff --git a/shaders/prebuilt/ui.vert.spv b/shaders/prebuilt/ui.vert.spv
index 659049dd..619a9690 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 3c366602..0b099db3 100644
--- a/shaders/ui.frag.glsl
+++ b/shaders/ui.frag.glsl
@@ -17,6 +17,7 @@ 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;
@@ -31,6 +32,8 @@ float cellNoise(uint serial, uint col, uint row) {
}
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 a = texture(u_atlas, v_uv).r;
bool oldLayer = (v_effect.x & 0x80000000u) != 0u;
// A block cursor is foreground chrome even though its fill occupies the
diff --git a/shaders/ui.vert.glsl b/shaders/ui.vert.glsl
index d23b609c..c1779add 100644
--- a/shaders/ui.vert.glsl
+++ b/shaders/ui.vert.glsl
@@ -19,12 +19,17 @@ layout(location = 5) in vec4 a_present_rect;
// 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
+// drops what lies outside it. x1 < x0 is none. A vertical transition clips
+// its pane's instances to the box the pane is growing into.
+layout(location = 7) in vec4 a_clip;
layout(location = 0) out vec2 v_uv;
layout(location = 1) out vec3 v_fg;
layout(location = 2) out vec3 v_bg;
layout(location = 3) out vec2 v_cell_uv;
layout(location = 4) flat out uvec4 v_effect;
+layout(location = 5) flat out vec4 v_clip;
void main() {
vec2 pos;
@@ -70,5 +75,6 @@ void main() {
v_fg = a_fg;
v_bg = a_bg;
v_effect = a_effect;
+ v_clip = a_clip;
gl_Position = vec4(pos, 0.0, 1.0);
}