diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-29 22:05:58 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:17 -0300 |
| commit | 813a0b2bf3c110f2287d7136f0dfc540c0978cd6 (patch) | |
| tree | 8250da85fde87d8cc4ccbbceaa304b1bed82be4e /shaders | |
| parent | 714da820136ac89d6a79ed0141e7325829ab8204 (diff) | |
| download | pardes-813a0b2bf3c110f2287d7136f0dfc540c0978cd6.tar.gz pardes-813a0b2bf3c110f2287d7136f0dfc540c0978cd6.zip | |
The GUI embeds its shaders' GLSL from shaders/ always: the 14 prebuilt copies, identical to their sources, go, and so does the label saying which was used
shaders/prebuilt/*.glsl were byte-identical to shaders/X.glsl or to prefix.glsl + post/X.glsl (checked with cmp, all 14), kept only so a -Dprebuilt-shaders build could name them; EffectCode and Config then labelled the GUI's shader source as live or prebuilt. The GUI embeds shaderSource (a concatenation, no glslc) either way now; the prebuilt SPIR-V stays, and zig build shaders refreshes only it. Config's report and EffectCode lose their GUI shader source line.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'shaders')
| -rw-r--r-- | shaders/prebuilt/bloom-down.frag.glsl | 39 | ||||
| -rw-r--r-- | shaders/prebuilt/bloom-up.frag.glsl | 26 | ||||
| -rw-r--r-- | shaders/prebuilt/decor.frag.glsl | 83 | ||||
| -rw-r--r-- | shaders/prebuilt/image.frag.glsl | 45 | ||||
| -rw-r--r-- | shaders/prebuilt/image.vert.glsl | 49 | ||||
| -rw-r--r-- | shaders/prebuilt/overlay.frag.glsl | 17 | ||||
| -rw-r--r-- | shaders/prebuilt/overlay.vert.glsl | 11 | ||||
| -rw-r--r-- | shaders/prebuilt/post-bloom.frag.glsl | 141 | ||||
| -rw-r--r-- | shaders/prebuilt/post-crt.frag.glsl | 186 | ||||
| -rw-r--r-- | shaders/prebuilt/post-grain.frag.glsl | 133 | ||||
| -rw-r--r-- | shaders/prebuilt/post-vignette.frag.glsl | 139 | ||||
| -rw-r--r-- | shaders/prebuilt/post.vert.glsl | 10 | ||||
| -rw-r--r-- | shaders/prebuilt/ui.frag.glsl | 93 | ||||
| -rw-r--r-- | shaders/prebuilt/ui.vert.glsl | 82 |
14 files changed, 0 insertions, 1054 deletions
diff --git a/shaders/prebuilt/bloom-down.frag.glsl b/shaders/prebuilt/bloom-down.frag.glsl deleted file mode 100644 index 3465926d..00000000 --- a/shaders/prebuilt/bloom-down.frag.glsl +++ /dev/null @@ -1,39 +0,0 @@ -#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-up.frag.glsl b/shaders/prebuilt/bloom-up.frag.glsl deleted file mode 100644 index 368076ed..00000000 --- a/shaders/prebuilt/bloom-up.frag.glsl +++ /dev/null @@ -1,26 +0,0 @@ -#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/decor.frag.glsl b/shaders/prebuilt/decor.frag.glsl deleted file mode 100644 index bb1ef0d6..00000000 --- a/shaders/prebuilt/decor.frag.glsl +++ /dev/null @@ -1,83 +0,0 @@ -#version 450 - -// 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; - 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/image.frag.glsl b/shaders/prebuilt/image.frag.glsl deleted file mode 100644 index 0cc1b2ee..00000000 --- a/shaders/prebuilt/image.frag.glsl +++ /dev/null @@ -1,45 +0,0 @@ -#version 450 - -layout(set = 2, binding = 0) uniform sampler2D u_image; -layout(std140, set = 3, binding = 0) uniform UiUniforms { - float background_opacity; -} u_ui; - -layout(location = 0) in vec2 v_uv; -layout(location = 1) in vec2 v_panel_uv; -layout(location = 2) flat in uvec4 v_effect; -layout(location = 0) out vec4 o_col; - -float cellNoise(uint serial, uint col, uint row) { - uint x = serial ^ (col * 0x9e3779b9u) ^ (row * 0x85ebca6bu); - x ^= x >> 16; - x *= 0x7feb352du; - x ^= x >> 15; - x *= 0x846ca68bu; - x ^= x >> 16; - return float(x & 0xffffu) / 65535.0; -} - -void main() { - vec4 source = texture(u_image, v_uv); - // Keep source coverage for destination subtraction; the pipeline scales - // source alpha by the same opacity through its alpha blend constant. - source.rgb *= clamp(u_ui.background_opacity, 0.0, 1.0); - uint effect = v_effect.x & 0x7fffffffu; - bool oldLayer = (v_effect.x & 0x80000000u) != 0u; - float progress = clamp(uintBitsToFloat(v_effect.y), 0.0, 1.0); - uvec2 dimensions = max( - uvec2(v_effect.w & 0xffffu, v_effect.w >> 16), - uvec2(1u)); - uvec2 cellCoord = min( - uvec2(floor(max(v_panel_uv, vec2(0.0)) * vec2(dimensions))), - dimensions - 1u); - float noise = cellNoise(v_effect.z, cellCoord.x, cellCoord.y); - if (effect == 3u) { - bool reveal = progress >= 1.0 || (progress > 0.0 && noise < progress); - if (oldLayer == reveal) discard; - o_col = source; - return; - } - o_col = source; -} diff --git a/shaders/prebuilt/image.vert.glsl b/shaders/prebuilt/image.vert.glsl deleted file mode 100644 index 04196ce4..00000000 --- a/shaders/prebuilt/image.vert.glsl +++ /dev/null @@ -1,49 +0,0 @@ -#version 450 - -// One instance per Surface image attachment. The CPU has already converted -// the pane's cell rectangle and the aspect-preserving contain fit to NDC. -layout(location = 0) in vec4 a_rect; // x0, y0, x1, y1 -layout(location = 1) in vec4 a_uv_rect; // u0, v0, u1, v1 -layout(location = 2) in vec4 a_panel_rect; -layout(location = 3) in vec4 a_present_rect; -layout(location = 4) in uvec4 a_effect; - -layout(location = 0) out vec2 v_uv; -layout(location = 1) out vec2 v_panel_uv; -layout(location = 2) flat out uvec4 v_effect; - -void main() { - vec2 pos; - int corner = gl_VertexIndex % 6; - if (corner == 0) { - pos = vec2(a_rect.x, a_rect.y); - v_uv = vec2(a_uv_rect.x, a_uv_rect.y); - } else if (corner == 1) { - pos = vec2(a_rect.z, a_rect.y); - v_uv = vec2(a_uv_rect.z, a_uv_rect.y); - } else if (corner == 2) { - pos = vec2(a_rect.z, a_rect.w); - v_uv = vec2(a_uv_rect.z, a_uv_rect.w); - } else if (corner == 3) { - pos = vec2(a_rect.x, a_rect.y); - v_uv = vec2(a_uv_rect.x, a_uv_rect.y); - } else if (corner == 4) { - pos = vec2(a_rect.z, a_rect.w); - v_uv = vec2(a_uv_rect.z, a_uv_rect.w); - } else { - pos = vec2(a_rect.x, a_rect.w); - v_uv = vec2(a_uv_rect.x, a_uv_rect.w); - } - v_panel_uv = v_uv; - uint effect = a_effect.x & 0x7fffffffu; - if (effect != 0u) { - vec2 panel_size = a_panel_rect.zw - a_panel_rect.xy; - panel_size.x = abs(panel_size.x) < 0.000001 ? 0.000001 : panel_size.x; - panel_size.y = abs(panel_size.y) < 0.000001 ? -0.000001 : panel_size.y; - v_panel_uv = (pos - a_panel_rect.xy) / panel_size; - if (effect == 1u || effect == 2u || effect == 5u) - pos = mix(a_present_rect.xy, a_present_rect.zw, v_panel_uv); - } - v_effect = a_effect; - gl_Position = vec4(pos, 0.0, 1.0); -} diff --git a/shaders/prebuilt/overlay.frag.glsl b/shaders/prebuilt/overlay.frag.glsl deleted file mode 100644 index b5ac8d5a..00000000 --- a/shaders/prebuilt/overlay.frag.glsl +++ /dev/null @@ -1,17 +0,0 @@ -#version 450 - -layout(std140, set = 3, binding = 0) uniform UiUniforms { - float background_opacity; -} u_ui; - -layout(location = 0) in vec4 v_color; - -layout(location = 0) out vec4 o_col; - -void main() { - // Preserve shape coverage for destination subtraction. The pipeline uses - // the matching opacity blend constant for source alpha, so graphics laid - // over a background with the same opacity do not accumulate opaque seams. - // Text/cursor draw groups bind opacity 1 instead. - o_col = vec4(v_color.rgb * clamp(u_ui.background_opacity, 0.0, 1.0), v_color.a); -} diff --git a/shaders/prebuilt/overlay.vert.glsl b/shaders/prebuilt/overlay.vert.glsl deleted file mode 100644 index 5f6be593..00000000 --- a/shaders/prebuilt/overlay.vert.glsl +++ /dev/null @@ -1,11 +0,0 @@ -#version 450 - -layout(location = 0) in vec2 a_pos; -layout(location = 1) in vec4 a_color; - -layout(location = 0) out vec4 v_color; - -void main() { - v_color = a_color; - gl_Position = vec4(a_pos, 0.0, 1.0); -} diff --git a/shaders/prebuilt/post-bloom.frag.glsl b/shaders/prebuilt/post-bloom.frag.glsl deleted file mode 100644 index a84cf88a..00000000 --- a/shaders/prebuilt/post-bloom.frag.glsl +++ /dev/null @@ -1,141 +0,0 @@ -#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-crt.frag.glsl b/shaders/prebuilt/post-crt.frag.glsl deleted file mode 100644 index ca44d014..00000000 --- a/shaders/prebuilt/post-crt.frag.glsl +++ /dev/null @@ -1,186 +0,0 @@ -#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 -// 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. - // 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 * 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); - 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-grain.frag.glsl b/shaders/prebuilt/post-grain.frag.glsl deleted file mode 100644 index a4a02e99..00000000 --- a/shaders/prebuilt/post-grain.frag.glsl +++ /dev/null @@ -1,133 +0,0 @@ -#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-vignette.frag.glsl b/shaders/prebuilt/post-vignette.frag.glsl deleted file mode 100644 index d5737901..00000000 --- a/shaders/prebuilt/post-vignette.frag.glsl +++ /dev/null @@ -1,139 +0,0 @@ -#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.vert.glsl b/shaders/prebuilt/post.vert.glsl deleted file mode 100644 index 86739a65..00000000 --- a/shaders/prebuilt/post.vert.glsl +++ /dev/null @@ -1,10 +0,0 @@ -#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/ui.frag.glsl b/shaders/prebuilt/ui.frag.glsl deleted file mode 100644 index 51ec5b8c..00000000 --- a/shaders/prebuilt/ui.frag.glsl +++ /dev/null @@ -1,93 +0,0 @@ -#version 450 - -// Sample the glyph atlas (R = coverage 0..1) and mix the cell's bg up to its fg -// by that coverage. Output is PREMULTIPLIED: an opaque cell is unchanged. -// WindowOpacity changes only the ground's coverage, never the glyph's ink. -// A cell whose background is the see-through ground (config.gui_transparent, -// a theme with no bg of its own) still contributes only its ink, at the ink's -// own coverage, so the compositor keeps the rest. - -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; -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; - -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 - // cell background: keep it visible at WindowOpacity 0. Otherwise a clear - // theme ground has no coverage and ordinary backgrounds use the setting. - // The three high flags are shared with ui.vert.glsl and src/gui/gui.zig. - 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 & 0x07ffffffu; - float progress = clamp(uintBitsToFloat(v_effect.y), 0.0, 1.0); - - // 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. - 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; - // v_effect.z: how far its pane's text has moved the dots (G13's - // parallax), in pixels, as a float's bits (0 without). - vec2 at = gl_FragCoord.xy - vec2(0.0, uintBitsToFloat(v_effect.z)); - vec2 d = mod(at, 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 = 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) { - if (!oldLayer) { - o_col = cell; - return; - } - if (progress >= 1.0) discard; - o_col = cell * (1.0 - progress); - return; - } - - // FreeType's hinted grayscale bitmap is already the intended coverage. - // Preserve it exactly; weight-changing gamma hacks blur small stems. - o_col = cell; -} diff --git a/shaders/prebuilt/ui.vert.glsl b/shaders/prebuilt/ui.vert.glsl deleted file mode 100644 index de22adee..00000000 --- a/shaders/prebuilt/ui.vert.glsl +++ /dev/null @@ -1,82 +0,0 @@ -#version 450 - -// Terminal cell renderer. The CPU uploads one instance per visible cell; this -// shader expands each instance into a two-triangle quad with gl_VertexIndex. -// The fragment shader mixes fg/bg by the atlas's alpha (a glyph mask in the R -// channel), so background fills and glyph foregrounds draw in a single pass. - -layout(location = 0) in vec4 a_rect; // x0, y0, x1, y1 -layout(location = 1) in vec4 a_uv_rect; // u0, v0, u1, v1 -layout(location = 2) in vec3 a_fg; -layout(location = 3) in vec3 a_bg; -// Final and presented panel rectangles in NDC. The CPU still uploads logical -// final cells; this shader is the only place transition geometry is applied. -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 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 -// 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; - vec2 uv; - int corner = gl_VertexIndex % 6; - if (corner == 0) { - pos = vec2(a_rect.x, a_rect.y); - uv = vec2(a_uv_rect.x, a_uv_rect.y); - v_cell_uv = vec2(0.0, 0.0); - } else if (corner == 1) { - pos = vec2(a_rect.z, a_rect.y); - uv = vec2(a_uv_rect.z, a_uv_rect.y); - v_cell_uv = vec2(1.0, 0.0); - } else if (corner == 2) { - pos = vec2(a_rect.z, a_rect.w); - uv = vec2(a_uv_rect.z, a_uv_rect.w); - v_cell_uv = vec2(1.0, 1.0); - } else if (corner == 3) { - pos = vec2(a_rect.x, a_rect.y); - uv = vec2(a_uv_rect.x, a_uv_rect.y); - v_cell_uv = vec2(0.0, 0.0); - } else if (corner == 4) { - pos = vec2(a_rect.z, a_rect.w); - uv = vec2(a_uv_rect.z, a_uv_rect.w); - v_cell_uv = vec2(1.0, 1.0); - } else { - pos = vec2(a_rect.x, a_rect.w); - uv = vec2(a_uv_rect.x, a_uv_rect.w); - v_cell_uv = vec2(0.0, 1.0); - } - - 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. - vec2 panel_size = a_panel_rect.zw - a_panel_rect.xy; - panel_size.x = abs(panel_size.x) < 0.000001 ? 0.000001 : panel_size.x; - panel_size.y = abs(panel_size.y) < 0.000001 ? -0.000001 : panel_size.y; - vec2 within = (pos - a_panel_rect.xy) / panel_size; - pos = mix(a_present_rect.xy, a_present_rect.zw, within); - } - v_uv = uv; - v_fg = a_fg; - v_bg = a_bg; - v_effect = a_effect; - v_clip = a_clip; - gl_Position = vec4(pos, 0.0, 1.0); -} |
