diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-17 00:15:15 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:01 -0300 |
| commit | 9bd77e54943d954291b5faef287ccca5dcebd7a4 (patch) | |
| tree | 3f2d628781441568620b8108fab920713f26f649 /examples/spheres/shaders/trail.vert | |
| parent | e997fc3e6b312b30f5af90012fc22365bab701d4 (diff) | |
| download | sketchbook-9bd77e54943d954291b5faef287ccca5dcebd7a4.tar.gz sketchbook-9bd77e54943d954291b5faef287ccca5dcebd7a4.zip | |
examples: micscope and spheres come home, as they were, building
Both lived outside any repository, beside sketchbook, with manifests that
pointed at ../01-drat-meout/lib/sketchbook, which no longer exists. They
are copied into examples/micscope and examples/spheres (their sources,
shaders, tests, test material and web icons; not their caches, builds,
packages, state files or .gitignore, which the root's covers), their
manifests depend on "../.." as the other examples do, and their
READMEs link sketchbook there. Nothing else changed: both build against
today's library and pass their own zig build test (micscope 62/62 steps,
11/11 tests, its transport, record, render and tuner scripts; spheres
75/75 steps, 3/3 tests, its play script). The originals are untouched.
micscope's test/reference.flac (3.7 MiB, CC BY-SA 3.0, credited in its
test/README.md) is the rendering reference its render script opens. The
README lists both examples.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'examples/spheres/shaders/trail.vert')
| -rw-r--r-- | examples/spheres/shaders/trail.vert | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/examples/spheres/shaders/trail.vert b/examples/spheres/shaders/trail.vert new file mode 100644 index 0000000..7f9f35c --- /dev/null +++ b/examples/spheres/shaders/trail.vert @@ -0,0 +1,48 @@ +#version 450 +#extension GL_GOOGLE_include_directive : require +// System 0's trails: per body, a ribbon through its last positions, +// `radius` pixels wide at the newest and tapering to nothing at the oldest, +// fading as it goes. Six vertices per segment; segments past what has been +// filled, or across a jump, collapse to nothing. +layout(location = 0) out vec4 color; + +#include "SkyView.glsl" + +layout(set = 0, binding = 0) readonly buffer Trail { vec2 trail[]; }; + +// Match layouts.zig and main.zig's palette. +const uint TRAIL = 1024u; +const vec3 palette[3] = vec3[](vec3(0.40, 0.85, 1.0), vec3(1.0, 0.45, 0.82), vec3(1.0, 0.80, 0.35)); + +void main() { + uint segment = uint(gl_VertexIndex) / 6u; + uint corner = uint(gl_VertexIndex) % 6u; + uint body = segment / (TRAIL - 1u); + uint age = segment % (TRAIL - 1u); + if (age + 1u >= u.filled) { + gl_Position = vec4(0.0, 0.0, 2.0, 1.0); + color = vec4(0.0); + return; + } + // Corners 0, 3, 5 at the newer end, 1, 2, 4 at the older; 0, 1, 3 on + // one side, 2, 4, 5 on the other. + bool older = corner == 1u || corner == 2u || corner == 4u; + bool side = corner == 2u || corner == 4u || corner == 5u; + uint a = (u.head + TRAIL - age) % TRAIL; + uint b = (u.head + TRAIL - age - 1u) % TRAIL; + // A jump (system 0 stepping into a snapshot) breaks the trail. + if (distance(trail[body * TRAIL + a], trail[body * TRAIL + b]) > u.gap) { + gl_Position = vec4(0.0, 0.0, 2.0, 1.0); + color = vec4(0.0); + return; + } + vec2 pa = (trail[body * TRAIL + a] - u.center) / u.per_pixel; + vec2 pb = (trail[body * TRAIL + b] - u.center) / u.per_pixel; + vec2 along = pb - pa; + float len = length(along); + vec2 normal = len > 1e-4 ? vec2(-along.y, along.x) / len : vec2(0.0, 1.0); + float fade = 1.0 - float(older ? age + 1u : age) / float(u.filled); + vec2 at = (older ? pb : pa) + normal * (side ? 1.0 : -1.0) * u.radius * fade; + gl_Position = vec4(at * 2.0 / u.size, 0.0, 1.0); + color = vec4(palette[body], 1.0) * u.alpha * fade * fade; +} |
