Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

#162: bench/at-time checks that every still of a batch shows its own frame's time, as it does alone and as a scene stepped through every frame before it does. The fix (cdebceb9d9, a frame-pure load's plugin clock is pure: Time and the keyed rows are the frame drawn's) was held only by runtime/plugins' unit tests, and nothing drew the issue's case. Since #77 a still of a scene no plugin carries state for isn't stepped to, and the plugins' clock then never moved: every still sampled globals.time 0, and a batch's later frames drew its first frame's <Material> uniforms, which land as keyed rows. time.tsx is one 64 x 64 face with globals.time on its left half and a <Material> uniform the frame gives its time on its right, so the halves match only when Time is the frame's; its stepped twin carries an empty animation player, which Bevy carries from frame to frame, so its stills are stepped to as every still was in 0.1.0. The check draws both at 90, 30, 60 in one run and the pure one at 90 alone: each frame's halves must match, each pure frame must match the stepped one, 90 alone must match the batch's 90, the frames must move on, and the pure stills must step no frame. On the build from before the fix: globals.time 0 on every frame and the uniform frozen at the batch's first (0 and 135 levels on all three), up to 225 levels off the stepped scene. On main: 137, 188 and 225 on both halves of 30, 60 and 90, the same as the stepped scene, with no frame stepped.

shinyobjectz2a98bbcb0395
diff --git a/bench/at-time/check.sh b/bench/at-time/check.sh
new file mode 100755
index 00000000..a58e2e97
--- /dev/null
+++ b/bench/at-time/check.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+# #162: every still of a batch (--at A,B,C in one run) shows its own frame's time, as it does alone and as a scene
+# stepped through every frame before it does. Since #77 a still of a scene no plugin carries state for isn't stepped to,
+# and the plugins' clock then never moved: every still sampled globals.time 0, and a batch's later frames drew its
+# first frame's <Material> uniforms (they land as keyed rows). time.tsx's face shows globals.time on its left half and
+# a uniform the frame gives its time on its right, so the halves match only when Time is the frame's. Its "time"
+# composition is drawn at 90, 30, 60 in one run (the clock forwards and back) and at 90 alone, and must step no frame
+# to reach them; "stepped" (the same face with an animation player, so its stills are stepped to, as 0.1.0 drew every
+# still) at the same three. Each frame's halves must match within 1 level, each "time" frame must match the "stepped"
+# one and 90 alone the batch's 90 (within 1 level), and 90 must be brighter than 60 and 60 than 30. Exits 1 on a failure.
+# bench/at-time/check.sh (RAEA_BIN: the raea to run, default target/release/raea)
+cd "$(dirname "$0")/../.." || exit 2
+BIN=${RAEA_BIN:-$PWD/target/release/raea}
+export RAEA_SIGN=0 RAEA_MARK=0 RAEA_EXPORT_CACHE=0
+OUT=$(mktemp -d "${TMPDIR:-/tmp}/raea-at-time.XXXXXX")
+trap 'rm -rf "$OUT"' EXIT
+draw() { # NAME COMPOSITION AT: the frames in $OUT/NAME, the plugin clock's trace in $OUT/NAME.log
+ RAEA_PLUGIN_TRACE=1 "$BIN" render bench/at-time/time.tsx --composition "$2" --at "$3" -o "$OUT/$1" > "$OUT/$1.log" 2>&1 && [ -f "$OUT/$1/frame-00000.png" ] || { echo "FAIL $1: the render failed"; grep -v "^plugin clock" "$OUT/$1.log" | tail -4 | sed 's/^/ /'; exit 1; }
+}
+draw batch time 90,30,60
+draw lone time 90
+draw stepped stepped 90,30,60
+status=0
+fail() { echo "FAIL $*"; status=1; }
+steps() { grep -c "^plugin clock: .* step$" "$OUT/$1.log"; }
+(( $(steps batch) == 0 && $(steps lone) == 0 )) || fail "the time stills stepped $(steps batch) and $(steps lone) frames, wanted none (it has nothing a plugin carries)"
+(( $(steps stepped) > 0 )) || fail "the stepped stills stepped no frame, so they show nothing of the stepped clock"
+half() { magick "$1" -crop "24x48+$2+8" +repage -format "%[fx:int(255*mean.r+0.5)]" info:; } # FILE X: a half's grey
+apart() { magick "$1" "$2" -compose difference -composite -format "%[fx:int(255*maxima+0.5)]" info:; }
+k=0
+for at in 90 30 60; do
+ f=$(printf 'frame-%05d.png' $k)
+ for run in batch stepped; do
+ t=$(half "$OUT/$run/$f" 4) u=$(half "$OUT/$run/$f" 36)
+ (( t - u <= 1 && u - t <= 1 )) && echo "ok $run frame $at: globals.time's half $t, the uniform's $u" || fail "$run frame $at: globals.time's half is $t and the uniform's $u: Time isn't the frame's"
+ done
+ d=$(apart "$OUT/batch/$f" "$OUT/stepped/$f")
+ (( d <= 1 )) || fail "frame $at differs from the stepped scene's by up to $d levels"
+ eval "grey_$at=$(half "$OUT/batch/$f" 4)"
+ k=$((k + 1))
+done
+d=$(apart "$OUT/lone/frame-00000.png" "$OUT/batch/frame-00000.png")
+(( d <= 1 )) && echo "ok frame 90 alone matches the batch's frame 90" || fail "frame 90 alone differs from the batch's frame 90 by up to $d levels"
+(( grey_90 > grey_60 && grey_60 > grey_30 )) || fail "the batch's frames 30, 60 and 90 are $grey_30, $grey_60 and $grey_90: frozen, not moving on"
+[ $status = 0 ] && echo "PASS every still of a batch shows its own frame's time, as alone and as stepped to"
+exit $status
diff --git a/bench/at-time/time.tsx b/bench/at-time/time.tsx
new file mode 100644
index 00000000..151e750a
--- /dev/null
+++ b/bench/at-time/time.tsx
@@ -0,0 +1,35 @@
+// #162's composition, which bench/at-time/check.sh draws: one face, its left half grey by Bevy's globals.time and its
+// right half by a <Material> uniform the frame gives its time in seconds (each at a quarter of it), so the halves match
+// only when Time is the frame drawn's. "time" holds nothing a plugin carries, so a still draws only its own frame
+// (#77); "stepped" is the same face with an animation player on it (it plays nothing), which Bevy carries from frame
+// to frame, so a still is stepped to through every frame before it.
+import { Composition, registerRoot, useCurrentFrame } from "raea";
+import { Transform } from "raea/transform";
+import { Camera3d } from "raea/camera";
+import { Cuboid, Mesh3d } from "raea/mesh";
+import { BevyComponent } from "raea/3d";
+import { Material } from "@raea/render/bevy3d";
+
+function Shot({ stepped }: { stepped: boolean }) {
+ const f = useCurrentFrame();
+ return (
+ <>
+ <Mesh3d transform={Transform.fromXyz(0, 0, 0)}>
+ <Cuboid half_size={[2, 2, 0.01]} />
+ <Material fragment="time.wesl" uniforms={{ seconds: f / 30 }} />
+ {stepped ? <BevyComponent type="bevy_animation::AnimationPlayer" value={{ active_animations: {} }} /> : null}
+ </Mesh3d>
+ <Camera3d transform={Transform.fromXyz(0, 0, 3).lookingAt([0, 0, 0])} />
+ </>
+ );
+}
+
+const Pure = () => <Shot stepped={false} />;
+const Stepped = () => <Shot stepped />;
+
+registerRoot(() => (
+ <>
+ <Composition id="time" component={Pure} width={64} height={64} fps={30} durationInFrames={120} />
+ <Composition id="stepped" component={Stepped} width={64} height={64} fps={30} durationInFrames={120} />
+ </>
+));
diff --git a/bench/at-time/time.wesl b/bench/at-time/time.wesl
new file mode 100644
index 00000000..7e94c325
--- /dev/null
+++ b/bench/at-time/time.wesl
@@ -0,0 +1,13 @@
+// The left half grey by Bevy's globals.time, the right by the uniform the frame gives: each a quarter of its seconds.
+import bevy_pbr::render::{
+ mesh_view_bindings::globals,
+ forward_io::VertexOutput,
+};
+
+@group(constants::MATERIAL_BIND_GROUP) @binding(0) var<uniform> seconds: f32;
+
+@fragment
+fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
+ let t = select(seconds, globals.time, in.uv.x < 0.5) / 4.0;
+ return vec4<f32>(t, t, t, 1.0);
+}