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
MeshPass with depth and vertex colours, Mesh3d material={false}; Bevy parity for shader_advanced/specialized_mesh_pipeline, exact
shinyobjectz4175c116fb76
diff --git a/bench/bevy-parity/examples.list b/bench/bevy-parity/examples.listindex 04fdb0fa..70d6437a 100644--- a/bench/bevy-parity/examples.list+++ b/bench/bevy-parity/examples.list@@ -149,3 +149,4 @@ shader_advanced/deferred_raymarchshader_advanced/manual_materialshader_advanced/mesh_shader_introshader_advanced/render_depth_to_texture+shader_advanced/specialized_mesh_pipelinediff --git a/bench/bevy-parity/runs.tsv b/bench/bevy-parity/runs.tsvindex c1c05deb..79e12e4c 100644--- a/bench/bevy-parity/runs.tsv+++ b/bench/bevy-parity/runs.tsv@@ -148,3 +148,4 @@ shader_advanced/deferred_raymarch - 5,10,30shader_advanced/manual_material - 5,10,30shader_advanced/mesh_shader_intro - 5,10,30,60,120,240,300shader_advanced/render_depth_to_texture - 5,10,30,60+shader_advanced/specialized_mesh_pipeline - 5,10diff --git a/docs/bevy-parity.md b/docs/bevy-parity.mdindex 6364bec9..3a4eabd6 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 **149**, passing **149**, excluded **17** (docs/bevy-parity/excluded.tsv), left **272**.+Examples: **438**, ported **150**, passing **150**, excluded **17** (docs/bevy-parity/excluded.tsv), left **271**.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.@@ -253,6 +253,8 @@ doesn't pay.| shader_advanced/render_depth_to_texture | 30 | 0.999617 | 6 | 1 / 1 | 452 / 536 | 7 / 9 | 2 / 3 | 2.149 / 1.113 = 1.113 + 0 | yes | || shader_advanced/render_depth_to_texture | 5 | 0.999617 | 6 | 1 / 1 | 452 / 536 | 7 / 9 | 2 / 3 | 47.576 / 2.77 = 2.77 + 0 | yes | || shader_advanced/render_depth_to_texture | 60 | 0.999617 | 6 | 1 / 1 | 452 / 536 | 7 / 9 | 2 / 3 | 1.975 / 0.999 = 0.999 + 0 | yes | |+| shader_advanced/specialized_mesh_pipeline | 10 | 1.000000 | 0 | 0 / 0 | 447 / 532 | 9 / 9 | 1 / 1 | 2.325 / 1.877 = 1.877 + 0 | yes | |+| shader_advanced/specialized_mesh_pipeline | 5 | 1.000000 | 0 | 0 / 0 | 445 / 532 | 9 / 9 | 1 / 1 | 46.496 / 2.986 = 2.986 + 0 | yes | |## Excludeddiff --git a/docs/bevy-parity/results.jsonl b/docs/bevy-parity/results.jsonlindex 89a8d7db..5d58a02c 100644--- a/docs/bevy-parity/results.jsonl+++ b/docs/bevy-parity/results.jsonl@@ -240,3 +240,5 @@{"example":"shader_advanced/render_depth_to_texture","frame":30,"ssim":0.999617,"tile":6,"bevy":{"batch_keys":1,"entities":452,"extents":["1.5000 1.5000 1.5000","2.0000 2.0000 0.0000"],"frame":30,"frame_ms":2.149,"materials":2,"mesh_entities":2,"meshes":7,"other_material":1,"visible":2},"raea":{"frame":37,"entities":536,"mesh_entities":2,"visible":2,"meshes":9,"materials":3,"batch_keys":1,"other_material":1,"extents":["1.5000 1.5000 1.5000","2.0000 2.0000 0.0000"],"frame_ms":1.113,"step_ms":null,"cost_ms":1.113},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"shader_advanced/render_depth_to_texture","frame":5,"ssim":0.999617,"tile":6,"bevy":{"batch_keys":1,"entities":452,"extents":["1.5000 1.5000 1.5000","2.0000 2.0000 0.0000"],"frame":5,"frame_ms":47.576,"materials":2,"mesh_entities":2,"meshes":7,"other_material":1,"visible":2},"raea":{"frame":12,"entities":536,"mesh_entities":2,"visible":2,"meshes":9,"materials":3,"batch_keys":1,"other_material":1,"extents":["1.5000 1.5000 1.5000","2.0000 2.0000 0.0000"],"frame_ms":2.77,"step_ms":null,"cost_ms":2.77},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"shader_advanced/render_depth_to_texture","frame":60,"ssim":0.999617,"tile":6,"bevy":{"batch_keys":1,"entities":452,"extents":["1.5000 1.5000 1.5000","2.0000 2.0000 0.0000"],"frame":60,"frame_ms":1.975,"materials":2,"mesh_entities":2,"meshes":7,"other_material":1,"visible":2},"raea":{"frame":67,"entities":536,"mesh_entities":2,"visible":2,"meshes":9,"materials":3,"batch_keys":1,"other_material":1,"extents":["1.5000 1.5000 1.5000","2.0000 2.0000 0.0000"],"frame_ms":0.999,"step_ms":null,"cost_ms":0.999},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}+{"example":"shader_advanced/specialized_mesh_pipeline","frame":10,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":0,"entities":447,"extents":["0.2500 0.2500 0.0000","0.5000 0.3750 0.0000"],"frame":10,"frame_ms":2.325,"materials":1,"mesh_entities":4,"meshes":9,"other_material":4,"visible":4},"raea":{"frame":17,"entities":532,"mesh_entities":4,"visible":4,"meshes":9,"materials":1,"batch_keys":0,"other_material":4,"extents":["0.2500 0.2500 0.0000","0.5000 0.3750 0.0000"],"frame_ms":1.877,"step_ms":null,"cost_ms":1.877},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}+{"example":"shader_advanced/specialized_mesh_pipeline","frame":5,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":0,"entities":445,"extents":["0.2500 0.2500 0.0000","0.5000 0.3750 0.0000"],"frame":5,"frame_ms":46.496,"materials":1,"mesh_entities":4,"meshes":9,"other_material":4,"visible":4},"raea":{"frame":12,"entities":532,"mesh_entities":4,"visible":4,"meshes":9,"materials":1,"batch_keys":0,"other_material":4,"extents":["0.2500 0.2500 0.0000","0.5000 0.3750 0.0000"],"frame_ms":2.986,"step_ms":null,"cost_ms":2.986},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}diff --git a/engine/render/src/engine/spawn.rs b/engine/render/src/engine/spawn.rsindex bf702696..80a9bce2 100644--- a/engine/render/src/engine/spawn.rs+++ b/engine/render/src/engine/spawn.rs@@ -271,8 +271,8 @@ pub(crate) fn spawn_3d(world: &mut World, e: Entity, t: &Tup, inserted: &[Tup],} else if vals.get("shadow_catch").is_some_and(V::truthy) {// `shadow: "catch"`: only the shadows falling on it, in its colour and opacity (shadow_catch.rs)grid::put(world, e, mesh, shadow_catch::ShadowCatchMaterial::of(&mat), vals);- } else if vals.contains_key("toon") {- // a MeshToonMaterial: the surface lit in bands over the standard one, and its ink outline (toon.rs)+ } else if vals.contains_key("toon") || vals.get("no_material").is_some_and(V::truthy) {+ // a MeshToonMaterial (toon.rs: the standard surface lit in bands, its ink outline); `material: false` noneworld.entity_mut(e).insert((Mesh3d(mesh.clone()), transform_of(vals)));toon::spawn_mesh(world, e, vals, &mesh, mat);} else if let Some(extension) = grid {diff --git a/runtime/scene/src/parts.rs b/runtime/scene/src/parts.rsindex 212545a1..1e44b0c7 100644--- a/runtime/scene/src/parts.rs+++ b/runtime/scene/src/parts.rs@@ -268,6 +268,10 @@ pub(crate) fn meshes_rows(tr: &Tracks, names: &[String], p: &mut Program) {if its[0].props.get("shadow").and_then(Value::as_str) == Some("catch") {row.insert("shadow_catch".into(), V::N(1.0));}+ // `material: false`: no material, drawn only by a pass of its own (a MeshPass), as a Bevy Mesh3d without one+ if its[0].props.get("material") == Some(&Value::Bool(false)) {+ row.insert("no_material".into(), V::N(1.0));+ }// `receiveShadow: false`: no shadow falls on it (NotShadowReceiver)if its[0].props.get("receiveShadow") == Some(&Value::Bool(false)) {row.insert("receive".into(), V::N(0.0));diff --git a/sdk/raea/bench/bevy-parity/shader_advanced/specialized_mesh_pipeline.tsx b/sdk/raea/bench/bevy-parity/shader_advanced/specialized_mesh_pipeline.tsxnew file mode 100644index 00000000..18069a73--- /dev/null+++ b/sdk/raea/bench/bevy-parity/shader_advanced/specialized_mesh_pipeline.tsx@@ -0,0 +1,36 @@+// Bevy v0.20.0 examples/shader_advanced/specialized_mesh_pipeline.rs in raea's TSX (docs/control.feature FC2d): meshes+// with no material drawn only by a SpecializedMeshPipeline of assets/shaders/specialized_mesh_pipeline.wesl as written+// (positions at location 0, compressed or not, and colours at 1 under VERTEX_COLORS when the mesh has them), depth+// tested and written GreaterEqual, back faces culled, under the view's MSAA: a <MeshPass depth> in each mesh. Three+// copies of one triangle ((-0.5, -0.5), (0.5, -0.5), (0, 0.25), coloured red, green and blue) at (-0.5, -0.25),+// (0, 0.5) and (0.5, -0.25), and a 0.5 m Rectangle with no normals or uvs, compressed (MeshCompressionArgs::regular()),+// at (0, -1/3, -1), each a <Mesh3d material={false}> (no MeshMaterial3d); the camera at (0, 0, 3) looking at the+// origin, in Bevy's default 1280 x 720 window.+import { Composition, registerRoot, staticFile } from "raea";+import { BufferMesh, MeshPass } from "raea/3d";+import { Camera3d } from "raea/camera";+import { Mesh3d, Plane3d } from "raea/mesh";+import { Transform } from "raea/transform";++const SHADER = staticFile("shaders/specialized_mesh_pipeline.wesl");++function Shot() {+ return (+ <>+ {([[-0.5, -0.25], [0, 0.5], [0.5, -0.25]] as const).map(([x, y]) => (+ <Mesh3d key={x} transform={Transform.fromXyz(x, y, 0)} material={false}>+ <BufferMesh positions={[-0.5, -0.5, 0, 0.5, -0.5, 0, 0, 0.25, 0]} indices={[0, 1, 2]} colors={[1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1]} />+ <MeshPass shader={SHADER} depth />+ </Mesh3d>+ ))}+ {/* a Rectangle is Plane3d facing +Z, its positions the same; the shader reads only them */}+ <Mesh3d transform={Transform.fromXyz(0, -1 / 3, -1)} compressed material={false}>+ <Plane3d normal={[0, 0, 1]} half_size={[0.25, 0.25]} />+ <MeshPass shader={SHADER} depth />+ </Mesh3d>+ <Camera3d transform={Transform.fromXyz(0, 0, 3).lookingAt([0, 0, 0])} />+ </>+ );+}++registerRoot(() => <Composition id="main" component={Shot} durationInFrames={11} fps={60} width={1280} height={720} />);diff --git a/sdk/render/src/3d/phase.tsx b/sdk/render/src/3d/phase.tsxindex 56f13991..b725375d 100644--- a/sdk/render/src/3d/phase.tsx+++ b/sdk/render/src/3d/phase.tsx@@ -54,15 +54,19 @@ export interface MeshPassProps {/** its entry points (Bevy's default names) */vertex?: string;fragment?: string;+ /** whether it tests and writes the view's depth (GreaterEqual), as a mesh in Bevy's opaque phase does (Bevy's+ * shader_advanced/specialized_mesh_pipeline); without, it draws over everything */+ depth?: boolean;}/** The mesh it's inside drawn again by your shader, in a phase of its own after the camera's main opaque pass: onto- * the colour target, with no depth test, back faces culled (Bevy's shader_advanced/custom_render_phase).+ * the colour target, with no depth test unless `depth`, back faces culled (Bevy's shader_advanced/custom_render_phase). It+ * reads the mesh's colours at location 1 under VERTEX_COLORS when the mesh has them.* @bevy raea_sys_phase::MeshPass */export function MeshPass(p: MeshPassProps) {- const { shader, vertex = "vertex", fragment = "fragment" } = p;+ const { shader, vertex = "vertex", fragment = "fragment", depth = false } = p;if (typeof shader !== "string" || !shader) throw new TypeError(`MeshPass: shader is a shader file, staticFile("shaders/x.wesl"), got ${JSON.stringify(shader)}`);- return <BevyComponent type="raea_sys_phase::MeshPass" value={{ shader: assetPath(shader), vertex, fragment }} />;+ return <BevyComponent type="raea_sys_phase::MeshPass" value={{ shader: assetPath(shader), vertex, fragment, depth: depth === true }} />;}export interface ShaderInstancesProps {diff --git a/sdk/render/src/3d/shapes.tsx b/sdk/render/src/3d/shapes.tsxindex 9a32281c..4f9ab79e 100644--- a/sdk/render/src/3d/shapes.tsx+++ b/sdk/render/src/3d/shapes.tsx@@ -322,6 +322,9 @@ export interface MeshProps extends PointerHandlers3d {* way); its surface is ignored. "catch": it shows only the shadows falling on it, in its material's colour at its* material's opacity, and is clear elsewhere (three.js's ShadowMaterial: a floor under a product over a picture) */shadow?: boolean | "only" | "catch";+ /** false: no material at all, as a Bevy Mesh3d without a MeshMaterial3d, so only a pass of its own draws it (a+ * <MeshPass>: Bevy's shader_advanced/specialized_mesh_pipeline); its surface is ignored */+ material?: false;/** three.js's name for `shadow`'s true and false (`shadow` wins when both are given) */castShadow?: boolean;/** a page drawn on it over its UVs: the screen spec <Mesh3d> makes for a page element with layer="surface"@@ -405,6 +408,7 @@ export function Mesh(props: MeshProps) {if (!(scale > 0) || !Number.isFinite(scale)) throw new RangeError(`Mesh: scale must be a positive number, got ${scale}`);} else checkVec("Mesh", "scale", scale);if (props.shadow !== undefined && typeof props.shadow !== "boolean" && props.shadow !== "only" && props.shadow !== "catch") throw new TypeError(`Mesh: shadow is true, false, "only" or "catch", got ${JSON.stringify(props.shadow)}`);+ if (props.material !== undefined && props.material !== false) throw new TypeError(`Mesh: material is false (no material) or left out, got ${JSON.stringify(props.material)}`);checkPass("Mesh", props.pass);const manifold = shape instanceof Solid ? shape.expr : shape ?? shapeFromChildren(props.children);const extra: Record<string, string> = {};diff --git a/systems/phase/src/mesh_pass.rs b/systems/phase/src/mesh_pass.rsindex ea0fc24d..022e5b88 100644--- a/systems/phase/src/mesh_pass.rs+++ b/systems/phase/src/mesh_pass.rs@@ -1,12 +1,13 @@//! A mesh drawn again in a phase of its own (docs/control.feature FC2d), as Bevy's shader_advanced/custom_render_phase//! draws its stencil: a Mesh3d entity with a MeshPass is drawn, after the camera's main opaque pass, by a pipeline of//! its shader file as written (its `vertex` and `fragment`, reading the mesh's positions at location 0, compressed or-//! not), with Bevy's mesh view and mesh bind groups (0 and 2, group 1 empty), straight onto the view's colour target-//! with no depth attachment, back faces culled. The phase is sorted by distance, as the example's Stencil3d is.+//! not, and its colours at location 1 under VERTEX_COLORS when it has them), with Bevy's mesh view and mesh bind+//! groups (0 and 2, group 1 empty), straight onto the view's colour target, back faces culled: the view's depth not+//! read, or with `depth` tested and written GreaterEqual as an opaque mesh is (shader_advanced/specialized_mesh_pipeline). The phase is sorted by distance, as the example's Stencil3d is.use std::ops::Range;-use bevy::core_pipeline::core_3d::{main_opaque_pass_3d, TransparentSortingInfo3d};+use bevy::core_pipeline::core_3d::{main_opaque_pass_3d, TransparentSortingInfo3d, CORE_3D_DEPTH_FORMAT};use bevy::core_pipeline::schedule::Core3d;use bevy::core_pipeline::Core3dSystems;use bevy::camera::visibility::{self, VisibilityClass};@@ -30,7 +31,7 @@ use bevy::render::render_phase::{sort_phase_system, AddRenderCommand, CachedRenduse bevy::render::render_resource::*;use bevy::render::renderer::{RenderContext, ViewQuery};use bevy::render::sync_world::{MainEntity, MainEntityHashSet};-use bevy::render::view::{ExtractedView, RenderVisibleEntities, RetainedViewEntity, ViewTarget};+use bevy::render::view::{ExtractedView, RenderVisibleEntities, RetainedViewEntity, ViewDepthStencilTexture, ViewTarget};use bevy::render::{Extract, Render, RenderApp, RenderDebugFlags, RenderSystems};use indexmap::IndexMap;use nonmax::NonMaxU32;@@ -46,6 +47,8 @@ pub struct MeshPass {pub shader: String,pub vertex: String,pub fragment: String,+ /// whether it tests and writes the view's depth (GreaterEqual), as a mesh in Bevy's opaque phase does+ pub depth: bool,/// its shader file, registered as written (raea-sys-shader), and the id register gave it#[reflect(ignore)]pub registered: Option<(String, u128)>,@@ -78,6 +81,7 @@ pub struct PassKey {shader: u128,vertex: String,fragment: String,+ depth: bool,}impl SpecializedMeshPipeline for PassPipeline {@@ -92,6 +96,10 @@ impl SpecializedMeshPipeline for PassPipeline {}attributes.push(Mesh::ATTRIBUTE_POSITION.at_shader_location(0));}+ if layout.0.contains(Mesh::ATTRIBUTE_COLOR) {+ defs.push("VERTEX_COLORS".into());+ attributes.push(Mesh::ATTRIBUTE_COLOR.at_shader_location(1));+ }let buffer = layout.0.get_layout(&attributes)?;let view = self.mesh.get_view_layout(MeshPipelineViewLayoutKey::from(key.mesh));let shader = Handle::Uuid(bevy::asset::uuid::Uuid::from_u128(key.shader), core::marker::PhantomData);@@ -101,6 +109,9 @@ impl SpecializedMeshPipeline for PassPipeline {vertex: VertexState { shader: shader.clone(), shader_defs: defs.clone(), entry_point: Some(key.vertex.into()), buffers: vec![buffer], ..default() },fragment: Some(FragmentState { shader, shader_defs: defs, entry_point: Some(key.fragment.into()), targets: vec![Some(ColorTargetState { format: key.mesh.target_format(), blend: None, write_mask: ColorWrites::ALL })], ..default() }),primitive: PrimitiveState { topology: key.mesh.primitive_topology(), strip_index_format: key.mesh.strip_index_format(), cull_mode: Some(Face::Back), ..default() },+ // the view's depth is always attached: compared GreaterEqual and written with `depth`, else not read+ depth_stencil: Some(DepthStencilState { format: CORE_3D_DEPTH_FORMAT, depth_write_enabled: Some(key.depth), depth_compare: Some(if key.depth { CompareFunction::GreaterEqual } else { CompareFunction::Always }), stencil: default(), bias: default() }),+ multisample: MultisampleState { count: key.mesh.msaa_samples(), ..default() },..default()})}@@ -270,7 +281,7 @@ fn queue(continue;};let Some(mesh) = meshes.get(instance.mesh_asset_id()) else { continue };- let key = PassKey { mesh: view_key | MeshPipelineKey::from_primitive_topology_and_strip_index(mesh.primitive_topology(), mesh.index_format()), shader, vertex: pass.vertex.clone(), fragment: pass.fragment.clone() };+ let key = PassKey { mesh: view_key | MeshPipelineKey::from_primitive_topology_and_strip_index(mesh.primitive_topology(), mesh.index_format()), shader, vertex: pass.vertex.clone(), fragment: pass.fragment.clone(), depth: pass.depth };let id = match pipelines.specialize(&cache, &pipeline, key, &mesh.layout) {Ok(id) => id,Err(err) => {@@ -294,14 +305,14 @@ fn queue(}/// The pass drawn onto the view's colour target, no depth attachment, in the camera's viewport.-fn draw(world: &World, view: ViewQuery<(&ExtractedCamera, &ExtractedView, &ViewTarget, Option<&MainPassResolutionOverride>)>, phases: Res<ViewSortedRenderPhases<Pass3d>>, mut ctx: RenderContext) {+fn draw(world: &World, view: ViewQuery<(&ExtractedCamera, &ExtractedView, &ViewTarget, &ViewDepthStencilTexture, Option<&MainPassResolutionOverride>)>, phases: Res<ViewSortedRenderPhases<Pass3d>>, mut ctx: RenderContext) {let entity = view.entity();- let (camera, extracted, target, over) = view.into_inner();+ let (camera, extracted, target, depth, over) = view.into_inner();let Some(phase) = phases.get(&extracted.retained_view_entity) else { return };if phase.items.is_empty() {return;}- let mut pass = ctx.begin_tracked_render_pass(RenderPassDescriptor { label: Some("raea mesh pass"), color_attachments: &[Some(target.get_color_attachment())], depth_stencil_attachment: None, timestamp_writes: None, occlusion_query_set: None, multiview_mask: None });+ let mut pass = ctx.begin_tracked_render_pass(RenderPassDescriptor { label: Some("raea mesh pass"), color_attachments: &[Some(target.get_color_attachment())], depth_stencil_attachment: Some(depth.get_attachment(StoreOp::Store)), timestamp_writes: None, occlusion_query_set: None, multiview_mask: None });if let Some(v) = Viewport::from_viewport_and_override(camera.viewport.as_ref(), over) {pass.set_camera_viewport(&v);}