Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bench/bevy-parity/examples.list
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,4 @@ shader_advanced/mesh_shader_intro
shader_advanced/render_depth_to_texture
shader_advanced/specialized_mesh_pipeline
shader_advanced/texture_binding_array
2d/2d_shapes
1 change: 1 addition & 0 deletions bench/bevy-parity/runs.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,4 @@ shader_advanced/mesh_shader_intro - 5,10,30,60,120,240,300
shader_advanced/render_depth_to_texture - 5,10,30,60
shader_advanced/specialized_mesh_pipeline - 5,10
shader_advanced/texture_binding_array - 5,10
2d/2d_shapes - 5,10
488 changes: 245 additions & 243 deletions docs/bevy-parity.md

Large diffs are not rendered by default.

486 changes: 244 additions & 242 deletions docs/bevy-parity/results.jsonl

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion engine/render/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl Engine {
self.app.world_mut().resource_mut::<FrameRows>().parse_looks();
// a glTF model, and a panorama a live frame showed first (#38), set up before the frame that shows it draws
if spawned { scene3d::await_models(&mut self.app)?; }
raea_sys_post::msaa_for_3d(self.app.world_mut(), has_3d(rows));
raea_sys_post::msaa_for_3d(self.app.world_mut(), has_3d(rows) || raea_sys_sprite::has_2d(rows));
environment::live_rows(&mut self.app, rows, &self.dir)
}

Expand Down
6 changes: 3 additions & 3 deletions engine/render/src/engine/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ impl Engine {
#[cfg(feature = "native")]
let mut rows2d: Vec<(String, serde_json::Value, Entity)> = Vec::new();
let mut camera = None;
// an edit with no 3D rows draws nothing through the 3D pipeline: its camera only clears, so it gets no MSAA
// (4x colour and depth targets at full size were most of the start-up memory)
let has_3d = has_3d(inserted);
// an edit with no 3D or 2D mesh rows draws nothing through a mesh pipeline: its camera only clears, so it gets no
// MSAA (4x targets at full size were most of the start-up memory); a 2D one's shares the 2D camera's (sprite)
let has_3d = has_3d(inserted) || raea_sys_sprite::has_2d(inserted);
// cameras first, so UI can target them; otherwise insertion order
let mut order: Vec<(&Tup, Entity)> = inserted.iter().zip(ents.iter().copied()).collect();
order.sort_by_key(|(t, _)| t.kind != "camera");
Expand Down
10 changes: 6 additions & 4 deletions runtime/bundle/src/outside.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ fn roots(dir: &Path) -> Vec<(&'static str, PathBuf)> {
}

/// Every source outside the edit's folder `dir` that its sources import by relative path, and what those import in
/// turn (each file once, so a cycle ends). The SDK's own files are left out: they come by name (rewrite_into). A file
/// outside both raea's home and the project's root is refused, naming its importer.
/// turn (each file once, so a cycle ends). The SDK packages' own files are left out: they come by name
/// (rewrite_into). A file outside both raea's home and the project's root is refused, naming its importer.
pub fn outside(dir: &Path) -> R<Vec<Outside>> {
outside_in(&absolute(dir), &roots(&absolute(dir)))
}

pub fn outside_in(dir: &Path, roots: &[(&'static str, PathBuf)]) -> R<Vec<Outside>> {
let sdk = absolute(&raea_io_home::home().join("sdk"));
// the SDK's package sources, which come by name; anything else under sdk/ (a bench's shared helper) is copied
let home = raea_io_home::home();
let sdk: Vec<PathBuf> = std::iter::once("sdk/raea/src".to_string()).chain(crate::rewrite::sdks().into_iter().map(|(_, d)| d)).map(|d| absolute(&home.join(d))).collect();
let re = specs();
let mut seen = BTreeSet::new();
let mut out = vec![];
Expand All @@ -64,7 +66,7 @@ pub fn outside_in(dir: &Path, roots: &[(&'static str, PathBuf)]) -> R<Vec<Outsid
}
// one the bundler can't find either: left for it to name
let Some(t) = resolve(&base, spec) else { continue };
if t.starts_with(dir) || t.starts_with(&sdk) || t.components().any(|c| c.as_os_str() == "node_modules") || !seen.insert(t.clone()) {
if t.starts_with(dir) || sdk.iter().any(|s| t.starts_with(s)) || t.components().any(|c| c.as_os_str() == "node_modules") || !seen.insert(t.clone()) {
continue;
}
let Some((name, root)) = roots.iter().find(|(_, r)| t.starts_with(r)) else {
Expand Down
6 changes: 4 additions & 2 deletions runtime/look/src/parts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ pub fn sheet(p: &mut Program, row: &mut BTreeMap<String, V>, id: &str, its: &[It
}
}

/// `color` keyed as col_r, col_g, col_b (`default` where a frame has none)
/// `color` keyed as col_r, col_g, col_b (`default` where a frame has none); `srgb` ([r, g, b], a Bevy Srgba's
/// channels) over it, unrounded, as a ColorMaterial's colour reaches the GPU in Bevy
pub fn tint(p: &mut Program, row: &mut BTreeMap<String, V>, id: &str, its: &[Item], default: &str) {
let colors: Vec<[f64; 3]> = its.iter().map(|i| rgb(&hex(i.props.get("color")).unwrap_or(default.into()))).collect();
let given = |i: &Item| i.props.get("srgb").and_then(Value::as_array).filter(|a| a.len() == 3).and_then(|a| Some([a[0].as_f64()?, a[1].as_f64()?, a[2].as_f64()?]));
let colors: Vec<[f64; 3]> = its.iter().map(|i| given(i).unwrap_or_else(|| rgb(&hex(i.props.get("color")).unwrap_or(default.into())))).collect();
for (c, name) in ["col_r", "col_g", "col_b"].iter().enumerate() {
exact(p, row, id, name, &colors.iter().map(|v| v[c]).collect::<Vec<_>>());
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/scene2d/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ pub fn shapes(tracks: &[Track], p: &mut Program) {
// its ColorMaterial's texture (a path, or { path, sampler }) and AlphaMode2d ("opaque", "blend", or "mask" with its cutoff)
let tex = first.get("texture");
if let Some(t) = tex.and_then(|t| t.as_str().or(t.get("path").and_then(Value::as_str))) { row.insert("texture".into(), V::S(src_path(t))); }
// as JSON: the texture's sampler (raea-sys-sampler's), the uv_transform (an Affine2), the mesh's Mesh::ATTRIBUTE_COLOR and its own Material2d
for (col, v) in [("texture_sampler", tex.and_then(|t| t.get("sampler"))), ("uv_transform", first.get("uv_transform")), ("vertex_colors", first.get("vertex_colors")), ("shader", first.get("shader"))] { if let Some(v) = v { row.insert(col.into(), V::S(v.to_string())); } }
// as JSON: the texture's sampler (raea-sys-sampler's), the uv_transform (an Affine2), the mesh's Mesh::ATTRIBUTE_COLOR, its own Material2d and a Bevy primitive
for (col, v) in [("texture_sampler", tex.and_then(|t| t.get("sampler"))), ("uv_transform", first.get("uv_transform")), ("vertex_colors", first.get("vertex_colors")), ("shader", first.get("shader")), ("primitive", first.get("primitive"))] { if let Some(v) = v { row.insert(col.into(), V::S(v.to_string())); } }
match first.get("alpha_mode") {
Some(Value::String(a)) => { row.insert("alpha".into(), V::S(a.to_lowercase())); }
Some(Value::Object(m)) => { row.insert("alpha".into(), V::S("mask".into())); row.insert("alpha_cutoff".into(), V::N(n(m, "Mask", 0.5))); }
Expand Down
75 changes: 75 additions & 0 deletions sdk/raea/bench/bevy-parity/2d/2d_shapes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Bevy v0.20.0 examples/2d/2d_shapes.rs in raea's TSX (docs/control.feature FC2): a Camera2d and twelve Mesh2d
// primitives in a row at y 75 (Circle, CircularSector, CircularSegment, Ellipse, Annulus, Capsule2d, Rhombus,
// Rectangle, RegularPolygon, Triangle2d, Segment2d, Polyline2d), x spread from -500 to 500, each a ColorMaterial of
// Color::hsl(360 i / 12, 0.95, 0.7); below them at y -75 ten rings (to_ring(5) or a Ring of two shapes), spread as
// twelve would be, coloured by i / 12. In the bottom left the ROTATE and WIREFRAME feathers checkboxes, unchecked,
// under helpers/theme.rs basic_example_theme(WHITE), so nothing turns and no wireframe draws; Bevy's default 1280 x 720
// window and clear colour.
import { AbsoluteFill, Composition, registerRoot } from "raea";
import { Canvas3D } from "raea/3d";
import { Hsla, Srgba } from "raea/color";
import { UiTheme } from "raea/feathers";
import { Annulus, Capsule2d, Circle, CircularSector, CircularSegment, ColorMaterial, Ellipse, Mesh2d, Polyline2d, Rectangle, RegularPolygon, Rhombus, Segment2d, Triangle2d } from "raea/sprite";
import { Transform } from "raea/transform";
import { BottomLeft, OptionCheckbox, basic_example_theme } from "../helpers/theme";

const X_EXTENT = 1000, Y_EXTENT = 150, THICKNESS = 5;
const TRIANGLE: [number, number][] = [[0, 50], [-50, -50], [50, -50]];

const SHAPES = [
<Circle radius={50} />,
<CircularSector arc={{ radius: 50, half_angle: 1 }} />,
<CircularSegment arc={{ radius: 50, half_angle: 1.25 }} />,
<Ellipse half_size={[25, 50]} />,
<Annulus inner_circle={{ radius: 25 }} outer_circle={{ radius: 50 }} />,
<Capsule2d radius={25} half_length={25} />,
<Rhombus half_diagonals={[37.5, 50]} />,
<Rectangle half_size={[25, 50]} />,
<RegularPolygon circumcircle={{ radius: 50 }} sides={6} />,
<Triangle2d vertices={TRIANGLE} />,
<Segment2d vertices={[[-50, 50], [50, -50]]} />,
<Polyline2d vertices={[[-50, 50], [0, -50], [50, 50]]} />,
];

const RINGS = [
<Circle radius={50} ring={THICKNESS} />,
<CircularSector arc={{ radius: 50, half_angle: 1 }} inner={{ arc: { radius: 45, half_angle: 1 } }} />,
<CircularSegment arc={{ radius: 50, half_angle: 1.25 }} ring={THICKNESS} />,
// concentric ellipses, each half size less THICKNESS (Ellipse has no Inset)
<Ellipse half_size={[25, 50]} inner={{ half_size: [25 - THICKNESS, 50 - THICKNESS] }} />,
<Circle radius={50} inner={{ radius: 25 }} />,
<Capsule2d radius={25} half_length={25} ring={THICKNESS} />,
<Rhombus half_diagonals={[37.5, 50]} ring={THICKNESS} />,
<Rectangle half_size={[25, 50]} ring={THICKNESS} />,
<RegularPolygon circumcircle={{ radius: 50 }} sides={6} ring={THICKNESS} />,
<Triangle2d vertices={TRIANGLE} ring={THICKNESS} />,
];

/** a row of shapes spread over X_EXTENT at height y, `n` places wide, each coloured by its place */
function row(shapes: JSX.Element[], n: number, y: number) {
return shapes.map((shape, i) => (
<Mesh2d key={`${y} ${i}`} transform={Transform.fromXyz(-X_EXTENT / 2 + (i / (n - 1)) * X_EXTENT, y, 0)}>
{shape}
<ColorMaterial color={new Hsla((360 * i) / n, 0.95, 0.7).to_srgba()} />
</Mesh2d>
));
}

function Shot() {
return (
<AbsoluteFill>
<Canvas3D layered clearColor="rgb(43, 44, 47)">
{row(SHAPES, SHAPES.length, Y_EXTENT / 2)}
{row(RINGS, RINGS.length + 2, -Y_EXTENT / 2)}
</Canvas3D>
<UiTheme theme={basic_example_theme(new Srgba(1, 1, 1, 1))}>
<BottomLeft>
<OptionCheckbox name="ROTATE" />
<OptionCheckbox name="WIREFRAME" />
</BottomLeft>
</UiTheme>
</AbsoluteFill>
);
}

registerRoot(() => <Composition id="main" component={Shot} durationInFrames={11} fps={60} width={1280} height={720} />);
53 changes: 53 additions & 0 deletions sdk/raea/bench/bevy-parity/helpers/theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Bevy v0.20.0 examples/helpers/theme.rs in raea's TSX: basic_example_theme, the feathers theme the examples' option
// menus use (2d_shapes, wireframe_2d, the 3d examples with checkboxes), each token its own colour
// (ThemeProps::new_non_contextual), and the option menus' checkbox and corner node (helpers/checkbox.rs, scene.rs).
import { createElement, type ReactNode } from "react";
import { Oklcha, Srgba } from "raea/color";
import { FeathersCheckbox, caption, palette, tokens, type ThemeProps, type ThemeToken } from "raea/feathers";
import { Node, px } from "raea/ui";

/** palettes::basic::GRAY */
const GRAY = new Srgba(0.5019608, 0.5019608, 0.5019608, 1);
const BLACK = new Srgba(0, 0, 0, 1);
const WHITE = new Srgba(1, 1, 1, 1);

/** ThemeProps::new_non_contextual: each token its own semantic colour, of the token's name, with no surface overrides */
function new_non_contextual(init: [ThemeToken, Srgba | Oklcha][]): ThemeProps {
const t: ThemeProps = { semantic_base: {}, semantic_overrides: {}, token_assignments: {} };
for (const [token, c] of init) {
t.token_assignments[token] = token;
t.semantic_base[token] = c instanceof Oklcha ? c : Oklcha.from(c);
}
return t;
}

/** helpers/theme.rs basic_example_theme(text_color) */
export function basic_example_theme(text: Srgba): ThemeProps {
const k = tokens, p = palette;
return new_non_contextual([
[k.RADIO_TEXT, text], [k.RADIO_MARK, BLACK], [k.RADIO_MARK_HOVER, BLACK], [k.RADIO_MARK_PRESSED, BLACK],
[k.RADIO_BG, WHITE], [k.RADIO_BG_HOVER, GRAY], [k.RADIO_BG_PRESSED, GRAY], [k.RADIO_BG_CHECKED, WHITE], [k.RADIO_BG_CHECKED_HOVER, BLACK], [k.RADIO_BG_CHECKED_PRESSED, BLACK],
[k.RADIO_BORDER, BLACK], [k.RADIO_BORDER_HOVER, GRAY], [k.RADIO_BORDER_PRESSED, BLACK], [k.RADIO_BORDER_CHECKED, BLACK], [k.RADIO_BORDER_CHECKED_HOVER, BLACK], [k.RADIO_BORDER_CHECKED_PRESSED, BLACK],
[k.TEXT_INPUT_TEXT, text], [k.TEXT_INPUT_BG, BLACK], [k.TEXT_INPUT_LABEL_BG, BLACK],
[k.TEXT_INPUT_CURSOR, p.ACCENT.lighter(0.2)], [k.TEXT_INPUT_SELECTION, p.ACCENT], [k.TEXT_INPUT_SELECTION_UNFOCUSED, p.TRANSPARENT],
[k.CHECKBOX_TEXT, text], [k.CHECKBOX_BG, BLACK], [k.CHECKBOX_MARK, WHITE], [k.CHECKBOX_BORDER, BLACK], [k.CHECKBOX_BORDER_HOVER, p.GRAY_2], [k.CHECKBOX_BORDER_CHECKED_HOVER, p.GRAY_0],
[k.CHECKBOX_BORDER_PRESSED, p.GRAY_1], [k.CHECKBOX_BORDER_CHECKED_PRESSED, p.GRAY_1], [k.CHECKBOX_BORDER_CHECKED, BLACK], [k.CHECKBOX_BG_HOVER, p.GRAY_0], [k.CHECKBOX_BG_CHECKED, BLACK],
[k.CHECKBOX_BG_CHECKED_HOVER, BLACK], [k.CHECKBOX_BG_CHECKED_PRESSED, p.GRAY_1], [k.CHECKBOX_BG_PRESSED, BLACK],
[k.BUTTON_BG, p.TRANSPARENT], [k.BUTTON_BG_HOVER, p.TRANSPARENT], [k.BUTTON_BG_PRESSED, p.TRANSPARENT], [k.MENU_BG, p.GRAY_0], [k.MENU_BORDER, p.GRAY_0],
[k.MENUITEM_BG_HOVER, p.TRANSPARENT], [k.MENUITEM_BG_PRESSED, p.TRANSPARENT], [k.MENUITEM_BG_FOCUSED, p.TRANSPARENT], [k.LISTROW_BG, p.TRANSPARENT], [k.LISTROW_BG_HOVER, p.BLACK], [k.LISTROW_BG_SELECTED, p.BLACK],
[k.BUTTON_TEXT, text], [k.LISTROW_TEXT, text],
// the helper sets the slider tokens twice; the second, below, replaces the first, as HashMap::insert does
[k.SLIDER_BG, p.BLACK], [k.SLIDER_BG_HOVER, p.GRAY_0], [k.SLIDER_BG_PRESSED, p.GRAY_1], [k.SLIDER_BAR, p.ACCENT], [k.SLIDER_BAR_HOVER, p.ACCENT.lighter(0.05)], [k.SLIDER_BAR_PRESSED, p.ACCENT.lighter(0.1)],
[k.SLIDER_TEXT, text], [k.TEXT_MAIN, text],
]);
}

/** helpers/checkbox.rs feathers_option_checkbox: a feathers checkbox captioned with the option's name, in a row */
export function OptionCheckbox({ name, checked = false }: { name: string; checked?: boolean }): ReactNode {
return createElement(Node, { align_items: "Center", column_gap: px(5) }, createElement(FeathersCheckbox, { checked }, caption(name)));
}

/** helpers/scene.rs bottom_left_scene: the option menu's column, 10 px from the bottom left, its rows 6 px apart */
export function BottomLeft({ children }: { children?: ReactNode }): ReactNode {
return createElement(Node, { flex_direction: "Column", position_type: "Absolute", row_gap: px(6), left: px(10), bottom: px(10) }, children);
}
2 changes: 1 addition & 1 deletion sdk/raea/src/sprite.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// docs/sdk.feature S1b: a Bevy-named entry point.
// raea/sprite (bevy_sprite): 2D pictures and flat shapes over the 3D, drawn by a 2D camera of their own (S3c).
export { Sprite, Shape2D, type SpriteProps, type Shape2DProps, type Place2dProps, type AlphaMode2d, type SpriteImageMode } from "@raea/render/3d/sprite";
export { Mesh2d, Circle, Rectangle, Ellipse, RegularPolygon, ColorMaterial, type Mesh2dProps, type CircleProps, type RectangleProps, type EllipseProps, type RegularPolygonProps, type ColorMaterialProps, type MeshAttributes } from "@raea/render/bevy3d";
export { Mesh2d, Circle, Rectangle, Ellipse, RegularPolygon, CircularSector, CircularSegment, Annulus, Capsule2d, Rhombus, Triangle2d, Segment2d, Polyline2d, ConvexPolygon, ColorMaterial, type RingProps, type ArcProps, type AnnulusProps, type Capsule2dProps, type RhombusProps, type VerticesProps, type Mesh2dProps, type CircleProps, type RectangleProps, type EllipseProps, type RegularPolygonProps, type ColorMaterialProps, type MeshAttributes } from "@raea/render/bevy3d";
8 changes: 7 additions & 1 deletion sdk/render/src/3d/sprite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ export interface Shape2DProps extends Place2dProps {
sides?: number;
/** a CSS colour (white by default); with a texture, it tints it */
color?: string;
/** the colour as a Bevy Srgba's [r, g, b], unrounded, over `color` (a Mesh2d's ColorMaterial gives it) */
srgb?: [number, number, number];
/** a picture on it, mapped by the mesh's UVs (Bevy's ColorMaterial texture), or one with its own sampler (Bevy's
* load_with_settings: { path, sampler: { wrap: "repeat" } }) */
texture?: string | { path: string; sampler: SamplerSpec };
Expand All @@ -139,6 +141,10 @@ export interface Shape2DProps extends Place2dProps {
/** its own Material2d in place of the ColorMaterial: the spec a <Material> in a Mesh2d makes (docs/control.feature
* FC2a); the shape's colour, texture and alpha_mode are then the material's to draw */
shader?: Record<string, unknown>;
/** one of Bevy's 2D primitives in place of `shape`, its reflected fields over Bevy's default: { primitive:
* "Capsule2d", radius: 25, half_length: 25 }; a 2D shape given `inner` (the same shape's fields) is Bevy's Ring, or
* given `ring: thickness` its to_ring (raea-sys-mesh primitive_mesh). A Mesh2d's primitive child makes it. */
primitive?: Record<string, unknown>;
}

/** bevy_sprite_render's AlphaMode2d */
Expand Down Expand Up @@ -167,7 +173,7 @@ export function Shape2D(props: Shape2DProps) {
const vc = props.vertex_colors;
if (vc !== undefined && !(Array.isArray(vc) && vc.every((c) => Array.isArray(c) && c.length === 4 && c.every(Number.isFinite)))) throw new TypeError(`Shape2D: vertex_colors is one linear [r, g, b, a] per vertex, got ${JSON.stringify(vc)}`);
const verts = ({ rect: 4, triangle: 3 } as Record<string, number>)[props.shape ?? "rect"];
if (vc !== undefined && verts !== undefined && vc.length !== verts) throw new RangeError(`Shape2D: a ${props.shape ?? "rect"}'s mesh has ${verts} vertices, so vertex_colors has ${verts} colours, got ${vc.length}`);
if (vc !== undefined && verts !== undefined && props.primitive === undefined && vc.length !== verts) throw new RangeError(`Shape2D: a ${props.shape ?? "rect"}'s mesh has ${verts} vertices, so vertex_colors has ${verts} colours, got ${vc.length}`);
const id = useId();
const [w, h] = props.size ?? [100, 100];
const round = props.shape === "circle" || props.shape === "ellipse" || props.shape === "polygon";
Expand Down
Loading
Loading