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
#18: what an element paints at an offset of its own is placed in its own axes, so it turns with a rotated ancestor. blitz-paint added background-position, a background's tiles (image and gradient), box-shadow offsets (outer and inset), text-shadow offsets, the scroll offset, an inline SVG's and a custom widget's content-box origin after the element's transform (then_translate), in the page's axes; they now go before it (pre_translate), as an <img>'s already did. One image split across stacked divs by background-position stopped lining up under a -4deg parent, and an inset shadow's band came out uneven. The inset shadow's offset also takes the page's scale now, as the outer one's does. bench/rotated-paint/check.sh draws the same picture twice under -4deg (three background slices of one image and of one gradient, and a box shadow, against one div each and a box behind): 7,811 pixels differ by more than 10% on the raea before this, 37 after (the slices' antialiased seams); it passes at 200. Eight unrotated parity cases (background-image, background-shorthand, gradient-tiles, shadow, shadow-forms, overflow-scroll, repeating-gradient, conic-gradient) are pixel-identical before and after.
shinyobjectzaef305429a2e
diff --git a/bench/rotated-paint/check.sh b/bench/rotated-paint/check.shnew file mode 100755index 00000000..844950aa--- /dev/null+++ b/bench/rotated-paint/check.sh@@ -0,0 +1,17 @@+#!/bin/bash+# #18: edit.tsx's "sliced" and "whole" pictures under a -4deg rotation must match, but for the seams between slices+# (each slice's edge antialiased against the next): at most 200 pixels may differ by more than 10%. When a background's+# position, its tiles or a box shadow's offset move in the page's axes instead of the element's, about 7,800 do.+# bench/rotated-paint/check.sh (RAEA_BIN: the raea to run, default target/release/raea)+cd "$(dirname "$0")/../.." || exit 2+BIN=${RAEA_BIN:-$PWD/target/release/raea}+# pixel checks: no Content Credentials or TrustMark id in the frames+export RAEA_SIGN=0 RAEA_MARK=0+OUT=$(mktemp -d "${TMPDIR:-/tmp}/raea-rotated-paint.XXXXXX")+trap 'rm -rf "$OUT"' EXIT+for c in sliced whole; do+ "$BIN" render bench/rotated-paint/edit.tsx --composition $c -o "$OUT/$c.png" > "$OUT/$c.log" 2>&1 || { echo "FAIL: the $c render failed"; tail -5 "$OUT/$c.log"; exit 1; }+done+d=$(magick compare -metric AE -fuzz 10% "$OUT/sliced.png" "$OUT/whole.png" null: 2>&1 | cut -d' ' -f1 | cut -d. -f1)+[ -n "$d" ] && [ "$d" -le 200 ] || { echo "FAIL: ${d:-?} pixels differ between the sliced and whole pictures (at most 200)"; exit 1; }+echo "PASS: $d pixels differ between the sliced and whole pictures (the seams)"diff --git a/bench/rotated-paint/edit.tsx b/bench/rotated-paint/edit.tsxnew file mode 100644index 00000000..92f719c0--- /dev/null+++ b/bench/rotated-paint/edit.tsx@@ -0,0 +1,45 @@+// #18: what an element paints at an offset of its own (background-position, a background's tiles, a box shadow) moves+// in the element's axes, so it turns with a rotated ancestor. Each composition draws the same picture two ways under a+// -4deg rotation: "sliced" splits one background image and one gradient across stacked divs by background-position,+// and gives a box a shadow; "whole" draws each image in one div and the shadow as a box behind. check.sh compares them.+import { AbsoluteFill, Composition, registerRoot } from "raea";++// an 8 x 8 of four quarters (yellow, clear, blue, green), drawn 240 px a side+const QUAD = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAIUlEQVR4nGP4dUb0PzJmQAd0UKCa/Po/MlY6GoeC6aAAABvgeQHBIU/gAAAAAElFTkSuQmCC";+const GRAD = "repeating-linear-gradient(35deg, #e11d48 0 18px, #0ea5e9 18px 36px, #fde047 36px 54px)";+const W = 240;+const H = 300;+const CUTS = [0, 110, 190, H];+const at = (left: number, top: number, w: number, h: number) => ({ position: "absolute", left, top, width: w, height: h }) as const;+const image = { backgroundImage: `url("${QUAD}")`, backgroundSize: `${W}px ${W}px`, backgroundRepeat: "repeat", imageRendering: "pixelated" } as const;++function Stack({ sliced, left, bg }: { sliced: boolean; left: number; bg: object }) {+ if (!sliced) return <div style={{ ...at(left, 0, W, H), ...bg }} />;+ return (+ <>+ {CUTS.slice(1).map((end, k) => (+ <div key={k} style={{ ...at(left, CUTS[k], W, end - CUTS[k]), ...bg, backgroundPosition: `0px ${-CUTS[k]}px` }} />+ ))}+ </>+ );+}++function Picture({ sliced }: { sliced: boolean }) {+ return (+ <AbsoluteFill style={{ background: "#151515" }}>+ <div style={{ ...at(200, 150, 900, 420), transform: "rotate(-4deg)", transformOrigin: "50% 60%" }}>+ <Stack sliced={sliced} left={0} bg={image} />+ <Stack sliced={sliced} left={300} bg={{ backgroundImage: GRAD, backgroundSize: `${W}px ${H}px` }} />+ {!sliced && <div style={{ ...at(620, 60, 200, 160), background: "#a3e635" }} />}+ <div style={{ ...at(600, 30, 200, 160), background: "#f6f1e8", boxShadow: sliced ? "20px 30px 0 #a3e635" : undefined }} />+ </div>+ </AbsoluteFill>+ );+}++registerRoot(() => (+ <>+ <Composition id="sliced" component={() => <Picture sliced />} width={1280} height={720} fps={30} durationInFrames={1} />+ <Composition id="whole" component={() => <Picture sliced={false} />} width={1280} height={720} fps={30} durationInFrames={1} />+ </>+));diff --git a/vendor/blitz-paint/src/render.rs b/vendor/blitz-paint/src/render.rsindex 23d16265..b3031b05 100644--- a/vendor/blitz-paint/src/render.rs+++ b/vendor/blitz-paint/src/render.rs@@ -1261,7 +1261,8 @@ impl<'dom, 'a> BlitzDomPainter<'dom, 'a> {y: content_position.y - node.scroll_offset().y,};- cx.transform = cx.transform.then_translate(Vec2 {+ // raea: scrolled in the element's axes (#18)+ cx.transform = cx.transform.pre_translate(Vec2 {x: -node.scroll_offset().x * self.scale,y: -node.scroll_offset().y * self.scale,});@@ -2113,10 +2114,11 @@ impl ElementCx<'_, '_> {None if inline || !natural => Affine::scale(self.scale),_ => svg_viewport_affine(svg, paint_size.width, paint_size.height),};- let transform = (self.transform * viewport).then_translate(Vec2 { x, y });+ // raea: the content box's place in the element's axes (#18): before its transform, not after+ let transform = self.transform.pre_translate(Vec2 { x, y }) * viewport;// raea: the same, split where a non-scaling stroke is drawn (anyrender_svg render_svg_tree_in): the page's// place and device scale, then the viewBox's mapping in CSS px- let host = (self.transform * Affine::scale(self.scale)).then_translate(Vec2 { x, y });+ let host = self.transform.pre_translate(Vec2 { x, y }) * Affine::scale(self.scale);let in_css = Affine::scale(1.0 / self.scale) * viewport;// raea: its text grown as the page's text is (text.rs svg_text_look)anyrender_svg::set_text_look(crate::text::svg_text_look);@@ -2255,7 +2257,7 @@ impl ElementCx<'_, '_> {if let Some(widget_scene) = self.custom_widget_scene {let x = self.frame.content_box.origin().x;let y = self.frame.content_box.origin().y;- let transform = self.transform.then_translate(Vec2 { x, y });+ let transform = self.transform.pre_translate(Vec2 { x, y }); // raea: in the element's axes (#18)// TODO: eliminate clonescene.append_scene(widget_scene.clone(), transform);diff --git a/vendor/blitz-paint/src/render/background.rs b/vendor/blitz-paint/src/render/background.rsindex 96879157..315ef6ce 100644--- a/vendor/blitz-paint/src/render/background.rs+++ b/vendor/blitz-paint/src/render/background.rs@@ -532,20 +532,23 @@ impl ElementCx<'_, '_> {y_ratio,);- let transform = base_transform- .pre_scale_non_uniform(x_ratio, y_ratio)- .then_translate(Vec2 {- x: x.translate,- y: y.translate,- });+ // raea: the position and each tile's place are in the element's own axes, so they go before its transform+ // (pre_translate); after it (then_translate) they moved in the page's axes, and under a rotated ancestor+ // slices of one image set apart by background-position stopped lining up (#18)+ let transform = base_transform.pre_translate(Vec2 {+ x: x.translate,+ y: y.translate,+ });let tile_rect = Rect::new(0.0, 0.0, x.rect_len, y.rect_len);for hc in 0..y.count {for wc in 0..x.count {- let transform = transform.then_translate(Vec2 {- x: wc as f64 * x.stride,- y: hc as f64 * y.stride,- });+ let transform = transform+ .pre_translate(Vec2 {+ x: wc as f64 * x.stride,+ y: hc as f64 * y.stride,+ })+ .pre_scale_non_uniform(x_ratio, y_ratio);scene.fill(peniko::Fill::NonZero,@@ -621,7 +624,8 @@ impl ElementCx<'_, '_> {¤t_color,);- let transform = base_transform.then_translate(Vec2 {+ // raea: in the element's axes, as an image layer's (#18)+ let transform = base_transform.pre_translate(Vec2 {x: x.translate,y: y.translate,});@@ -658,7 +662,7 @@ impl ElementCx<'_, '_> {for hc in 0..y.count {for wc in 0..x.count {- let transform = transform.then_translate(Vec2 {+ let transform = transform.pre_translate(Vec2 {x: wc as f64 * x.stride,y: hc as f64 * y.stride,});diff --git a/vendor/blitz-paint/src/render/box_shadow.rs b/vendor/blitz-paint/src/render/box_shadow.rsindex 5edd1067..043e87e0 100644--- a/vendor/blitz-paint/src/render/box_shadow.rs+++ b/vendor/blitz-paint/src/render/box_shadow.rs@@ -53,7 +53,8 @@ impl ElementCx<'_, '_> {let alpha = shadow_color.components[3];if alpha != 0.0 {- let transform = self.transform.then_translate(Vec2 {+ // raea: the offset in the element's axes, so it turns with a rotated element (#18)+ let transform = self.transform.pre_translate(Vec2 {x: shadow.base.horizontal.px() as f64 * self.scale,y: shadow.base.vertical.px() as f64 * self.scale,});@@ -112,9 +113,10 @@ impl ElementCx<'_, '_> {// TODO draw shadows with matching individual radii instead of averaginglet radius = self.frame.border_radii.average();- let transform = self.transform.then_translate(Vec2 {- x: shadow.base.horizontal.px() as f64,- y: shadow.base.vertical.px() as f64,+ // raea: in the element's axes (#18), and at the page's scale, as an outer shadow's offset is+ let transform = self.transform.pre_translate(Vec2 {+ x: shadow.base.horizontal.px() as f64 * self.scale,+ y: shadow.base.vertical.px() as f64 * self.scale,});scene.push_layer(diff --git a/vendor/blitz-paint/src/text.rs b/vendor/blitz-paint/src/text.rsindex 6916daf6..825e0525 100644--- a/vendor/blitz-paint/src/text.rs+++ b/vendor/blitz-paint/src/text.rs@@ -964,7 +964,7 @@ pub(crate) fn stroke_text<'a>(if color.components[3] == 0.0 {continue;}- let at = transform.then_translate(kurbo::Vec2::new(dx * scale, dy * scale));+ let at = transform.pre_translate(kurbo::Vec2::new(dx * scale, dy * scale)); // in the run's axes (#18)let sigma = blur * scale / 2.0;if sigma > 0.0 {let reach = sigma * 3.0;diff --git a/vendor/vendor.toml b/vendor/vendor.tomlindex a411ccda..c1a0d71d 100644--- a/vendor/vendor.toml+++ b/vendor/vendor.toml@@ -56,7 +56,7 @@ exit = "a bevy_ui_widgets release on parley 0.12"path = "vendor/blitz-paint"upstream = "crates.io:0.3.0-beta.4"kind = "patch"-reason = "angled tile gradients, many-tile gradient layers as one brush, text-shadow, ellipsis, inline-box opacity, box-shadow blur as Chrome's; filters by GPU passes (B4a/B4b); z-index boxes clipped by the overflow between them and their stacking context; a range input's thumb"+reason = "angled tile gradients, many-tile gradient layers as one brush, text-shadow, ellipsis, inline-box opacity, box-shadow blur as Chrome's; filters by GPU passes (B4a/B4b); z-index boxes clipped by the overflow between them and their stacking context; a range input's thumb; what an element paints at an offset of its own (background position and tiles, box and text shadows, scroll, inline SVG) placed in its own axes under a rotated ancestor (#18)"exit = "a Blitz release that draws these"[blitz-dom]