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
A filter takes in what its element draws outside its box, as Chrome filters it
James Dimachkie43e8892ce23a
diff --git a/bench/filter-overflow/check.sh b/bench/filter-overflow/check.shnew file mode 100755index 00000000..5c559050--- /dev/null+++ b/bench/filter-overflow/check.sh@@ -0,0 +1,43 @@+#!/bin/bash+# A filter takes in all its element draws, as Chrome filters it: what its descendants draw outside its box too.+# raea-page's filter layer was the element's border box grown by the filter's reach, so a blurred wrapper of no size+# lost its absolutely positioned children (a few px of blur were left), and a 60 px box with grayscale(1) showed 60 px+# of a 200x100 child. page.tsx draws both, and the same box clipping its overflow (which must still cut the child)+# and clipping x alone (which cuts its side and shows all its height), and a grayscale box around a square whose+# own drop shadow falls outside it. Each probe is Chrome 157's pixel, within 3.+# The layer stops at a clip in the way: clipped.tsx's 60 small filtered boxes each hold a clipping box with a child+# that covers the frame (30 of the clipping boxes in flow, 30 painted by the filtered box's stacking context), and 30+# layers the size of the frame are more than Vello's image atlas holds, so its 60 tiles are counted (from the+# frame's mean: each is 60x60 of grey 92 on white). Exits 1 on a failure.+# bench/filter-overflow/check.sh (RAEA_BIN: the raea to run, default target/release/raea)+cd "$(dirname "$0")/../.." || exit 2+BIN=${RAEA_BIN:-$PWD/target/release/raea}+export RAEA_SIGN=0 RAEA_MARK=0 RAEA_EXPORT_CACHE=0+OUT=$(mktemp -d "${TMPDIR:-/tmp}/raea-filter-overflow.XXXXXX")+trap 'rm -rf "$OUT"' EXIT+for c in page clipped; do+ mkdir -p "$OUT/$c"+ "$BIN" render bench/filter-overflow/$c.tsx --at 0 -o "$OUT/$c" > "$OUT/$c.log" 2>&1 && [ -f "$OUT/$c/frame-00000.png" ] || { echo "FAIL $c: the render failed"; sed 's/^/ /' "$OUT/$c.log" | tail -4; exit 1; }+done+status=0+want() { # X,Y R G B WHAT: page.tsx's pixel, each channel within 3+ local p; p=$(magick "$OUT/page/frame-00000.png" -alpha off -format "%[fx:int(255*p{$1}.r+0.5)] %[fx:int(255*p{$1}.g+0.5)] %[fx:int(255*p{$1}.b+0.5)]" info:)+ read -r r g b <<< "$p"+ (( r - $2 <= 3 && $2 - r <= 3 && g - $3 <= 3 && $3 - g <= 3 && b - $4 <= 3 && $4 - b <= 3 )) || { echo "FAIL at $1: $p, wanted $2 $3 $4 ($5)"; status=1; }+}+want 100,100 255 0 0 "a blurred wrapper's first child, its middle"+want 240,100 0 0 255 "its second child"+want 430,90 54 54 54 "a grayscale box's red child"+want 530,90 54 54 54 "the child's own drop shadow, outside the box"+want 480,90 255 255 255 "between them"+want 70,250 92 92 92 "a grayscale box's child, inside the box"+want 190,270 92 92 92 "the child past the box"+want 190,330 255 255 255 "below the child"+want 370,250 92 92 92 "a clipping box's child, inside the box"+want 450,270 255 255 255 "its child past the box, clipped"+want 500,300 92 92 92 "a box clipping x alone: its child below the box"+want 580,250 255 255 255 "and its child past its side, clipped"+tiles=$(magick "$OUT/clipped/frame-00000.png" -alpha off -colorspace gray -format "%[fx:int((1-mean)*1920*1080/(3600*(1-92/255))+0.5)]" info:)+[ "$tiles" = 60 ] || { echo "FAIL clipped.tsx: $tiles of its 60 tiles drawn"; status=1; }+[ $status = 0 ] && echo "PASS a filter over what its element draws outside its box"+exit $statusdiff --git a/bench/filter-overflow/clipped.tsx b/bench/filter-overflow/clipped.tsxnew file mode 100644index 00000000..3d3a9c84--- /dev/null+++ b/bench/filter-overflow/clipped.tsx@@ -0,0 +1,20 @@+// 60 small filtered boxes, each around a clipping box of its size holding a child that covers the frame from any of+// them (the last 30 clipping boxes positioned with a z-index, so the filtered box's stacking context paints them):+// 60 grey 60 px tiles on white. A filter's layer reaches over what its element draws, and stops at a clip in+// the way: made from the element's overflow, which reaches through clips, each of these layers would be the size of+// the frame, and 30 of them are more than Vello's image atlas holds, of either kind. bench/filter-overflow/check.sh+import { AbsoluteFill, Composition, registerRoot } from "raea";+function O() {+ return (+ <AbsoluteFill style={{ background: "#fff" }}>+ {Array.from({ length: 60 }, (_, i) => (+ <div key={i} style={{ position: "absolute", left: 60 + (i % 10) * 180, top: 60 + Math.floor(i / 10) * 170, width: 60, height: 60, filter: "grayscale(1)" }}>+ <div style={{ width: 60, height: 60, overflow: "hidden", ...(i < 30 ? {} : { position: "relative", zIndex: 1 }) }}>+ <div style={{ position: "relative", left: -2000, top: -1500, width: 4000, height: 3000, background: "#008000" }} />+ </div>+ </div>+ ))}+ </AbsoluteFill>+ );+}+registerRoot(() => <Composition id="o" component={O} width={1920} height={1080} fps={30} durationInFrames={1} />);diff --git a/bench/filter-overflow/page.tsx b/bench/filter-overflow/page.tsxnew file mode 100644index 00000000..9cbf6a70--- /dev/null+++ b/bench/filter-overflow/page.tsx@@ -0,0 +1,26 @@+// A filter takes in all its element draws, what its descendants draw outside its box included. Top: a wrapper of no+// size with a blur, around two absolutely positioned squares; and a 60 px box with grayscale(1) around a red square+// whose own drop shadow falls 100 px to its right. Below, a 60 px box with grayscale(1) holding a 200x100 green+// child, three ways: as it is (all of the child shows), clipping its overflow (60 px of it), and clipping x alone+// (60 px wide, all 100 px tall). bench/filter-overflow/check.sh+import { AbsoluteFill, Composition, registerRoot } from "raea";+const square = (left: number, background: string) => <div style={{ position: "absolute", left, top: 0, width: 120, height: 120, background }} />;+const box = (left: number, clip: object) => (+ <div style={{ position: "absolute", left, top: 220, width: 60, height: 60, filter: "grayscale(1)", ...clip }}>+ <div style={{ width: 200, height: 100, background: "#008000" }} />+ </div>+);+function O() {+ return (+ <AbsoluteFill style={{ background: "#fff" }}>+ <div style={{ position: "absolute", left: 40, top: 40, filter: "blur(4px)" }}>{square(0, "#f00")}{square(140, "#00f")}</div>+ <div style={{ position: "absolute", left: 400, top: 60, width: 60, height: 60, filter: "grayscale(1)" }}>+ <div style={{ width: 60, height: 60, background: "#f00", filter: "drop-shadow(100px 0 0 #f00)" }} />+ </div>+ {box(40, {})}+ {box(340, { overflow: "hidden" })}+ {box(480, { overflowX: "clip", overflowY: "visible" })}+ </AbsoluteFill>+ );+}+registerRoot(() => <Composition id="o" component={O} width={640} height={360} fps={30} durationInFrames={1} />);diff --git a/vendor/blitz-paint/src/render.rs b/vendor/blitz-paint/src/render.rsindex 5a7d211c..ab258bdc 100644--- a/vendor/blitz-paint/src/render.rs+++ b/vendor/blitz-paint/src/render.rs@@ -722,6 +722,56 @@ impl<'dom, 'a> BlitzDomPainter<'dom, 'a> {(if plain { Phase::Blocks } else { Phase::Inlines }, plain)}+ /// raea: the boxes `node_id` and its descendants draw, in its own space: `scrollable_overflow`'s walk (blitz-dom's+ /// resolve_transforms), cut on each axis an element clips to that element's box grown by its+ /// overflow-clip-margin, as its overflow clip cuts what is drawn (the root element clips nothing: `should_clip`).+ /// The overflow itself reaches through every clip, so a layer made from it is as large as content nobody sees: a+ /// filtered card around a small clipping box with a page of content in it would be drawn into a texture the size+ /// of the page. With `own_filter`, grown by the reach of the element's own filter, which draws past its boxes (a+ /// descendant's drop shadow).+ fn drawn_bounds(&self, node_id: NodeId, own_filter: bool) -> Rect {+ let dom = self.dom.as_ref();+ let Some(node) = dom.get_node(node_id) else { return Rect::ZERO };+ let size = node.final_layout().size;+ let own = Rect::new(0.0, 0.0, size.width as f64 * self.scale, size.height as f64 * self.scale);+ let styles = node.primary_styles();+ let (clips_x, clips_y, grow) = styles.as_ref().filter(|_| self.root_element_id != Some(node_id)).map_or((false, false, 0.0), |s| {+ let b = s.get_box();+ (!matches!(b.overflow_x, Overflow::Visible), !matches!(b.overflow_y, Overflow::Visible), s.get_margin().overflow_clip_margin.offset.0.px() as f64 * self.scale.max(1.0))+ });+ let filtered = |r: Rect| match styles.as_ref().filter(|_| own_filter).and_then(|s| convert_filters(&s.get_effects().filter.0)) {+ Some(f) => {+ let reach = f.expansion_rect();+ Rect::new(r.x0 + reach.x0, r.y0 + reach.y0, r.x1 + reach.x1, r.y1 + reach.y1)+ }+ None => r,+ };+ let clip = own.inflate(grow.max(0.0), grow.max(0.0));+ if clips_x && clips_y {+ return filtered(clip);+ }+ let mut all = own;+ let in_flow = node.layout_children.borrow();+ let in_flow = in_flow.iter().flatten().copied().filter(|&c| dom.get_node(c).is_some_and(|c| !c.is_out_of_flow()));+ let pseudos = [node.before(), node.after()].into_iter().flatten().filter(|&c| dom.get_node(c).is_some_and(|c| !c.is_out_of_flow()));+ for child_id in in_flow.chain(node.hoisted_children.borrow().iter().copied()).chain(pseudos) {+ let Some(child) = dom.get_node(child_id) else { continue };+ let at = child.final_layout().location;+ let mut to_own = Affine::translate((at.x as f64 * self.scale, at.y as f64 * self.scale));+ if let Some(t) = child.transform().as_deref() {+ to_own *= *t;+ }+ all = all.union(to_own.transform_rect_bbox(self.drawn_bounds(child_id, true)));+ }+ if clips_x {+ (all.x0, all.x1) = (all.x0.max(clip.x0), all.x1.min(clip.x1));+ }+ if clips_y {+ (all.y0, all.y1) = (all.y0.max(clip.y0), all.y1.min(clip.y1));+ }+ filtered(all)+ }+fn render_element(&self,scene: &mut impl PaintScene,@@ -1183,6 +1233,22 @@ impl<'dom, 'a> BlitzDomPainter<'dom, 'a> {.unwrap_or(Rect::ZERO);let mut effect_layer_clip = cx.frame.border_box_path().bounding_box();+ // raea: a filter's input is all the element draws, what its descendants draw outside its box+ // included, as Chrome filters it (a 0x0 wrapper's absolutely positioned children were cut off at its+ // box, a blur's reach of them left): its boxes up to the clips in their way (`drawn_bounds`), and the+ // same of each box its stacking context paints, where that puts it (hoisted_content_bbox's places)+ if filter.is_some() {+ effect_layer_clip = effect_layer_clip.union(self.drawn_bounds(node_id, false));+ for hoisted in node.stacking_context.iter().flat_map(|sc| sc.children.iter()) {+ let Some(child) = self.dom.as_ref().get_node(hoisted.node_id) else { continue };+ let (p, at) = (hoisted.position(node.tree(), node_id), child.final_layout().location);+ let mut to_own = Affine::translate(((p.x + at.x) as f64 * self.scale, (p.y + at.y) as f64 * self.scale));+ if let Some(t) = child.transform().as_deref() {+ to_own *= *t;+ }+ effect_layer_clip = effect_layer_clip.union(to_own.transform_rect_bbox(self.drawn_bounds(hoisted.node_id, true)));+ }+ }effect_layer_clip.x0 += filter_expansion_area.x0;effect_layer_clip.y0 += filter_expansion_area.y0;effect_layer_clip.x1 += filter_expansion_area.x1;diff --git a/vendor/vendor.toml b/vendor/vendor.tomlindex ac84fa75..c7860030 100644--- a/vendor/vendor.toml+++ b/vendor/vendor.toml@@ -63,7 +63,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; 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); background-clip: text, its background masked by the text of the element and everything in it (#37) as Chrome does, unscrolled; inline text in a scroller scrolled once, not twice (#46); a rounded corner where one side has no width (a left-only border on a rounded box), which drew nothing; a bevy_ui node's box shadow (data-raea-bevy-shadow, its BoxShadowSamples) drawn as bevy_ui draws it: spread by its width and its height and corners by the same ratio, then blurred as box_shadow.wesl blurs it, from a CPU bitmap (render/bevy_shadow.rs); a stacking context's out-of-flow boxes from containing blocks above it kept in its layer and not culled (raea #39)"+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); background-clip: text, its background masked by the text of the element and everything in it (#37) as Chrome does, unscrolled; inline text in a scroller scrolled once, not twice (#46); a rounded corner where one side has no width (a left-only border on a rounded box), which drew nothing; a bevy_ui node's box shadow (data-raea-bevy-shadow, its BoxShadowSamples) drawn as bevy_ui draws it: spread by its width and its height and corners by the same ratio, then blurred as box_shadow.wesl blurs it, from a CPU bitmap (render/bevy_shadow.rs); a stacking context's out-of-flow boxes from containing blocks above it kept in its layer and not culled (raea #39); a filter's layer over the boxes the element and its descendants draw (up to the overflow clips in their way), not its border box alone"exit = "a Blitz release that draws these"[blitz-dom]