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
FC0a: ui/render_ui_to_texture ports at 0.99998. UiTexture and targetImage draw bevy_ui into an image a StandardMaterial samples: the UI is laid out as a Screen's picture (painted alone, handed to raea-render by name each frame), and a material texture of raea-screen:name@WxH resolves to that screen's image (raea-sys-screen named_image). 86 of 90 ported examples pass
shinyobjectzb6053cf8a7fe
diff --git a/Cargo.lock b/Cargo.lockindex 8b17902c..c76da2bf 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -15461,6 +15461,7 @@ dependencies = ["image","raea-core-program","raea-sys-frame",+ "raea-sys-material","serde_json","wgpu",]diff --git a/bench/bevy-parity/examples.list b/bench/bevy-parity/examples.listindex 426f16c9..3dbc84ab 100644--- a/bench/bevy-parity/examples.list+++ b/bench/bevy-parity/examples.list@@ -89,3 +89,4 @@ ui/scroll_and_overflow/scrollbarsui/scroll_and_overflow/overflow_debugui/text/font_queryui/images/image_node_resizing+ui/render_ui_to_texturediff --git a/bench/bevy-parity/runs.tsv b/bench/bevy-parity/runs.tsvindex 460ba70d..377f1489 100644--- a/bench/bevy-parity/runs.tsv+++ b/bench/bevy-parity/runs.tsv@@ -88,3 +88,4 @@ ui/scroll_and_overflow/scrollbars - 10ui/scroll_and_overflow/overflow_debug - 10ui/text/font_query - 10ui/images/image_node_resizing - 10+ui/render_ui_to_texture - 10diff --git a/docs/bevy-parity.md b/docs/bevy-parity.mdindex 4608ac18..06b57f9a 100644--- a/docs/bevy-parity.md+++ b/docs/bevy-parity.md@@ -4,7 +4,7 @@ Bevy v0.20.0's examples against their raea TSX ports (docs/control.feature FC0a)don't edit. An example passes when every probed frame passes pixels (SSIM 0.98 and no 32 px tile off by more than 24 of 255) and cost (batch keys andframe time at most 1.25x the example's). Wall time is one machine's, measured in the same run.-Examples: **438**, ported **89**, passing **85**, excluded **16** (docs/bevy-parity/excluded.tsv), left **337**.+Examples: **438**, ported **90**, passing **86**, excluded **16** (docs/bevy-parity/excluded.tsv), left **336**.raea's frame ms is its update's plus the time React takes to step a frame for its 3D (step), which the exampledoesn't pay.@@ -145,6 +145,7 @@ doesn't pay.| ui/scroll_and_overflow/overflow_transform | 10 | 0.995397 | 12 | 0 / 0 | 447 / 492 | 5 / 7 | 1 / 1 | 45.188 / 2.255 = 2.255 + 0 | yes | || ui/scroll_and_overflow/overflow_debug | 10 | 0.996511 | 10 | 0 / 0 | 463 / 492 | 5 / 7 | 1 / 1 | 39.92 / 1.736 = 1.736 + 0 | yes | || ui/images/image_node_resizing | 10 | 0.998112 | 9 | 0 / 0 | 455 / 492 | 5 / 7 | 1 / 1 | 31.752 / 1.604 = 1.604 + 0 | yes | |+| ui/render_ui_to_texture | 10 | 0.999980 | 1 | 1 / 1 | 450 / 495 | 6 / 8 | 2 / 2 | 39.73 / 2.716 = 2.716 + 0 | yes | |## Excludeddiff --git a/sdk/raea/bench/bevy-parity/ui/render_ui_to_texture.tsx b/sdk/raea/bench/bevy-parity/ui/render_ui_to_texture.tsxnew file mode 100644index 00000000..966aa948--- /dev/null+++ b/sdk/raea/bench/bevy-parity/ui/render_ui_to_texture.tsx@@ -0,0 +1,51 @@+// Bevy v0.20.0 examples/ui/render_ui_to_texture.rs in raea's TSX (docs/control.feature FC0a): a bevy_ui tree drawn by+// a Camera2d (order -1) into a 512 x 512 image, the base_color_texture (reflectance 0.02) of a default 1 m Cuboid at+// z 1.5. The tree is a css GRAY root filling the image, centring an absolute css BLUE box (20 px padding, 10 px+// corners) holding "Drag Me!" in white 40 px Bevy's default font. The cube is turned PI about X, then about world X at+// 0.1 rad/s and world Y at 0.07 rad/s each update (rotate_x, then rotate_y). A default DirectionalLight and the camera+// are at z 5, looking at the origin, in Bevy's default 1280 x 720 window. The diegetic pointer (a ray cast into the+// cube's UVs) hovers and drags the box only under a cursor, so it stays blue where it was laid out.+import { AbsoluteFill, Composition, registerRoot, useCurrentFrame } from "raea";+import { Canvas3D } from "raea/3d";+import { Quat, Transform } from "raea/transform";+import { Camera3d } from "raea/camera";+import { Cuboid, Mesh3d } from "raea/mesh";+import { StandardMaterial } from "raea/pbr";+import { DirectionalLight } from "raea/light";+import { BorderRadius, Node, Text, UiRect, UiTexture, percent, px, targetImage } from "raea/ui";+import { Srgba } from "raea/color";++const IMAGE = targetImage("ui", 512, 512);+const DT = 1 / 60;++// the cube's rotation after `frame` updates of rotator_system, each a delta of 1/60 s+function turned(frame: number) {+ let q = Quat.fromRotationX(Math.PI);+ for (let i = 0; i < frame; i++) q = Quat.mul(Quat.fromRotationY(0.07 * DT), Quat.mul(Quat.fromRotationX(0.1 * DT), q));+ return q;+}++function Shot() {+ const frame = useCurrentFrame();+ return (+ <AbsoluteFill>+ <Canvas3D layered clearColor="rgb(43, 44, 47)">+ <DirectionalLight />+ <Mesh3d transform={{ translation: [0, 0, 1.5], rotation: turned(frame) }}>+ <Cuboid half_size={[0.5, 0.5, 0.5]} />+ <StandardMaterial base_color_texture={IMAGE} reflectance={0.02} />+ </Mesh3d>+ <Camera3d transform={Transform.fromXyz(0, 0, 5).lookingAt([0, 0, 0])} />+ </Canvas3D>+ <UiTexture target={IMAGE}>+ <Node width={percent(100)} height={percent(100)} flex_direction="Column" justify_content="Center" align_items="Center" background_color={new Srgba(0.5, 0.5, 0.5)}>+ <Node position_type="Absolute" align_items="Center" padding={UiRect.all(px(20))} border_radius={BorderRadius.all(px(10))} background_color={new Srgba(0, 0, 1)}>+ <Text font_size={{ Px: 40 }} color={new Srgba(1, 1, 1)}>Drag Me!</Text>+ </Node>+ </Node>+ </UiTexture>+ </AbsoluteFill>+ );+}++registerRoot(() => <Composition id="main" component={Shot} durationInFrames={11} fps={60} width={1280} height={720} />);diff --git a/sdk/raea/conformance/ui-texture.test.tsx b/sdk/raea/conformance/ui-texture.test.tsxnew file mode 100644index 00000000..7b83a503--- /dev/null+++ b/sdk/raea/conformance/ui-texture.test.tsx@@ -0,0 +1,32 @@+// docs/control.feature FC0a: bevy_ui drawn into an image a material samples (ui/render_ui_to_texture). A UiTexture's UI+// is a screen's picture (painted on its own, off the frame's view), and the material names that screen's image.+import { describe, expect, test } from "bun:test";+import { Node, UiTexture, targetImage } from "raea/ui";+import { renderFrame } from "../src/test";++const html = (el: React.ReactElement) => renderFrame(el, { frame: 0, width: 320, height: 240, fps: 30, durationInFrames: 30 });++describe("targetImage: an image a camera renders into, as a material's texture names it", () => {+ test("its name and size, as raea-sys-screen's named_image reads them", () => {+ expect(targetImage("ui", 512, 256)).toBe("raea-screen:ui@512x256");+ });+ test("refuses a name the page couldn't carry, or a size that isn't whole px", () => {+ expect(() => targetImage("a b", 1, 1)).toThrow(/name/);+ expect(() => targetImage("ui", 0, 1)).toThrow(/whole px/);+ expect(() => targetImage("ui", 1.5, 1)).toThrow(/whole px/);+ });+});++describe("UiTexture: the roots inside drawn into the image instead of the window", () => {+ test("a screen's picture of the image's name and size, see-through, off the frame's view", () => {+ const out = html(<UiTexture target={targetImage("ui", 512, 256)}><Node /></UiTexture>);+ expect(out).toContain('data-raea-screen="ui"');+ expect(out).toContain('data-raea-screen-w="512"');+ expect(out).toContain('data-raea-screen-h="256"');+ expect(out).toMatch(/background-color:\s*transparent/);+ expect(out).toMatch(/left:\s*-20000px/);+ });+ test("refuses a target that isn't a targetImage", () => {+ expect(() => html(<UiTexture target="branding/icon.png" />)).toThrow(/targetImage/);+ });+});diff --git a/sdk/raea/src/ui.ts b/sdk/raea/src/ui.tsindex cea0b6ab..ee719d63 100644--- a/sdk/raea/src/ui.ts+++ b/sdk/raea/src/ui.ts@@ -6,7 +6,7 @@ export * from "@raea/video/region";// InputRegion (input-region.tsx) joins when it is committedexport * from "@raea/video/panel";// bevy_ui's Node and Text, and bevy_text's TextSpan, with their values (Val, UiRect, BorderRadius, Overflow)-export { Node, GhostNode, Text, TextSpan, TextShadow, Text2d, UiScale, Viewport, UiTargetCamera, ImageNode, InlineImage, type TextureSlicer, type SliceScaleMode, ImagePlugin, FontVariationTag, TextureAtlasLayout, type ImageNodeProps, px, percent, vw, vh, vmin, vmax, auto, UiRect, BorderRadius, CornerRadius, Overflow, OverflowClipMargin, type NodeProps, type TextProps, type TextStyleProps, type TextRunProps, type Text2dProps, type Val } from "@raea/render/bevy3d";+export { Node, GhostNode, Text, TextSpan, TextShadow, Text2d, UiScale, Viewport, UiTargetCamera, UiTexture, targetImage, ImageNode, InlineImage, type TextureSlicer, type SliceScaleMode, ImagePlugin, FontVariationTag, TextureAtlasLayout, type ImageNodeProps, px, percent, vw, vh, vmin, vmax, auto, UiRect, BorderRadius, CornerRadius, Overflow, OverflowClipMargin, type NodeProps, type TextProps, type TextStyleProps, type TextRunProps, type Text2dProps, type Val } from "@raea/render/bevy3d";export { LinearGradient, RadialGradient, ConicGradient, ColorStop, AngularColorStop, UiPosition, type Gradient, type RadialGradientShape, type InterpolationColorSpace } from "@raea/render/bevy3d";export { GridTrack, RepeatedGridTrack, GridPlacement, type GridTrackRepetition, type GridAutoFlow, type MinTrackSizingFunction, type MaxTrackSizingFunction, FontSource, type GenericFontFamily } from "@raea/render/bevy3d";export { Rot2, Val2, UiTransform, BoxShadow, type ShadowStyle } from "@raea/render/bevy3d";diff --git a/sdk/render/src/bevy3d.tsx b/sdk/render/src/bevy3d.tsxindex dede4273..f384ce6f 100644--- a/sdk/render/src/bevy3d.tsx+++ b/sdk/render/src/bevy3d.tsx@@ -29,6 +29,7 @@ export { Hdr } from "./bevy3d/core";export { Lightmap, type LightmapProps } from "./bevy3d/lightmap";// bevy_ui's Node, Text and TextSpan, and their values, drawn by the pageexport { Node, GhostNode, Text, TextSpan, TextShadow, Text2d, UiScale, Viewport, UiTargetCamera, FontVariationTag, type NodeProps, type TextProps, type TextStyleProps, type TextRunProps, type Text2dProps } from "./bevy3d/ui";+export { UiTexture, targetImage } from "./bevy3d/ui-texture";export { ImageNode, InlineImage, ImagePlugin, TextureAtlasLayout, type TextureSlicer, type SliceScaleMode, type ImageNodeProps } from "./bevy3d/ui-image";export { px, percent, vw, vh, vmin, vmax, auto, UiRect, BorderRadius, CornerRadius, Overflow, OverflowClipMargin, type Val } from "./bevy3d/ui-val";export { LinearGradient, RadialGradient, ConicGradient, ColorStop, AngularColorStop, UiPosition, type Gradient, type RadialGradientShape, type InterpolationColorSpace } from "./bevy3d/ui-gradient";diff --git a/sdk/render/src/bevy3d/ui-texture.tsx b/sdk/render/src/bevy3d/ui-texture.tsxnew file mode 100644index 00000000..aca48295--- /dev/null+++ b/sdk/render/src/bevy3d/ui-texture.tsx@@ -0,0 +1,25 @@+// docs/control.feature FC0a: bevy_ui rendered into an image a 3D material samples (Bevy's ui/render_ui_to_texture: a+// Camera2d whose RenderTarget is an Image, its UI roots under UiTargetCamera, the Image a base_color_texture). The+// image is a <Screen>'s: UiTexture lays its UI out as a screen's picture (screenContent: off the frame's view, painted+// on its own and handed to raea-render by name each frame), and a material naming it samples that screen's image+// (raea-sys-screen's named_image: `raea-screen:name@WxH`), with no screen quad of its own.+import type { ReactNode } from "react";+import { screenContent } from "../screen";++/** An image the UI inside a <UiTexture> is drawn into, `width` x `height` px (bevy_image's Image::new_target_texture):+ * pass it to a material's texture field, e.g. StandardMaterial's base_color_texture. The name tells one target+ * from another (and from the composition's <Screen>s). @bevy bevy_image::Image::new_target_texture */+export function targetImage(name: string, width: number, height: number): string {+ if (!/^[A-Za-z0-9_-]+$/.test(name)) throw new TypeError(`targetImage: a name is letters, digits, _ and -, got ${JSON.stringify(name)}`);+ if (![width, height].every((n) => Number.isInteger(n) && n >= 1 && n <= 8192)) throw new RangeError(`targetImage: width and height are whole px from 1 to 8192, got ${width} x ${height}`);+ return `raea-screen:${name}@${width}x${height}`;+}++/** The UI roots inside drawn into `target` instead of the window (a Camera2d with RenderTarget::Image, the roots'+ * UiTargetCamera): laid out in a box the image's size, see-through where they draw nothing, and nowhere in the frame+ * itself. A root's 100% is the image's size. @bevy bevy_camera::RenderTarget::Image */+export function UiTexture({ target, children }: { target: string; children?: ReactNode }) {+ const m = /^raea-screen:([A-Za-z0-9_-]+)@(\d+)x(\d+)$/.exec(target);+ if (!m) throw new TypeError(`UiTexture: target is a targetImage(name, width, height), got ${JSON.stringify(target)}`);+ return screenContent(m[1], { resolution: [Number(m[2]), Number(m[3])], crt: false, background: "transparent", children });+}diff --git a/sdk/skills/raea/reference/sdk.md b/sdk/skills/raea/reference/sdk.mdindex 58467445..0eb1f85f 100644--- a/sdk/skills/raea/reference/sdk.md+++ b/sdk/skills/raea/reference/sdk.md@@ -99,7 +99,7 @@ with a capital, hooks with `use`. A component's props are in its file.## `raea/ui` (sdk/raea/src/ui.ts)-`AbsoluteFill`, `AngularColorStop`, `BorderRadius`, `BoxShadow`, `ColorStop`, `ConicGradient`, `CornerRadius`, `FontFeatureTag`, `FontSource`, `FontVariationTag`, `FontWidth`, `GhostNode`, `GlobalUiDebugOptions`, `GridPlacement`, `GridTrack`, `ImageNode`, `ImagePlugin`, `InlineImage`, `LinearGradient`, `Node`, `Overflow`, `OverflowClipMargin`, `RadialGradient`, `RepeatedGridTrack`, `Rot2`, `Scrollbar`, `ScrollbarThumb`, `Text`, `Text2d`, `TextShadow`, `TextSpan`, `TextureAtlasLayout`, `UiPosition`, `UiRect`, `UiScale`, `UiTargetCamera`, `UiTransform`, `Val2`, `Viewport`, `auto`, `percent`, `px`, `vh`, `vmax`, `vmin`, `vw`+`AbsoluteFill`, `AngularColorStop`, `BorderRadius`, `BoxShadow`, `ColorStop`, `ConicGradient`, `CornerRadius`, `FontFeatureTag`, `FontSource`, `FontVariationTag`, `FontWidth`, `GhostNode`, `GlobalUiDebugOptions`, `GridPlacement`, `GridTrack`, `ImageNode`, `ImagePlugin`, `InlineImage`, `LinearGradient`, `Node`, `Overflow`, `OverflowClipMargin`, `RadialGradient`, `RepeatedGridTrack`, `Rot2`, `Scrollbar`, `ScrollbarThumb`, `Text`, `Text2d`, `TextShadow`, `TextSpan`, `TextureAtlasLayout`, `UiPosition`, `UiRect`, `UiScale`, `UiTargetCamera`, `UiTexture`, `UiTransform`, `Val2`, `Viewport`, `auto`, `percent`, `px`, `targetImage`, `vh`, `vmax`, `vmin`, `vw`## `raea/video` (sdk/raea/src/video.ts)diff --git a/systems/material/src/maps.rs b/systems/material/src/maps.rsindex 7cb85f53..8b813167 100644--- a/systems/material/src/maps.rs+++ b/systems/material/src/maps.rs@@ -8,6 +8,11 @@ use bevy::render::render_resource::TextureFormat;#[derive(Resource, Default)]pub struct Maps(pub HashMap<String, Handle<Image>>);+/// An image a texture source names instead of a file, by whoever draws it (raea-sys-screen's named_image: a UiTexture's+/// `raea-screen:name@WxH`, render_ui_to_texture); None for any other source.+#[derive(Resource)]+pub struct NamedImages(pub fn(&mut World, &str) -> Option<Handle<Image>>);+/// How a map's texels are read: colour (sRGB, the base colour) or data (linear: normals, roughness, occlusion).#[derive(Clone, Copy, PartialEq)]pub enum MapKind {@@ -195,7 +200,11 @@ pub fn material(world: &mut World, t: &Tup, inserted: &[Tup], dir: &Path) -> Res_ => BTreeMap::new(),};let sam = |prop: &str| own.get(prop).or(all.as_ref());- if let Some(s) = src("map") {+ // a UiTexture's image (raea-screen:name@WxH): the screen image its UI is drawn into+ let named = world.get_resource::<NamedImages>().map(|n| n.0);+ if let Some(h) = src("map").zip(named).and_then(|(s, named)| named(world, &s)) {+ m.base_color_texture = Some(h);+ } else if let Some(s) = src("map") {m.base_color_texture = Some(cached_map(world, s.clone(), MapKind::Colour, repeat, sam("map"), || map_picture(t, inserted, dir, "map", &s))?);}if let Some(s) = src("normal_map") {diff --git a/systems/screen/Cargo.toml b/systems/screen/Cargo.tomlindex d4d2bb2d..8536baa1 100644--- a/systems/screen/Cargo.toml+++ b/systems/screen/Cargo.toml@@ -9,6 +9,8 @@ description = "Live pictures on surfaces (<Screen>, a model's screen materials,[dependencies]image = { version = "0.25", default-features = false, features = ["png", "jpeg", "hdr"] }raea-sys-frame = { path = "../frame" }+# a material texture naming a screen's image (raea-sys-material NamedImages: render_ui_to_texture)+raea-sys-material = { path = "../material" }raea-core-program = { path = "../../core/program" }bevy = { version = "=0.20.0", default-features = false, features = ["std", "default_app", "3d_bevy_render"] }wgpu = "=30.0.1"diff --git a/systems/screen/src/lib.rs b/systems/screen/src/lib.rsindex bb7b7b93..4dd0c641 100644--- a/systems/screen/src/lib.rs+++ b/systems/screen/src/lib.rs@@ -53,6 +53,7 @@ pub fn install(app: &mut App) {bevy::asset::embedded_asset!(app, "screen.wesl");app.add_plugins(MaterialPlugin::<CrtMaterial>::default()).init_resource::<ScreenImages>()+ .insert_resource(raea_sys_material::maps::NamedImages(named_image)).add_systems(Update, (model_screens, mesh_screens, hide_nodes, sync_screens).chain().after(FrameSystems::Rows).before(FrameSystems::Tag));}@@ -187,6 +188,16 @@ fn seed(spec: &serde_json::Value) -> f32 {(h % 1024) as f32}+/// The screen image a material's texture names (`raea-screen:name@WIDTHxHEIGHT`, the SDK's targetImage: Bevy's+/// render_ui_to_texture, a UiTexture's UI drawn into it as a <Screen>'s picture is), made if no screen has it yet; None+/// for any other source, or a World without screens.+pub fn named_image(world: &mut World, src: &str) -> Option<Handle<Image>> {+ let (name, size) = src.strip_prefix("raea-screen:")?.rsplit_once('@')?;+ let (w, h) = size.split_once('x')?;+ let (w, h) = (w.parse::<u32>().ok()?.max(1), h.parse::<u32>().ok()?.max(1));+ world.contains_resource::<ScreenImages>().then(|| image(world, name, w, h))+}+/// A screen's image: black, the source's size, filled each frame by the host's copy.fn image(world: &mut World, name: &str, w: u32, h: u32) -> Handle<Image> {if let Some((hd, iw, ih)) = world.resource::<ScreenImages>().0.get(name) {diff --git a/tools/taxonomy.list b/tools/taxonomy.listindex ede430db..4064049e 100644--- a/tools/taxonomy.list+++ b/tools/taxonomy.list@@ -85,3 +85,4 @@ raea Field a signed distance field as text (raea-core-sdf), meshed intraea BevyApp Bevy's App as a TypeScript object for programs (App is its Bevy name, also exported)raea BevyComponent any reflected Bevy component on an entity by its type path (the TypeRegistry)raea BevyResource any reflected Bevy resource by its type path (the TypeRegistry)+raea UiTexture the UI roots a Camera2d with RenderTarget::Image draws into a named image (Bevy spreads it over camera, target and UiTargetCamera)