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.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
raea light check holds each scene's first still on the traced paths (solari, gi), reports it under steady and fails when the light moved; steady's hold, report and line as functions the check calls
shinyobjectz487e62c97bde
diff --git a/docs/manual/reference/cli/light.md b/docs/manual/reference/cli/light.mdindex cbdbc3bc..53ae2b2b 100644--- a/docs/manual/reference/cli/light.md+++ b/docs/manual/reference/cli/light.md@@ -41,7 +41,9 @@ pixel or two wide and new every frame. A blotch is tens of pixels wide and driftquarter of a second or more: on Solari, the world cache lit by too few rays. The two are told apart by size: thedeviation in time of each 32-pixel square's mean luminance (`blotch`, percent of the mean) against each 8-pixelsquare's (`grain`). Grain alone gives a `spread` of 0.25, and blotches bring it toward 1. A run over `--max` fails,-`DIR/held/steady.png` shows where (white is 6%), and `steady.json` holds the numbers.+`DIR/held/steady.png` shows where (white is 6%), and `steady.json` holds the numbers. A light whose level moves over the held frames fails too (`drift`, more than 0.05 of a stop between the first and the last quarter measured): a cache gaining or losing energy the longer it runs.++`raea light check` holds each scene's first still on the traced paths (`solari`, `gi`) the same way, reports it under `steady`, and fails when one moved.```shraea light steady compositions/shots.tsx --composition court --frame 1188 -o out/steady/diff --git a/engine/light/src/lib.rs b/engine/light/src/lib.rsindex 1e037234..fbcb013e 100644--- a/engine/light/src/lib.rs+++ b/engine/light/src/lib.rs@@ -20,6 +20,10 @@ use serde_json::{json, Value};use std::path::{Path, PathBuf};use std::time::Instant;+/// The light paths that trace, whose light is built over frames and can move with nothing else moving.+const TRACED: [&str; 2] = ["solari", "gi"];+/// How many times a traced path's still is held for `steady`.+const HELD: usize = 96;pub const USAGE: &str = "raea light check SCENES.json -o DIR [--scene NAME] [--paths raster,traced-ao,solari,gi] [--spp N] [--fresh] | raea light steady EDIT.tsx --frame N [--composition ID] [--frames 96] [--max 1.5] -o DIR | raea light steady DIR [--max 1.5] (steady: frame N held, and whether its light holds still)";/// The light paths a check compares: RAEA_LIGHT's, and traced-ao, raster with systems/rt's traced occlusion in place@@ -280,6 +284,12 @@ fn check(scene: &Scene, paths: &[String], spp: u32, out: &Path, fresh: bool) ->r["flicker_raw"] = json!(metric::flicker(&got).map(|f| round(f, 100.0)));r["seconds_a_shot_frame"] = json!(round(secs as f32 / all.len() as f32, 100.0));}+ // a traced path's light held: the first still drawn again and again, and what still changes (steady.rs)+ if TRACED.contains(&path.as_str()) {+ let held = root.join(format!("{path}-held"));+ steady::hold(&scene.dir, &scene.file, Some(&scene.composition), &scene.stills[0].to_string(), HELD, &switches(path), &held)?;+ r["steady"] = steady::report(&held, None)?;+ }r["live"] = match &scene.live {// at the scene's size only: the live 3D draws at its composition's size whatever the stage's// (runtime/live scene_3d), so a smaller stage measured the same frame (11-17), and no switch draws it smaller@@ -336,7 +346,14 @@ pub fn light(args: &[String]) -> R<String> {std::fs::create_dir_all(&out).map_err(|e| e.to_string())?;let report = json!({ "scenes": reports });std::fs::write(out.join("report.json"), serde_json::to_string_pretty(&report).unwrap_or_default()).map_err(|e| e.to_string())?;- Ok(format!("{}{}", table(&reports), format_args!("raea light: wrote {}", out.join("report.json").display())))+ let said = format!("{}{}", table(&reports), format_args!("raea light: wrote {}", out.join("report.json").display()));+ // a traced path whose held frame's light moved fails the check: its distance to the reference is of a frame that+ // won't be the same the next time+ let moved: Vec<String> = reports.iter().flat_map(|r| r["paths"].as_object().into_iter().flatten().filter(|(_, p)| p["steady"]["steady"] == json!(false)).map(|(path, p)| format!("{} on {path}: {}", r["name"].as_str().unwrap_or(""), steady::line(&p["steady"])))).collect();+ if !moved.is_empty() {+ return Err(format!("{said}\nthe light doesn't hold still ({}). {}", moved.join("; "), steady::WHY));+ }+ Ok(said)}#[cfg(test)]diff --git a/engine/light/src/steady.rs b/engine/light/src/steady.rsindex 008970c1..2732c82c 100644--- a/engine/light/src/steady.rs+++ b/engine/light/src/steady.rs@@ -97,46 +97,69 @@ fn held(dir: &Path) -> R<Vec<PathBuf>> {Ok(v)}+/// Frame `frame` of a composition held for `n` frames into `out` (`raea render --hold`), run in `dir` under `env`.+pub fn hold(dir: &Path, file: &str, composition: Option<&str>, frame: &str, n: usize, env: &[(&str, String)], out: &Path) -> R<()> {+ let _ = std::fs::remove_dir_all(out);+ std::fs::create_dir_all(out).map_err(|e| format!("{}: {e}", out.display()))?;+ let mut cmd = std::process::Command::new(std::env::current_exe().map_err(|e| e.to_string())?);+ cmd.current_dir(dir).envs(env.iter().map(|(k, v)| (*k, v)));+ cmd.args(["render", file, "--hold", &format!("{frame}:{n}"), "-o"]).arg(format!("{}/", out.display()));+ if let Some(c) = composition {+ cmd.args(["--composition", c]);+ }+ let run = cmd.args(["--despite", "clips", "raea light steady measures light, not placement"]).output().map_err(|e| e.to_string())?;+ if !run.status.success() {+ let err = String::from_utf8_lossy(&run.stderr);+ return Err(format!("the held render failed: {}", err.lines().rev().take(4).collect::<Vec<_>>().into_iter().rev().collect::<Vec<_>>().join(" | ")));+ }+ Ok(())+}++/// The held frames of `dir` measured: DIR/steady.png and steady.json written, and the report, its "steady" saying+/// whether the light held (`max`: the blotch a run may show, percent; MAX when None).+pub fn report(dir: &Path, max: Option<f64>) -> R<Value> {+ let max = max.unwrap_or(MAX);+ // the second half: the first is the light building from nothing, which a render's lead-in covers+ let files = held(dir)?;+ let frames: Vec<Luma> = files[files.len() / 2..].iter().map(|p| metric::load(p)).collect::<R<_>>()?;+ let (mut report, map) = measure(&frames)?;+ let png = dir.join("steady.png");+ map.save(&png).map_err(|e| format!("{}: {e}", png.display()))?;+ let get = |k: &str| report[k].as_f64().unwrap_or(0.0);+ let ok = get("blotch") <= max && get("worst") <= max * 3.0 && get("drift").abs() <= MAX_DRIFT;+ report["max"] = json!(max);+ report["max_drift"] = json!(MAX_DRIFT);+ report["steady"] = json!(ok);+ report["picture"] = json!(png);+ std::fs::write(dir.join("steady.json"), serde_json::to_string_pretty(&report).unwrap_or_default()).map_err(|e| e.to_string())?;+ Ok(report)+}++/// A report as one line.+pub fn line(r: &Value) -> String {+ format!(+ "drift {} stops (max {}), blotch {}% (max {}), worst {}% at {},{}, grain {}%, spread {} over {} held frames; {}",+ r["drift"], r["max_drift"], r["blotch"], r["max"], r["worst"], r["worst_at"][0], r["worst_at"][1], r["grain"], r["spread"], r["frames"], r["picture"].as_str().unwrap_or("")+ )+}++/// What a light that doesn't hold still is told.+pub const WHY: &str = "On Solari this is the world cache lit by too few rays, or gaining or losing energy the longer it runs: bake it (cache.bake, then cache.load), or give it a longer history";+pub fn steady(args: &[String]) -> R<String> {let first = args.first().ok_or(format!("usage: {USAGE}"))?;- let max = flag(args, "--max").map(|m| m.parse::<f64>().map_err(|_| format!("--max takes a percent, not {m}"))).transpose()?.unwrap_or(MAX);+ let max = flag(args, "--max").map(|m| m.parse::<f64>().map_err(|_| format!("--max takes a percent, not {m}"))).transpose()?;let dir = if Path::new(first).is_dir() {PathBuf::from(first)} else {let frame = flag(args, "--frame").ok_or(format!("usage: {USAGE}"))?;let n: usize = flag(args, "--frames").map(|n| n.parse().map_err(|_| format!("--frames takes a count, not {n}"))).transpose()?.unwrap_or(96);let out = PathBuf::from(flag(args, "-o").ok_or(format!("usage: {USAGE}"))?).join("held");- let _ = std::fs::remove_dir_all(&out);- std::fs::create_dir_all(&out).map_err(|e| format!("{}: {e}", out.display()))?;- let mut cmd = std::process::Command::new(std::env::current_exe().map_err(|e| e.to_string())?);- cmd.args(["render", first, "--hold", &format!("{frame}:{n}"), "-o"]).arg(format!("{}/", out.display()));- if let Some(c) = flag(args, "--composition") {- cmd.args(["--composition", &c]);- }- let run = cmd.args(["--despite", "clips", "raea light steady measures light, not placement"]).output().map_err(|e| e.to_string())?;- if !run.status.success() {- let err = String::from_utf8_lossy(&run.stderr);- return Err(format!("the held render failed: {}", err.lines().rev().take(4).collect::<Vec<_>>().into_iter().rev().collect::<Vec<_>>().join(" | ")));- }+ hold(Path::new("."), first, flag(args, "--composition").as_deref(), &frame, n, &[], &out)?;out};- // the second half: the first is the light building from nothing, which a render's lead-in covers- let files = held(&dir)?;- let frames: Vec<Luma> = files[files.len() / 2..].iter().map(|p| metric::load(p)).collect::<R<_>>()?;- let (mut report, map) = measure(&frames)?;- let png = dir.join("steady.png");- map.save(&png).map_err(|e| format!("{}: {e}", png.display()))?;- let (blotch, worst) = (report["blotch"].as_f64().unwrap_or(0.0), report["worst"].as_f64().unwrap_or(0.0));- let drift = report["drift"].as_f64().unwrap_or(0.0);- let ok = blotch <= max && worst <= max * 3.0 && drift.abs() <= MAX_DRIFT;- report["max"] = json!(max);- report["steady"] = json!(ok);- std::fs::write(dir.join("steady.json"), serde_json::to_string_pretty(&report).unwrap_or_default()).map_err(|e| e.to_string())?;- let line = format!(- "drift {drift} stops (max {MAX_DRIFT}), blotch {blotch}% (max {max}), worst {worst}% at {},{} (max {}), grain {}%, spread {} over {} held frames; {}",- report["worst_at"][0], report["worst_at"][1], max * 3.0, report["grain"], report["spread"], report["frames"], png.display()- );- if ok { Ok(format!("STEADY {line}")) } else { Err(format!("the light doesn't hold still: {line}. On Solari this is the world cache lit by too few rays: bake it (cache.bake, then cache.load), or give it a longer history")) }+ let r = report(&dir, max)?;+ if r["steady"] == json!(true) { Ok(format!("STEADY {}", line(&r))) } else { Err(format!("the light doesn't hold still: {}. {WHY}", line(&r))) }}#[cfg(test)]