summaryrefslogtreecommitdiff
path: root/addons/snake_shader/snake.frag
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-12 10:56:42 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commitf2b02c455f2bcdfb905a015eefbb630a28b4b12e (patch)
treec344c7ad42ec288dd5e1ebd0eb6d25f5aa2fbccc /addons/snake_shader/snake.frag
parentfc38c73c59f7855a4caad8aa4d3bb8e023309c13 (diff)
downloadpardes-f2b02c455f2bcdfb905a015eefbb630a28b4b12e.tar.gz
pardes-f2b02c455f2bcdfb905a015eefbb630a28b4b12e.zip
addons: an addon can hand the frontend a GPU scene (ABI 3.1), and a snake drawn by shaders does; a commit's patch keeps its own +Diff pane; a real ZLS checked through the window build
ABI 3.1 appends an optional `gpu` callback and its context to pa_paint: one self-contained sketchbook SGPU v1 scene for the pane, at most 4 MiB, copied during the call, the last successful call winning. The SDL frontend runs it on its own GPU through sketchbook's executor and composites its target texture into the pane; replicas carry the scene beside the authoritative pane frame; cells and rasters stay the fallback for terminals, older hosts and frontends without an executor. addons/snake_shader is such an addon (`zig build snake-shader`, the SnakeShader word: a board that follows its pane, buffered turns, a CRT look), with test/gpu_snake.py, test/gpu_snake_interaction.py and test/gpu_upgrade.py. Commit patches open as `+Diff-<short-hash>` and reuse only their own commit's pane, so another paged patch no longer replaces one already open. The language-server client looks in the standard per-user bin directory, which desktop launchers often leave out of PATH, and takes an empty answer that beats the startup progress notification onto the wire; test/real_zls.py checks imports, hover, references, rename previews, diagnostics and completion against a real ZLS from a private home. The dump's schema reader skips two fields older builds persisted, and a replica's shadow of a kind ticks when the authority's does. The reference, the guide, the building and setup notes and the changelog say so. The working copy as it stood on 2026-11-12; message written by Claude from the diff, at the author's request.
Diffstat (limited to 'addons/snake_shader/snake.frag')
-rw-r--r--addons/snake_shader/snake.frag52
1 files changed, 52 insertions, 0 deletions
diff --git a/addons/snake_shader/snake.frag b/addons/snake_shader/snake.frag
new file mode 100644
index 00000000..14896f2f
--- /dev/null
+++ b/addons/snake_shader/snake.frag
@@ -0,0 +1,52 @@
+#version 450
+layout(location = 0) in vec2 uv;
+layout(location = 0) out vec4 color;
+layout(std140, set = 3, binding = 0) uniform Board {
+ vec4 status; // dead, focused, target width, target height
+ vec4 points; // head xy, food xy
+ vec4 grid; // board size, hovered cell including walls
+ vec4 motion; // seconds, tile pixels, board offset xy
+ uvec4 rows[128];
+} board;
+float box(vec2 p, float size, float radius) {
+ vec2 d = abs(p) - size + radius;
+ return length(max(d, 0)) + min(max(d.x, d.y), 0) - radius;
+}
+void main() {
+ vec2 p = (uv * board.status.zw - board.motion.zw) / board.motion.y;
+ vec3 bg = vec3(.018, .028, .043);
+ float dim = board.status.y < .5 ? .6 : 1;
+ if (any(lessThan(p, vec2(0))) || any(greaterThanEqual(p, board.grid.xy + 2))) {
+ color = vec4(bg * dim, 1);
+ return;
+ }
+ ivec2 cell = ivec2(floor(p)) - 1;
+ vec2 local = fract(p) - .5;
+ vec3 ink = vec3(.10, .16, .23);
+ float dist = box(local, .43, .10);
+ bool inside = cell.x >= 0 && cell.x < int(board.grid.x) && cell.y >= 0 && cell.y < int(board.grid.y);
+ if (inside) {
+ dist = 1;
+ if ((board.rows[cell.y][cell.x / 32] & (1u << uint(cell.x % 32))) != 0u) {
+ ink = board.status.x > .5 ? vec3(.85, .12, .20) : vec3(.12, .78, .43);
+ dist = box(local, .44, .16);
+ if (all(equal(cell, ivec2(board.points.xy)))) ink *= 1.18;
+ } else if (all(equal(cell, ivec2(board.points.zw)))) {
+ ink = vec3(1, .42, .10) * (1 + .035 * sin(board.motion.x * 1.5707963));
+ dist = length(local) - .26;
+ } else {
+ bg += vec3(.008, .014, .018) * (1 - smoothstep(.44, .49, max(abs(local.x), abs(local.y))));
+ }
+ }
+ float aa = max(fwidth(dist), .002);
+ float coverage = 1 - smoothstep(-aa, aa, dist);
+ vec3 rgb = mix(bg + ink * .10 * exp(-max(dist, 0) * 8), ink, coverage);
+ if (board.grid.z >= 0) {
+ vec2 delta = p - (board.grid.zw + .5);
+ float halo = exp(-dot(delta, delta) * 2.5);
+ float rim = 1 - smoothstep(.015, .07, abs(box(local, .45, .09)));
+ bool hovered = all(equal(ivec2(floor(p)), ivec2(board.grid.zw)));
+ rgb += vec3(.12, .30, .36) * halo + (hovered ? vec3(.14, .32, .40) * rim : vec3(0));
+ }
+ color = vec4(rgb * dim, 1);
+}