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 camera into an image within the crate budgets, and its ambient light shared with the screen camera's. raea-render's spawn_camera takes its size and target together and ends with raea-sys-frame's into_image, which a screen camera's row passes through; image_of gives a rendercam's image as its target, so load and apply_rows spawn camera and rendercam rows in one arm (raea-render stays under 2,000 lines, with is_3d_spawn moved to raea-sys-frame's store). runtime/scene takes rendercam tracks where it hands them to raea-runtime-look. rendercam.rs's ambient_columns is the one place a camera's ambient columns come from (a pass camera now carries the ambient colour too)

shinyobjectz2598a7594270
diff --git a/engine/render/src/engine/load.rs b/engine/render/src/engine/load.rs
index cde73d2d..f7fea211 100644
--- a/engine/render/src/engine/load.rs
+++ b/engine/render/src/engine/load.rs
@@ -46,13 +46,12 @@ impl Engine {
for (t, e) in order {
let vals = &t.vals;
match t.kind.as_str() {
- "camera" => {
- spawn_camera(world, e, vals, inserted, &self.dir, (prog.width, prog.height), RenderTarget::Image(self.target.clone().into()), has_3d)?;
- camera.get_or_insert(e); // (the first camera: a second draws over it, two_passes)
+ "camera" | "rendercam" => {
+ let on = raea_sys_frame::camera::image_of(world, vals)?.unwrap_or(((prog.width, prog.height), RenderTarget::Image(self.target.clone().into())));
+ spawn_camera(world, e, vals, inserted, &self.dir, on, has_3d || t.kind == "rendercam")?;
+ if t.kind == "camera" { camera.get_or_insert(e); } // (the first camera: a second draws over it, two_passes)
}
- // a camera into an image, a pass before the screen's (R3F23a)
- "rendercam" => render_camera(world, e, vals, inserted, &self.dir)?,
- k if is_3d_spawn(k) => {
+ k if store::is_3d_spawn(k) => {
spawn_3d(world, e, t, inserted, &self.dir)?;
}
// without native a clip or a 2D row is a row only (a browser's page draws its own video and text)
diff --git a/engine/render/src/engine/spawn.rs b/engine/render/src/engine/spawn.rs
index ca78fd1a..bcc9de83 100644
--- a/engine/render/src/engine/spawn.rs
+++ b/engine/render/src/engine/spawn.rs
@@ -37,17 +37,12 @@ pub(crate) fn relational(edit: Res<Edit>, clock: Res<Clock>, mut err: ResMut<Err
let _ = &mut err;
}
-/// The kinds a row spawns as a thing in the 3D scene (spawn_3d).
-pub(crate) fn is_3d_spawn(kind: &str) -> bool {
- matches!(kind, "light" | "model" | "cube" | "sphere" | "plane" | "mesh" | "panel" | "decal" | "fogvolume" | "fire" | "grass" | "plate" | "splat" | "meshseq" | "entity" | "text" | "glyph" | "screenpage" | "sprite" | "shape2d")
-}
-
/// A 3D row's entity made what it draws (a light, a model, a mesh with its surface, a panel): what a load does for each
/// one, and what a live scene does for a row first seen mid-play (Engine::set_rows).
-/// A camera row's entity made the 3D camera, drawing into `target` (the edit's frame in an Engine; a plain App's own,
-/// SceneTarget): its lens and post-processing, motion blur's prepasses, the environment and a window on a larger view.
+/// A camera row's entity made the 3D camera, drawing into `target` (the edit's frame in an Engine, a plain App's own
+/// SceneTarget, or a rendercam's image: R3F23a): its lens and post, motion blur's prepasses, environment and view.
#[allow(clippy::too_many_arguments)]
-pub(crate) fn spawn_camera(world: &mut World, e: Entity, vals: &BTreeMap<String, V>, inserted: &[Tup], dir: &Path, size: (u32, u32), target: RenderTarget, has_3d: bool) -> Result<(), String> {
+pub(crate) fn spawn_camera(world: &mut World, e: Entity, vals: &BTreeMap<String, V>, inserted: &[Tup], dir: &Path, (size, target): ((u32, u32), RenderTarget), has_3d: bool) -> Result<(), String> {
let g = |k: &str, d: f32| num(vals, k, d);
world.entity_mut(e).insert((
Camera3d::default(),
@@ -78,18 +73,7 @@ pub(crate) fn spawn_camera(world: &mut World, e: Entity, vals: &BTreeMap<String,
environment::environment(world, e, vals, inserted, dir)?;
// a window on a larger view (view_*): matchmove
matchmove::camera_view(world, e, vals, Vec2::new(size.0 as f32, size.1 as f32));
- Ok(())
-}
-
-/// A camera row drawing into an image (a "rendercam", `into` "render:NAME:WxH[:float]": docs/r3f.feature R3F23a): the
-/// camera spawn_camera makes, on that image (raea-sys-frame's into_image), which a material's map naming it reads.
-pub(crate) fn render_camera(world: &mut World, e: Entity, vals: &BTreeMap<String, V>, inserted: &[Tup], dir: &Path) -> Result<(), String> {
- let Some(V::S(into)) = vals.get("into") else { return Err("a camera into an image needs `into` (\"render:NAME:WxH\")".into()) };
- let image = RenderImages::image(world, into, None)?;
- let size = RenderImages::name(into).and_then(|n| world.resource::<RenderImages>().0.get(n)).map_or((512, 512), |i| i.1);
- spawn_camera(world, e, vals, inserted, dir, size, RenderTarget::Image(image.into()), true)?;
- raea_sys_frame::camera::into_image(world, e, into);
- Ok(())
+ raea_sys_frame::camera::into_image(world, e, vals) // a rendercam's: no tone curve, MSAA or dither (R3F23a)
}
/// A live scene's rows applied to a World (Engine::set_rows, or a plain App's: docs/sdk.feature S6a): each row's values
@@ -128,9 +112,8 @@ pub fn apply_rows(world: &mut World, dir: &Path, rows: &[Tup]) -> Result<bool, S
None => {
let e = store::spawn(world, t);
// a camera first seen here is a plain App's (SceneTarget); an Engine's comes with its load
- match world.get_resource::<SceneTarget>().map(|s| (s.target.clone(), s.size)) {
- _ if t.kind == "rendercam" => render_camera(world, e, &t.vals, rows, dir)?,
- Some((target, size)) if t.kind == "camera" => spawn_camera(world, e, &t.vals, rows, dir, size, target, true)?,
+ match raea_sys_frame::camera::image_of(world, &t.vals)?.or_else(|| world.get_resource::<SceneTarget>().map(|s| (s.size, s.target.clone()))) {
+ Some(on) if matches!(t.kind.as_str(), "camera" | "rendercam") => spawn_camera(world, e, &t.vals, rows, dir, on, true)?,
_ => spawn_3d(world, e, t, &media, dir)?,
}
let r = store::rows(world).len() - 1;
diff --git a/runtime/look/src/camera.rs b/runtime/look/src/camera.rs
index f726d129..bed8dcd2 100644
--- a/runtime/look/src/camera.rs
+++ b/runtime/look/src/camera.rs
@@ -128,23 +128,12 @@ pub fn placed(all: &[Vec<Item>], p: &mut Program, row: &mut BTreeMap<String, V>,
/// The rest of a screen camera's row: the scene's ambient light, environment, sky, post-processing, composition
/// passes, lens and motion blur, frame by frame.
fn lit(all: &[Vec<Item>], p: &mut Program, row: &mut BTreeMap<String, V>, id: &str) {
- // ambient: every AmbientLight's intensity summed, per frame; its colour the first one's. Any AmbientLight sends the
- // column, so one of brightness 0 turns the ambient off as Bevy's does (with none, the camera keeps Bevy's default 80)
- // (those on the camera's layers: an image's pass lights its own scene with its own, rendercam.rs)
+ // ambient: the AmbientLights on the camera's layers (an image's pass lights its own scene with its own): rendercam.rs
let layers: Vec<u64> = match row.get("layers") {
Some(V::S(l)) => l.split(',').filter_map(|x| x.trim().parse().ok()).collect(),
_ => vec![0],
};
- let amb: Vec<f64> = all.iter().map(|its| ambient_on(its, &layers)).collect();
- let lit_by = |i: &&Item| i.kind == "ambient" && sees(&layers, i);
- if all.iter().flatten().any(|i| lit_by(&i)) {
- column(p, row, id, "ambient", &amb);
- if let Some(c) = all.iter().flatten().find(lit_by).and_then(|i| hex(i.props.get("color"))) {
- if c != "#ffffff" {
- row.insert("ambient_color".into(), V::S(c));
- }
- }
- }
+ ambient_columns(all, p, row, id, &layers);
// an <Environment>: each frame's panorama (an index into env_srcs, -1 for none), its light, turn and sky, keyed, so
// a cut from a hall to a street changes the light on that frame
// Bevy's EnvironmentMapLight with its own prefiltered maps (<EnvironmentMapLight>: its diffuse and specular
diff --git a/runtime/look/src/rendercam.rs b/runtime/look/src/rendercam.rs
index 808ba47d..86631443 100644
--- a/runtime/look/src/rendercam.rs
+++ b/runtime/look/src/rendercam.rs
@@ -25,11 +25,7 @@ pub fn render_cameras(all: &[Vec<Item>], tracks: &[(String, Vec<Option<Item>>)],
p.keys.insert((id.clone(), "on".into()), step_keys(&on));
}
row.insert("tonemap".into(), V::S(first.get("tonemap").and_then(Value::as_str).unwrap_or("none").to_string()));
- let layers = layers_of(first);
- let amb: Vec<f64> = all.iter().map(|f| ambient_on(f, &layers)).collect();
- if all.iter().flatten().any(|i| i.kind == "ambient" && sees(&layers, i)) {
- column(p, &mut row, &id, "ambient", &amb);
- }
+ ambient_columns(all, p, &mut row, &id, &layers_of(first));
rows.push(row);
}
if !rows.is_empty() {
@@ -37,6 +33,20 @@ pub fn render_cameras(all: &[Vec<Item>], tracks: &[(String, Vec<Option<Item>>)],
}
}
+/// A camera's ambient light, from the AmbientLights on its `layers`: their intensities summed per frame (`ambient`,
+/// keyed) and the first one's colour. Any such light sends the column, so one of brightness 0 turns the ambient off as
+/// Bevy's does; with none, the camera keeps Bevy's default 80.
+pub(crate) fn ambient_columns(all: &[Vec<Item>], p: &mut Program, row: &mut BTreeMap<String, V>, id: &str, layers: &[u64]) {
+ let lit_by = |i: &&Item| i.kind == "ambient" && sees(layers, i);
+ if !all.iter().flatten().any(|i| lit_by(&i)) {
+ return;
+ }
+ column(p, row, id, "ambient", &all.iter().map(|its| ambient_on(its, layers)).collect::<Vec<_>>());
+ if let Some(c) = all.iter().flatten().find(lit_by).and_then(|i| hex(i.props.get("color"))).filter(|c| c != "#ffffff") {
+ row.insert("ambient_color".into(), V::S(c));
+ }
+}
+
/// A part's render layers (its `layers` prop), layer 0 when it names none, as Bevy's RenderLayers default.
pub fn layers_of(props: &Map<String, Value>) -> Vec<u64> {
match props.get("layers").and_then(Value::as_array) {
diff --git a/runtime/scene/src/lib.rs b/runtime/scene/src/lib.rs
index 8beddf29..4891e07e 100644
--- a/runtime/scene/src/lib.rs
+++ b/runtime/scene/src/lib.rs
@@ -141,9 +141,7 @@ fn walk(n: &Node3, parent: Mat4, out: &mut Vec<Item>) {
"Plate" => out.push(item("plate", Mat4::IDENTITY, None)),
"PerspectiveCamera" | "DirectionalLight" | "PointLight" | "SpotLight" | "RectAreaLight" => {
let kind = match &*n.kind {
- // a camera drawing into an image (`target` "render:NAME:WxH", R3F23a) is a pass before the screen's,
- // outside the screen's cameras (their order, which is active, a cut): rendercam.rs
- "PerspectiveCamera" if n.props.get("target").is_some_and(Value::is_string) => "rendercam",
+ "PerspectiveCamera" if n.props.get("target").is_some_and(Value::is_string) => "rendercam", // into an image (R3F23a)
"PerspectiveCamera" => "camera",
"DirectionalLight" => "directional",
"PointLight" => "point",
@@ -285,7 +283,6 @@ struct Tracks {
meshseqs: Vec<Track>,
entities: Vec<Track>,
texts: Vec<Track>,
- rendercams: Vec<Track>,
}
impl Tracks {
@@ -306,7 +303,6 @@ impl Tracks {
meshseqs: tracks_of(all, &["meshseq"]),
entities: tracks_of(all, &["entity"]),
texts: tracks_of(all, &["text"]),
- rendercams: tracks_of(all, &["rendercam"]),
}
}
}
@@ -336,6 +332,5 @@ fn rows_into_of(all: &[Vec<Item>], tr: &Tracks, p: &mut Program) {
raea_runtime_scene2d::shapes(&tr.shapes2d, p);
// baked simulations (<MeshSequence>, <Goo>): meshseq.rs
meshseq::rows(&tr.meshseqs, p);
- // cameras drawing into images (R3F23a): raea-runtime-look's rendercam.rs
- render_cameras(all, &tr.rendercams, p);
+ render_cameras(all, &tracks_of(all, &["rendercam"]), p); // cameras into images (R3F23a): raea-runtime-look rendercam.rs
}
diff --git a/systems/frame/src/camera.rs b/systems/frame/src/camera.rs
index 849fd11f..0cbb5a00 100644
--- a/systems/frame/src/camera.rs
+++ b/systems/frame/src/camera.rs
@@ -2,7 +2,7 @@
//! <Camera3d order clear_color viewport>, 3d/two_passes and 3d/split_screen).
use super::*;
-use bevy::camera::Viewport;
+use bevy::camera::{RenderTarget, Viewport};
/// The camera row's `order` among the cameras on its target, `clear` "none" to draw over the ones before without
/// clearing, and its viewport (`vp_x`, `vp_y`, `vp_w`, `vp_h`: physical px from the target's top left), on its Camera.
@@ -50,14 +50,26 @@ pub fn remove<B: Bundle>(world: &mut World, e: Entity) {
#[derive(Component, Clone, Copy, Default)]
pub struct IntoImage;
-/// A camera on a render image (`into`), as three draws into a render target: no multisampling (a target has none
-/// unless it asks), no dither, and Hdr for a float image (":float") so its values stay as drawn, unclamped and signed.
-/// Its tone curve is its row's (`tonemap` "none" unless it names one: raea-runtime-look's rendercam.rs).
-pub fn into_image(world: &mut World, e: Entity, into: &str) {
+/// The image a camera row draws into (a rendercam's `into`, "render:NAME:WxH[:float]": docs/r3f.feature R3F23a), made
+/// if it's new, as the camera's size and target; None for a screen camera.
+pub fn image_of(world: &mut World, vals: &BTreeMap<String, V>) -> Result<Option<((u32, u32), RenderTarget)>, String> {
+ let Some(V::S(into)) = vals.get("into") else { return Ok(None) };
+ let image = RenderImages::image(world, into, None)?;
+ let size = RenderImages::name(into).and_then(|n| world.resource::<RenderImages>().0.get(n)).map_or((512, 512), |i| i.1);
+ Ok(Some((size, RenderTarget::Image(image.into()))))
+}
+
+/// A camera on a render image (`into`, image_of's), as three draws into a render target: no multisampling (a target has
+/// none unless it asks), no dither, and Hdr for a float image (":float") so its values stay as drawn, unclamped and
+/// signed. Its tone curve is its row's (`tonemap` "none" unless it names one: raea-runtime-look's rendercam.rs). A
+/// screen camera's row (no `into`) is left as it is.
+pub fn into_image(world: &mut World, e: Entity, vals: &BTreeMap<String, V>) -> Result<(), String> {
+ let Some(V::S(into)) = vals.get("into") else { return Ok(()) };
let float = matches!(RenderImages::spec(into), Ok((_, _, RenderKind::Float)));
let mut c = world.entity_mut(e);
c.insert((IntoImage, Msaa::Off, bevy::core_pipeline::tonemapping::DebandDither::Disabled));
if float {
c.insert(bevy::camera::Hdr);
}
+ Ok(())
}
diff --git a/systems/frame/src/store.rs b/systems/frame/src/store.rs
index b30b2fed..bbc46dcb 100644
--- a/systems/frame/src/store.rs
+++ b/systems/frame/src/store.rs
@@ -56,6 +56,11 @@ fn column(world: &mut World, kind: &str, col: &str, ty: usize) -> ComponentId {
id
}
+/// The kinds a row spawns as a thing in the 3D scene (raea-render's spawn_3d).
+pub fn is_3d_spawn(kind: &str) -> bool {
+ matches!(kind, "light" | "model" | "cube" | "sphere" | "plane" | "mesh" | "panel" | "decal" | "fogvolume" | "fire" | "grass" | "plate" | "splat" | "meshseq" | "entity" | "text" | "glyph" | "screenpage" | "sprite" | "shape2d")
+}
+
/// The rows, in the edit's order.
pub fn rows(world: &World) -> &[Entity] {
world.get_resource::<Schema>().map(|s| s.order.as_slice()).unwrap_or(&[])