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.

R3F23: a standard material's map follows the render target an app drew this frame (R3F23c, part). A mesh's map that names render images is keyed frame by frame (runtime/scene parts.rs: maps, map_k by step), and the new crate raea-sys-rendermap's sync_render_maps points the material's base colour texture at the image its row names this frame, so two targets ping-ponged (GPUComputationRenderer, a feedback effect) show the one drawn last. A map naming a picture keeps its first frame's, as before. runtime/scene drops two doc lines left over from moved modules

shinyobjectz840de6756969
diff --git a/Cargo.lock b/Cargo.lock
index c94d73d4..71fad6d8 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -14845,6 +14845,7 @@ dependencies = [
"raea-sys-phase",
"raea-sys-post",
"raea-sys-procmat",
+ "raea-sys-rendermap",
"raea-sys-rt",
"raea-sys-sampler",
"raea-sys-screen",
@@ -16093,6 +16094,14 @@ dependencies = [
"serde_json",
]
+[[package]]
+name = "raea-sys-rendermap"
+version = "0.1.0"
+dependencies = [
+ "bevy",
+ "raea-sys-frame",
+]
+
[[package]]
name = "raea-sys-rt"
version = "0.1.0"
diff --git a/Cargo.toml b/Cargo.toml
index 5d66b0bf..543002d3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -119,6 +119,7 @@ members = [
"systems/screen",
"systems/matchmove",
"systems/grid",
+ "systems/rendermap",
"systems/meshseq",
"systems/environment",
"systems/look",
diff --git a/engine/render/Cargo.toml b/engine/render/Cargo.toml
index 2288331e..1b210038 100644
--- a/engine/render/Cargo.toml
+++ b/engine/render/Cargo.toml
@@ -33,6 +33,7 @@ raea-runtime-plugins = { path = "../../runtime/plugins" }
raea-sys-screen = { path = "../../systems/screen" }
raea-sys-matchmove = { path = "../../systems/matchmove" }
raea-sys-grid = { path = "../../systems/grid" }
+raea-sys-rendermap = { path = "../../systems/rendermap" }
raea-sys-meshseq = { path = "../../systems/meshseq" }
raea-sys-environment = { path = "../../systems/environment" }
raea-sys-look = { path = "../../systems/look" }
diff --git a/engine/render/src/engine/raea_plugins.rs b/engine/render/src/engine/raea_plugins.rs
index a1abd68e..f409c4a6 100644
--- a/engine/render/src/engine/raea_plugins.rs
+++ b/engine/render/src/engine/raea_plugins.rs
@@ -113,7 +113,7 @@ pub fn scene3d_systems() -> ScheduleConfigs<ScheduleSystem> {
super::scene3d::instance_models,
super::scene3d::model_shadow_markers,
super::scene3d::toon_models,
- ((super::scene3d::sync_meshes, super::scene3d::sync_instances, super::scene3d::sync_pictures, super::shader_ext::sync_shaded, raea_sys_sampler::arrays::sync_arrays, raea_sys_sampler::sync_samplers).chain(), super::toon::sync_toon, (super::scene3d::sync_camera, super::scene3d::sync_post).chain(), super::motion_blur::sync_motion_blur, (super::environment::sync_environment, super::environment::sync_prefiltered, super::environment::sync_suns).chain(), (super::scene3d::sync_light_sets, super::scene3d::sync_lights).chain(), super::scene3d::sync_fog_volumes, super::scene3d::sync_fog_dither, super::scene3d::sync_models, super::scene3d::sync_morphs, super::scene3d::sync_attach, super::grid::grid_models, super::scene3d::sync_bones, super::look::sync_frame_look, super::look::sync_looks, super::compose::sync_passes, super::look::sync_flat, super::paint::sync_paint, super::decal::sync_decals, super::text3d::sync_texts).chain(),
+ ((super::scene3d::sync_meshes, super::scene3d::sync_instances, super::scene3d::sync_pictures, raea_sys_rendermap::sync_render_maps, super::shader_ext::sync_shaded, raea_sys_sampler::arrays::sync_arrays, raea_sys_sampler::sync_samplers).chain(), super::toon::sync_toon, (super::scene3d::sync_camera, super::scene3d::sync_post).chain(), super::motion_blur::sync_motion_blur, (super::environment::sync_environment, super::environment::sync_prefiltered, super::environment::sync_suns).chain(), (super::scene3d::sync_light_sets, super::scene3d::sync_lights).chain(), super::scene3d::sync_fog_volumes, super::scene3d::sync_fog_dither, super::scene3d::sync_models, super::scene3d::sync_morphs, super::scene3d::sync_attach, super::grid::grid_models, super::scene3d::sync_bones, super::look::sync_frame_look, super::look::sync_looks, super::compose::sync_passes, super::look::sync_flat, super::paint::sync_paint, super::decal::sync_decals, super::text3d::sync_texts).chain(),
// --clay and --review's clay half: every standard surface grey, after the rows set their colours
super::scene3d::clay::clay_materials,
)
diff --git a/runtime/scene/src/lib.rs b/runtime/scene/src/lib.rs
index 4891e07e..114ab858 100644
--- a/runtime/scene/src/lib.rs
+++ b/runtime/scene/src/lib.rs
@@ -26,8 +26,6 @@ mod fast;
/// Gaussian splats' rows (<Splat>).
mod splat;
-/// 2D parts' rows (<Sprite>, <Shape2D>).
-/// <Instances>: a mesh or model row's placements (its `inst` column).
/// Baked simulations' and glitches' rows (<MeshSequence>, <Goo>, glitch props).
mod meshseq;
/// Fields of grass' rows (<Grass>).
diff --git a/runtime/scene/src/parts.rs b/runtime/scene/src/parts.rs
index c3ed953b..60d20324 100644
--- a/runtime/scene/src/parts.rs
+++ b/runtime/scene/src/parts.rs
@@ -169,9 +169,10 @@ pub(crate) fn meshes_rows(tr: &Tracks, names: &[String], p: &mut Program) {
}
}
for (prop, col) in [("map", "map"), ("normalMap", "normal_map"), ("roughnessMap", "rough_map"), ("metalnessMap", "metal_map"), ("metallicRoughnessMap", "mr_map"), ("aoMap", "ao_map"), ("emissiveMap", "emissive_map"), ("depthMap", "depth_map"), ("clearcoatNormalMap", "clearcoat_normal_map")] {
- if let Some(src) = m0.get(prop).and_then(Value::as_str) {
- row.insert(col.into(), V::S(src_path(src)));
- }
+ let Some(src) = m0.get(prop).and_then(Value::as_str) else { continue };
+ // render images an app ping-pongs between are keyed frame by frame (R3F23c: raea-sys-rendermap); a picture is its first frame's
+ let srcs: Vec<String> = if src.starts_with("render:") { mats.iter().map(|m| m.get(prop).and_then(Value::as_str).unwrap_or(src).to_string()).collect() } else { vec![src_path(src)] };
+ keyed_strings(p, &mut row, &id, col, &srcs);
}
if let Some(Value::Array(r)) = m0.get("repeat") {
if let [u, v] = r.as_slice() {
diff --git a/systems/rendermap/Cargo.toml b/systems/rendermap/Cargo.toml
new file mode 100644
index 00000000..a0faf1f2
--- /dev/null
+++ b/systems/rendermap/Cargo.toml
@@ -0,0 +1,11 @@
+[package]
+name = "raea-sys-rendermap"
+version = "0.1.0"
+edition = "2024"
+license = "FSL-1.1-ALv2"
+publish = false
+description = "A standard material's map that names another render image frame by frame (two targets an app ping-pongs)"
+
+[dependencies]
+raea-sys-frame = { path = "../frame" }
+bevy = { version = "=0.20.0", default-features = false, features = ["std", "default_app", "3d_bevy_render"] }
diff --git a/systems/rendermap/src/lib.rs b/systems/rendermap/src/lib.rs
new file mode 100644
index 00000000..b06f3f22
--- /dev/null
+++ b/systems/rendermap/src/lib.rs
@@ -0,0 +1,24 @@
+//! A standard material's map that names another render image frame by frame (docs/r3f.feature R3F23c): an app that
+//! ping-pongs between two render targets (three's GPUComputationRenderer, a feedback or trail effect) shows the one it
+//! drew this frame. raea-runtime-scene's parts.rs keys a mesh row's `map` when it names render images that change over
+//! the frames (`maps`, one a line, and `map_k`, keyed by step); the image each names is the one its camera draws into
+//! (raea-sys-frame's RenderImages). A map that names a picture keeps its first frame's.
+
+use bevy::prelude::*;
+use raea_sys_frame::{FrameRows, RenderImages};
+
+/// Each mesh whose map is keyed: its material's base colour texture, the render image its row names this frame.
+pub fn sync_render_maps(frame: Res<FrameRows>, renders: Option<Res<RenderImages>>, q: Query<(Entity, &MeshMaterial3d<StandardMaterial>)>, mut mats: ResMut<Assets<StandardMaterial>>) {
+ let Some(renders) = renders.filter(|_| frame.may_have("map_k")) else { return };
+ for (e, m) in &q {
+ let Some(v) = frame.vals(e).filter(|v| v.contains_key("map_k")) else { continue };
+ let Some(src) = raea_sys_frame::keyed(|c| v.get(c).cloned(), "map") else { continue };
+ let Some(img) = RenderImages::name(&src).and_then(|n| renders.0.get(n)).map(|i| i.0.clone()) else { continue };
+ // looked at first: get_mut marks the material changed whether or not it is
+ if mats.get(&m.0).is_some_and(|s| s.base_color_texture.as_ref() != Some(&img)) {
+ if let Some(mut s) = mats.get_mut(&m.0) {
+ s.base_color_texture = Some(img);
+ }
+ }
+ }
+}
diff --git a/tools/layers.toml b/tools/layers.toml
index a2665217..fd803c96 100644
--- a/tools/layers.toml
+++ b/tools/layers.toml
@@ -113,6 +113,7 @@ raea-runtime-scene3d = "runtime"
raea-sys-screen = "systems"
raea-sys-matchmove = "systems"
raea-sys-grid = "systems"
+raea-sys-rendermap = "systems"
raea-sys-meshseq = "systems"
raea-sys-environment = "systems"
raea-sys-look = "systems"