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/lookahead.comp | |
| 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/lookahead.comp')
| -rw-r--r-- | examples/spheres/shaders/lookahead.comp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/examples/spheres/shaders/lookahead.comp b/examples/spheres/shaders/lookahead.comp new file mode 100644 index 0000000..75902d7 --- /dev/null +++ b/examples/spheres/shaders/lookahead.comp @@ -0,0 +1,52 @@ +#version 450 +#extension GL_GOOGLE_include_directive : require +// Futures of system 0, one per thread, for spheres as an instrument: from +// the preset's start, alternative 0 exactly as system 0 began and the +// others nudged by growing amounts, so where the system is chaotic their +// futures fan out. Each is integrated ahead `count` samples a frame (with +// physics.glsl, as the live system is), leaving a snapshot every +// `sample_dt` and the chord its bodies would sing there (voices.glsl). A +// chord chosen then finds the nearest time it plays, in any of them. +layout(local_size_x = 32) in; + +#include "LookParams.glsl" +#include "physics.glsl" +#include "voices.glsl" + +// Where each alternative has got to: 3 vec4s each (position xy, velocity zw). +layout(set = 1, binding = 0) buffer State { vec4 state[]; }; +// Snapshots, sample-major: sample t of alternative a at 3 (t * K + a). +layout(set = 1, binding = 1) buffer Snapshots { vec4 snapshots[]; }; +// Chords, sample-major: t * K + a. +layout(set = 1, binding = 2) buffer Chords { uint chords[]; }; + +// Match main.zig's leapfrog step. +const float BASE_STEP = 0.004; + +void main() { + uint alt = gl_GlobalInvocationID.x; + if (alt >= u.alternatives) return; + vec3 m = u.masses.xyz; + vec2 p[3]; + vec2 v[3]; + for (int i = 0; i < 3; i++) { + vec4 b = state[3u * alt + uint(i)]; + p[i] = b.xy; + v[i] = b.zw; + } + vec2 a[3]; + accelerations(p, m, u.softening, a); + Mapping map = Mapping(u.base, u.speed_ref, u.depth_scale, u.couple_scale, u.quantize); + uint steps = uint(ceil(u.sample_dt / BASE_STEP)); + float dt = u.sample_dt / float(steps); + for (uint t = u.first; t < min(u.first + u.count, u.horizon); t++) { + uint at = t * u.alternatives + alt; + for (int i = 0; i < 3; i++) snapshots[3u * at + uint(i)] = vec4(p[i], v[i]); + vec4 sung[3]; + vec4 coupled[3]; + sing(p, v, map, sung, coupled); + chords[at] = chordOf(sung) | voicing(sung, coupled); + for (uint k = 0u; k < steps; k++) leapfrog(p, v, a, dt, m, u.softening, 256.0); + } + for (int i = 0; i < 3; i++) state[3u * alt + uint(i)] = vec4(p[i], v[i]); +} |
