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: bevy_ui's BorderGradient (the bottom layer over the border box, a node's own gradients over it clipped to the padding box; none without a border; a translucent background gradient over one refused); ui/styling/gradients ported
shinyobjectz4e570ce401c7
diff --git a/bench/bevy-parity/examples.list b/bench/bevy-parity/examples.listindex aa757965..967b9089 100644--- a/bench/bevy-parity/examples.list+++ b/bench/bevy-parity/examples.list@@ -69,3 +69,4 @@ ui/window_fallthroughui/text/inline_imageui/layout/z_indexui/styling/stacked_gradients+ui/styling/gradientsdiff --git a/bench/bevy-parity/runs.tsv b/bench/bevy-parity/runs.tsvindex 92bd8dee..d9e4ce0e 100644--- a/bench/bevy-parity/runs.tsv+++ b/bench/bevy-parity/runs.tsv@@ -68,3 +68,4 @@ ui/window_fallthrough - 10ui/text/inline_image - 10ui/layout/z_index - 10ui/styling/stacked_gradients - 10+ui/styling/gradients - 10diff --git a/docs/bevy-parity.md b/docs/bevy-parity.mdindex dddc0f61..93a97786 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 **69**, passing **65**, excluded **16** (docs/bevy-parity/excluded.tsv), left **357**.+Examples: **438**, ported **70**, passing **66**, excluded **16** (docs/bevy-parity/excluded.tsv), left **356**.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.@@ -125,6 +125,7 @@ doesn't pay.| ui/images/ui_texture_atlas | 5 | 0.999776 | 6 | 0 / 0 | 445 / 492 | 5 / 7 | 1 / 1 | 55.621 / 2.426 = 2.226 + 0.200 | yes | || ui/text/inline_image | 10 | 0.998473 | 8 | 0 / 0 | 446 / 492 | 5 / 7 | 1 / 1 | 30.442 / 1.739 = 1.421 + 0.318 | yes | || ui/styling/stacked_gradients | 10 | 0.994550 | 1 | 0 / 0 | 442 / 492 | 5 / 7 | 1 / 1 | 31.919 / 1.669 = 1.514 + 0.155 | yes | |+| ui/styling/gradients | 10 | 0.988141 | 14 | 0 / 0 | 553 / 492 | 5 / 7 | 1 / 1 | 43.397 / 5.563 = 2.245 + 3.318 | yes | |## Excludeddiff --git a/docs/bevy-parity/results.jsonl b/docs/bevy-parity/results.jsonlindex fb33c7d4..cb301cc0 100644--- a/docs/bevy-parity/results.jsonl+++ b/docs/bevy-parity/results.jsonl@@ -112,3 +112,4 @@{"example":"ui/images/ui_texture_atlas","frame":5,"ssim":0.999776,"tile":6,"bevy":{"batch_keys":0,"entities":445,"extents":[],"frame":5,"frame_ms":55.621,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":12,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":2.226,"step_ms":0.200,"cost_ms":2.426},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"ui/text/inline_image","frame":10,"ssim":0.998473,"tile":8,"bevy":{"batch_keys":0,"entities":446,"extents":[],"frame":10,"frame_ms":30.442,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.421,"step_ms":0.318,"cost_ms":1.739},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"ui/styling/stacked_gradients","frame":10,"ssim":0.994550,"tile":1,"bevy":{"batch_keys":0,"entities":442,"extents":[],"frame":10,"frame_ms":31.919,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.514,"step_ms":0.155,"cost_ms":1.669},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}+{"example":"ui/styling/gradients","frame":10,"ssim":0.988141,"tile":14,"bevy":{"batch_keys":0,"entities":553,"extents":[],"frame":10,"frame_ms":43.397,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":2.245,"step_ms":3.318,"cost_ms":5.563},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}diff --git a/sdk/raea/bench/bevy-parity/ui/styling/gradients.tsx b/sdk/raea/bench/bevy-parity/ui/styling/gradients.tsxnew file mode 100644index 00000000..3e80d041--- /dev/null+++ b/sdk/raea/bench/bevy-parity/ui/styling/gradients.tsx@@ -0,0 +1,82 @@+// Bevy v0.20.0 examples/ui/styling/gradients.rs in raea's TSX: three rows, each of 24 linear gradients (70 x 70,+// 35 x 70 and 70 x 35, at the eight angles a turn apart by an eighth) and three squares as tall as the row (a linear+// gradient turning at 0.5 rad/s, a ClosestSide radial one and a conic one), every node 20 px round with a yellow,+// white and orange border gradient: white to black (4 px borders), red, blue and lime (4 px), and the rainbow in hard+// stops (none). Under them "Current Space / Oklaba" between the Previous and Next buttons. In Oklab, Bevy's default;+// its buttons see no pointer here. Bevy's Camera2d over the default clear colour is the layered <Canvas3D>. In Bevy's+// default 1280 x 720 window, at frame 10 (its updates of 1/60 s turned the squares' linear gradients).+import { AbsoluteFill, Composition, registerRoot, useCurrentFrame } from "raea";+import { Canvas3D } from "raea/3d";+import { AngularColorStop, BorderRadius, ColorStop, ConicGradient, LinearGradient, Node, RadialGradient, Text, UiPosition, UiRect, percent, px, type Gradient } from "raea/ui";+import { Srgba } from "raea/color";++const TAU = 2 * Math.PI;+const [RED, BLUE, LIME, ORANGE, YELLOW] = [new Srgba(1, 0, 0), new Srgba(0, 0, 1), new Srgba(0, 1, 0), new Srgba(1, 0.64705884, 0), new Srgba(1, 1, 0)];+const [GREEN, INDIGO, VIOLET] = [new Srgba(0, 0.5019608, 0), new Srgba(0.29411766, 0, 0.50980395), new Srgba(0.93333334, 0.50980395, 0.93333334)];+const [WHITE, BLACK] = [new Srgba(1, 1, 1), new Srgba(0, 0, 0)];++const RAINBOW = [RED, ORANGE, YELLOW, GREEN, BLUE, INDIGO, VIOLET];+const ROWS: [number, ColorStop[]][] = [+ [4, [ColorStop.new(WHITE, percent(15)), ColorStop.new(BLACK, percent(85))]],+ [4, [ColorStop.auto(RED), ColorStop.auto(BLUE), ColorStop.auto(LIME)]],+ // each colour from i/7 to (i+1)/7 of the way+ [0, [ColorStop.auto(RED), ...RAINBOW.flatMap((c, i) => [i > 0 ? ColorStop.new(c, percent((100 * i) / 7)) : null, i < 6 ? ColorStop.new(c, percent((100 * (i + 1)) / 7)) : null]).filter((s): s is ColorStop => s !== null), ColorStop.auto(VIOLET)]],+];+const BORDER: Gradient[] = [LinearGradient.new((3 * TAU) / 8, [ColorStop.auto(YELLOW), ColorStop.auto(WHITE), ColorStop.auto(ORANGE)])];++/** The squares' linear angle after frame f's updates: each turns it 0.5 x its delta_secs (none on the first), in f32 */+function turnAt(f: number): number {+ let a = 0;+ for (let k = 1; k <= f; k++) a = Math.fround(a + Math.fround(0.5 * Math.fround(16_666_667e-9)));+ return a;+}++function Row({ b, stops, turn }: { b: number; stops: ColorStop[]; turn: number }) {+ const rounded = { border: UiRect.all(px(b)), border_radius: BorderRadius.all(px(20)), border_gradient: BORDER };+ const square = { ...rounded, aspect_ratio: 1, height: percent(100), margin: UiRect.left(px(20)) };+ return (+ <Node>+ <Node flex_direction="Column" row_gap={px(5)}>+ {[[70, 70], [35, 70], [70, 35]].map(([w, h]) => (+ <Node key={`${w}x${h}`} column_gap={px(10)}>+ {Array.from({ length: 8 }, (_, i) => <Node key={i} width={px(w)} height={px(h)} {...rounded} background_gradient={[LinearGradient.new((i * TAU) / 8, stops)]} />)}+ </Node>+ ))}+ </Node>+ <Node>+ <Node {...square} background_gradient={[LinearGradient.new(turn, stops)]} />+ <Node {...square} background_gradient={[RadialGradient.new(UiPosition.CENTER, "ClosestSide", stops)]} />+ <Node {...square} background_gradient={[ConicGradient.new(UiPosition.CENTER, stops.map((s) => AngularColorStop.auto(s.color)))]} />+ </Node>+ </Node>+ );+}++function Button({ caption }: { caption: string }) {+ return (+ <Node border={UiRect.all(px(2))} padding={UiRect.axes(px(8), px(4))} justify_content="Center" align_items="Center" border_radius={BorderRadius.MAX} border_color={WHITE} background_color={BLACK}>+ <Text>{caption}</Text>+ </Node>+ );+}++function Shot() {+ const turn = turnAt(useCurrentFrame());+ return (+ <AbsoluteFill>+ <Canvas3D layered clearColor="rgb(43, 44, 47)" />+ <Node flex_direction="Column" row_gap={px(20)} margin={UiRect.all(px(20))}>+ {ROWS.map(([b, stops], i) => <Row key={i} b={b} stops={stops} turn={turn} />)}+ <Node flex_direction="Row" align_items="Center" justify_content="Center" column_gap={px(20)}>+ <Node align_items="Center" justify_content="Center">+ <Text>{"Current Space\nOklaba"}</Text>+ </Node>+ <Button caption="Previous" />+ <Button caption="Next" />+ </Node>+ </Node>+ </AbsoluteFill>+ );+}++registerRoot(() => <Composition id="main" component={Shot} durationInFrames={11} fps={60} width={1280} height={720} />);diff --git a/sdk/raea/conformance/ui.test.tsx b/sdk/raea/conformance/ui.test.tsxindex fd411342..3464fd9d 100644--- a/sdk/raea/conformance/ui.test.tsx+++ b/sdk/raea/conformance/ui.test.tsx@@ -1,7 +1,7 @@// docs/control.feature FC0a: bevy_ui's Node, Text and TextSpan on the page, with Bevy's defaults, values and blend// (ui/styling/transparency_ui, ui/layout/fixed_node).import { describe, expect, test } from "bun:test";-import { AngularColorStop, ColorStop, ConicGradient, LinearGradient, RadialGradient, UiPosition, BorderRadius, CornerRadius, FontVariationTag, ImageNode, InlineImage, ImagePlugin, Node, TextureAtlasLayout, Overflow, OverflowClipMargin, Text, TextShadow, Text2d, UiScale, TextSpan, UiRect, auto, percent, px, vw } from "raea/ui";+import { AngularColorStop, UiRect as GradRect, ColorStop, ConicGradient, LinearGradient, RadialGradient, UiPosition, BorderRadius, CornerRadius, FontVariationTag, ImageNode, InlineImage, ImagePlugin, Node, TextureAtlasLayout, Overflow, OverflowClipMargin, Text, TextShadow, Text2d, UiScale, TextSpan, UiRect, auto, percent, px, vw } from "raea/ui";import { LinearRgba, Srgba } from "raea/color";import { Canvas3D } from "raea/3d";import { renderFrame } from "../src/test";@@ -223,6 +223,15 @@ describe("A sliced ImageNode, a sampled picture and UiScale", () => {expect(hinted).toContain("linear-gradient(0rad in srgb, rgba(255, 0, 0, 1) 0px, calc(0px + (100px - 0px) * 0.25), rgba(255, 0, 0, 0) 100px)");expect(() => html(<Node background_gradient={[RadialGradient.new(UiPosition.CENTER, { Circle: percent(10) }, [ColorStop.auto(red)])]} />)).toThrow(/Circle's radius in percent/);});+ test("BorderGradient is the bottom layer over the border box, the node's gradients over it clipped to the padding box, none without a border", () => {+ const g = [LinearGradient.to_right([ColorStop.auto(new Srgba(1, 1, 0)), ColorStop.auto(new Srgba(1, 0.5, 0))])];+ const own = [LinearGradient.to_top([ColorStop.auto(new Srgba(1, 0, 0)), ColorStop.auto(new Srgba(0, 0, 1))])];+ const out = html(<Node border={GradRect.all(px(4))} background_gradient={own} border_gradient={g} />);+ expect(out).toContain("background-image:linear-gradient(0rad in oklab, rgba(255, 0, 0, 1), rgba(0, 0, 255, 1)), linear-gradient(1.5707963267948966rad in oklab, rgba(255, 255, 0, 1), rgba(255, 128, 0, 1))");+ expect(out).toContain("background-clip:padding-box, border-box");+ expect(html(<Node border={GradRect.all(px(0))} background_gradient={own} border_gradient={g} />)).not.toContain("background-clip");+ expect(() => html(<Node border={GradRect.all(px(4))} background_gradient={[LinearGradient.to_top([ColorStop.auto(new Srgba(1, 0, 0, 0.5))])]} border_gradient={g} />)).toThrow(/translucent background_gradient/);+ });test("BorderColor takes a colour per side", () => {const out = html(<Node border={UiRect.all(px(2))} border_color={{ top: new Srgba(1, 0, 0), right: new Srgba(0, 0, 1), bottom: new Srgba(1, 1, 0), left: new Srgba(0, 1, 0) }} />);expect(out).toContain("border-color:rgba(255, 0, 0, 1) rgba(0, 0, 255, 1) rgba(255, 255, 0, 1) rgba(0, 255, 0, 1)");diff --git a/sdk/render/src/bevy3d/ui-gradient.ts b/sdk/render/src/bevy3d/ui-gradient.tsindex 85a96b9e..d4166a6c 100644--- a/sdk/render/src/bevy3d/ui-gradient.ts+++ b/sdk/render/src/bevy3d/ui-gradient.ts@@ -142,3 +142,12 @@ export function gradientsCss(who: string, gs: Gradient[]): string {if (!Array.isArray(gs)) throw new TypeError(`${who}: background_gradient is a list of gradients, got ${JSON.stringify(gs)}`);return gs.map((g) => gradientCss(who, g)).reverse().join(", ");}++/** Whether every stop of these gradients is opaque (a colour's alpha 1). */+export function gradientsOpaque(who: string, gs: Gradient[]): boolean {+ return gs.every((g) => g.stops.every((s) => {+ const css = colorCss(who, "stop", s.color);+ const a = /^rgba\(.*,\s*([\d.e+-]+)\)$/.exec(css);+ return a ? Number(a[1]) >= 1 : !/^(transparent|#[0-9a-f]{4}$|#[0-9a-f]{8}$|hsla|rgba|.*\/)/i.test(css);+ }));+}diff --git a/sdk/render/src/bevy3d/ui-val.ts b/sdk/render/src/bevy3d/ui-val.tsindex 95b2924c..169e5136 100644--- a/sdk/render/src/bevy3d/ui-val.ts+++ b/sdk/render/src/bevy3d/ui-val.ts@@ -143,9 +143,9 @@ export function colorCss(who: string, k: string, c: unknown): string {}/** What lies under a part of the UI, in linear light, when it's known: an opaque Node colour, or translucent ones over- * one. Bevy draws its UI onto an sRGB target, so a translucent colour blends in linear light; the page blends in sRGB.- * Over a known backdrop the colour is sent as the opaque colour Bevy's blend makes (white at 0.2 over srgb 0.1 green- * is 126, not the page's 72); over the 3D (unknown) it's sent as it is. */+ * one. Bevy draws its UI onto an sRGB target, so a translucent colour blends in linear light, as a page with bevy_ui in it+ * now does too (data-raea-blend). Over a known backdrop the colour is sent as the opaque colour Bevy's blend makes (white+ * at 0.2 over srgb 0.1 green is 126; sRGB blending made 72); over the 3D (unknown) it's sent as it is. */export type Backdrop = [number, number, number] | undefined;const toLinear = (c: number) => (c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4));diff --git a/sdk/render/src/bevy3d/ui.tsx b/sdk/render/src/bevy3d/ui.tsxindex 982e1156..623c122f 100644--- a/sdk/render/src/bevy3d/ui.tsx+++ b/sdk/render/src/bevy3d/ui.tsx@@ -10,7 +10,7 @@ import {checkVal, keyword, over, radiusCss, rectCss, type Backdrop, type BorderRadius, type Overflow, type OverflowClipMargin, type UiRect, type Val,} from "./ui-val";import { LinearRgba, type Srgba } from "./colors";-import { gradientsCss, type Gradient } from "./ui-gradient";+import { gradientsCss, gradientsOpaque, type Gradient } from "./ui-gradient";import type { TransformValue } from "./core";import { eulerOf } from "../3d/model";import { useVideoConfig } from "@raea/app/clock";@@ -44,6 +44,8 @@ export interface NodeProps {background_color?: Color;/** BackgroundGradient: gradients over the background colour, the first at the bottom, over the whole node */background_gradient?: Gradient[];+ /** BorderGradient: gradients over the border, laid out over the whole node */+ border_gradient?: Gradient[];/** BorderColor: every side one colour, or each its own ({ top, right, bottom, left }) */border_color?: Color | { top: Color; right: Color; bottom: Color; left: Color };/** Outline: a line outside the border box, `offset` from it (0 by default), white by default */@@ -121,6 +123,19 @@ export function nodeCss(who: string, p: NodeProps, back?: Backdrop): { css: CSSPs.backgroundOrigin = "border-box";back = undefined;}+ // (Bevy draws a BorderGradient over the border alone, and CSS clips no layer to the border's area: it is the bottom+ // layer over the border box and the node's own gradients sit over it clipped to the padding box, the background+ // colour under both, which is Bevy's picture while those gradients are opaque)+ // (no border, nothing to draw: its layer would show at the background's antialiased edge)+ const bordered = p.border !== undefined && [p.border.left, p.border.right, p.border.top, p.border.bottom].some((v) => parseFloat(String(v)) !== 0);+ if (p.border_gradient !== undefined && bordered) {+ if (p.border_color !== undefined) throw new TypeError(`${who}: border_color with border_gradient is to do; give one`);+ const own = p.background_gradient ?? [];+ if (!gradientsOpaque(who, own)) throw new TypeError(`${who}: border_gradient under a translucent background_gradient is to do`);+ s.backgroundImage = [...(own.length ? [s.backgroundImage] : []), gradientsCss(who, p.border_gradient)].join(", ");+ s.backgroundOrigin = "border-box";+ s.backgroundClip = [...own.map(() => "padding-box"), ...p.border_gradient.map(() => "border-box")].join(", ");+ }// (the border over its own background, as Bevy draws it)const bc = p.border_color;if (bc !== undefined && typeof bc === "object" && "top" in bc) {