summaryrefslogtreecommitdiffstats
path: root/test_buffer.sh
blob: 20d32e65e443cb2c1702331a9525b71318a19a41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
set -euo pipefail

HOST=localhost
PORT=9000
TSV_SRC=test-vid

# ensure relatively predictable timing for spawn()
cargo build

PIDS=()
cleanup() {
    for pid in "${PIDS[@]}"; do
        kill "$pid" 2>/dev/null || true
    done
    wait 2>/dev/null
}
trap cleanup EXIT

spawn() {
    BIN="$1"
    shift
    cargo run --bin "$BIN" -- "$@" &
    PIDS+=($!)
}

spawn tsv-video-buffer --name "$TSV_SRC" --frames 60 -- \
    -f lavfi -i "testsrc=size=1920x1080:rate=60"
spawn wgsl-render

sleep 2

SHADER='
@group(1) @binding(0) var<uniform> time: f32;

@group(1) @binding(1) var video: texture_3d<f32>;
@group(1) @binding(2) var s: sampler;

@fragment
fn fs_main(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
    let dims = textureDimensions(video);
    let frame = fract(time / f32(dims.z));
    return textureSampleLevel(video, s, vec3f(uv, frame), 0.0);
}
'
oscsend "$HOST" "$PORT" /texture/tex1 s "$TSV_SRC"
oscsend "$HOST" "$PORT" /sampler/samp1 ss nearest repeat
oscsend "$HOST" "$PORT" /module/package::main s "$SHADER"
oscsend "$HOST" "$PORT" /entrypoint s package::main
oscsend "$HOST" "$PORT" /binding/package::main/video s /texture/tex1
oscsend "$HOST" "$PORT" /binding/package::main/s s /sampler/samp1

spawn tsv-view

echo "Playing video buffer (Ctrl+C to stop)..."
T=0
while true; do
    oscsend "$HOST" "$PORT" /uniform/package::main/time f "$T"
    T=$((T+1 % 60))
    sleep 0.016
done