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 bench/bevy-parity/examples.list
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,4 @@ shader/pipeline_constants
shader_advanced/compute_mesh
shader_advanced/custom_phase_item
shader_advanced/custom_post_processing
shader_advanced/custom_vertex_attribute
1 change: 1 addition & 0 deletions bench/bevy-parity/runs.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,4 @@ shader/gpu_component_array_buffer - 60,180,240,400
shader_advanced/compute_mesh - 5,10
shader_advanced/custom_phase_item - 5,10
shader_advanced/custom_post_processing - 10,30,60
shader_advanced/custom_vertex_attribute - 5,10
4 changes: 3 additions & 1 deletion docs/bevy-parity.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 and
frame time at most 1.25x the example's). Wall time is one machine's, measured in the same run.

Examples: **438**, ported **141**, passing **141**, excluded **17** (docs/bevy-parity/excluded.tsv), left **280**.
Examples: **438**, ported **142**, passing **142**, excluded **17** (docs/bevy-parity/excluded.tsv), left **279**.

raea's frame ms is its update's plus the time React takes to step a frame for its 3D (step), which the example
doesn't pay.
Expand Down Expand Up @@ -227,6 +227,8 @@ doesn't pay.
| shader_advanced/custom_post_processing | 10 | 0.999958 | 0 | 1 / 1 | 443 / 522 | 6 / 8 | 2 / 2 | 57.331 / 2.521 = 2.521 + 0 | yes | |
| shader_advanced/custom_post_processing | 30 | 0.999954 | 0 | 1 / 1 | 443 / 522 | 6 / 8 | 2 / 2 | 3.654 / 3.275 = 3.275 + 0 | yes | |
| shader_advanced/custom_post_processing | 60 | 0.999954 | 0 | 1 / 1 | 443 / 522 | 6 / 8 | 2 / 2 | 3.697 / 2.305 = 2.305 + 0 | yes | |
| shader_advanced/custom_vertex_attribute | 10 | 1.000000 | 0 | 0 / 0 | 449 / 521 | 6 / 8 | 1 / 2 | 2.875 / 1.367 = 1.367 + 0 | yes | |
| shader_advanced/custom_vertex_attribute | 5 | 1.000000 | 0 | 0 / 0 | 447 / 521 | 6 / 8 | 1 / 2 | 41.257 / 2.953 = 2.953 + 0 | yes | |

## Excluded

Expand Down
2 changes: 2 additions & 0 deletions docs/bevy-parity/results.jsonl
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,5 @@
{"example":"shader_advanced/custom_post_processing","frame":10,"ssim":0.999958,"tile":0,"bevy":{"batch_keys":1,"entities":443,"extents":["0.5000 0.5000 0.5000"],"frame":10,"frame_ms":57.331,"materials":2,"mesh_entities":1,"meshes":6,"other_material":0,"visible":1},"raea":{"frame":17,"entities":522,"mesh_entities":1,"visible":1,"meshes":8,"materials":2,"batch_keys":1,"other_material":0,"extents":["0.5000 0.5000 0.5000"],"frame_ms":2.521,"step_ms":null,"cost_ms":2.521},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"shader_advanced/custom_post_processing","frame":30,"ssim":0.999954,"tile":0,"bevy":{"batch_keys":1,"entities":443,"extents":["0.5000 0.5000 0.5000"],"frame":30,"frame_ms":3.654,"materials":2,"mesh_entities":1,"meshes":6,"other_material":0,"visible":1},"raea":{"frame":37,"entities":522,"mesh_entities":1,"visible":1,"meshes":8,"materials":2,"batch_keys":1,"other_material":0,"extents":["0.5000 0.5000 0.5000"],"frame_ms":3.275,"step_ms":null,"cost_ms":3.275},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"shader_advanced/custom_post_processing","frame":60,"ssim":0.999954,"tile":0,"bevy":{"batch_keys":1,"entities":443,"extents":["0.5000 0.5000 0.5000"],"frame":60,"frame_ms":3.697,"materials":2,"mesh_entities":1,"meshes":6,"other_material":0,"visible":1},"raea":{"frame":67,"entities":522,"mesh_entities":1,"visible":1,"meshes":8,"materials":2,"batch_keys":1,"other_material":0,"extents":["0.5000 0.5000 0.5000"],"frame_ms":2.305,"step_ms":null,"cost_ms":2.305},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"shader_advanced/custom_vertex_attribute","frame":10,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":0,"entities":449,"extents":["0.5000 0.5000 0.5000"],"frame":10,"frame_ms":2.875,"materials":1,"mesh_entities":1,"meshes":6,"other_material":1,"visible":1},"raea":{"frame":17,"entities":521,"mesh_entities":1,"visible":1,"meshes":8,"materials":2,"batch_keys":0,"other_material":1,"extents":["0.5000 0.5000 0.5000"],"frame_ms":1.367,"step_ms":null,"cost_ms":1.367},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"shader_advanced/custom_vertex_attribute","frame":5,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":0,"entities":447,"extents":["0.5000 0.5000 0.5000"],"frame":5,"frame_ms":41.257,"materials":1,"mesh_entities":1,"meshes":6,"other_material":1,"visible":1},"raea":{"frame":12,"entities":521,"mesh_entities":1,"visible":1,"meshes":8,"materials":2,"batch_keys":0,"other_material":1,"extents":["0.5000 0.5000 0.5000"],"frame_ms":2.953,"step_ms":null,"cost_ms":2.953},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
6 changes: 3 additions & 3 deletions engine/render/src/engine/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,13 @@ pub(crate) fn spawn_3d(world: &mut World, e: Entity, t: &Tup, inserted: &[Tup],
// a shape as a value (docs/media.feature M2): its `shape` column, a CSG expression, built by Manifold
// once per expression (shape::cached), flat-shaded
let expr = match vals.get("shape") { Some(V::S(s)) => s.clone(), _ => return Err(format!("mesh {}: needs shape, as box(1, 1, 1) or minus(rounded_box(2, 1, 0.2, 0.1), text3d(\"SALE\", 0.45, 0.3))", t.id)) };
// a picture map needs texture coordinates, which Manifold doesn't make (scene3d); a normal map needs
// tangents too, made from them (mikktspace); so does a grid's outline (grid.rs)
// a picture map needs UVs, which Manifold doesn't make (scene3d); a normal map tangents (mikktspace), as a grid's outline
let grid = grid::grid_of(vals);
let uvs = scene3d::has_maps(vals) || grid.is_some();
let tangents = raea_sys_material::maps::needs_tangents(vals);
let attrs = match vals.get("attributes") { Some(V::S(a)) => a.as_str(), _ => "" };
// made once per shape and what it's given (share.rs): equal parts hold one Mesh, so Bevy batches them
let mesh = scene3d::shared_mesh(world, &format!("{expr}\0{uvs}\0{tangents}"), || raea_sys_material::mesh::shape_mesh(&t.id, &expr, uvs, tangents))?;
let mesh = scene3d::shared_mesh(world, &format!("{expr}\0{uvs}\0{tangents}\0{attrs}"), || raea_sys_material::mesh::shape_mesh(&t.id, &expr, uvs, tangents).and_then(|m| raea_sys_material::mesh::with_attributes(m, attrs).map_err(|e| format!("mesh {}: {e}", t.id))))?;
// a three.js shader (raea-sys-three-shader, docs/r3f.feature R3F11): its own material, and the mesh given
// what it reads; its pictures' files found as a model's are (the edit's folder, its media)
let three = match vals.get("three") {
Expand Down
4 changes: 4 additions & 0 deletions runtime/scene/src/parts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ pub(crate) fn meshes_rows(tr: &Tracks, names: &[String], p: &mut Program) {
}
layers_column(&mut row, &its[0].props);
instances_column(&mut row, &its);
// its geometry's own vertex attributes (JSON, Mesh3d `attributes`), from the first frame: raea-sys-mesh with_attributes
if let Some(Value::String(a)) = its[0].props.get("attributes") {
row.insert("attributes".into(), V::S(a.clone()));
}
name_column(&mut row, &its[0].props);
p.spawns.push(("mesh".into(), vec![row]));
components(p, &id, &its);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Bevy v0.20.0 examples/shader_advanced/custom_vertex_attribute.rs in raea's TSX (docs/control.feature FC2d): a
// default Cuboid given its own vertex attribute, ATTRIBUTE_BLEND_COLOR ("BlendColor", id 988540917, Float32x4), red
// at all 24 vertices, drawn by a Material whose vertex and fragment shaders are assets/shaders/custom_vertex_attribute.wesl
// as written; its specialize lays the vertex buffer out as POSITION at location 0 and BlendColor at 1, and its
// uniform `material` is { color: LinearRgba::WHITE }. The cube is at (0, 0.5, 0), the camera at (-2, 2.5, 5) looking
// at the origin, with no light, in Bevy's default 1280 x 720 window.
import { Composition, registerRoot, staticFile } from "raea";
import { Camera3d } from "raea/camera";
import { ATTRIBUTE_POSITION, Cuboid, Mesh3d, MeshVertexAttribute } from "raea/mesh";
import { Material } from "@raea/render/bevy3d"; // raea/pbr once scene-loop lands (its pbr.ts commit)
import { Transform } from "raea/transform";

const ATTRIBUTE_BLEND_COLOR = MeshVertexAttribute.new("BlendColor", 988540917, "Float32x4");
const SHADER = staticFile("shaders/custom_vertex_attribute.wesl");

function Shot() {
return (
<>
<Mesh3d transform={Transform.fromXyz(0, 0.5, 0)} attributes={[[ATTRIBUTE_BLEND_COLOR, Array.from({ length: 24 }, () => [1, 0, 0, 1])]]}>
<Cuboid />
<Material vertex={SHADER} fragment={SHADER} vertex_attributes={[[ATTRIBUTE_POSITION, 0], [ATTRIBUTE_BLEND_COLOR, 1]]} uniforms={{ material: { color: [1, 1, 1, 1] } }} />
</Mesh3d>
<Camera3d transform={Transform.fromXyz(-2, 2.5, 5).lookingAt([0, 0, 0])} />
</>
);
}

registerRoot(() => <Composition id="main" component={Shot} durationInFrames={11} fps={60} width={1280} height={720} />);
2 changes: 2 additions & 0 deletions sdk/raea/src/mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export { Sphere, Cylinder, Torus, Cone, Capsule, BufferMesh, type SphereProps, t
export * from "@raea/render/solid";
export { Mesh3d, ConicalFrustum, type Mesh3dProps, type ConicalFrustumProps } from "@raea/render/bevy3d";
export { Cuboid, Capsule3d, Plane3d, type CuboidProps, type Capsule3dProps, type Plane3dProps } from "./3d";
// a mesh's own vertex attributes (Mesh3d attributes) and the ones a Material's vertex buffer reads (vertex_attributes)
export { MeshVertexAttribute, ATTRIBUTE_POSITION, ATTRIBUTE_NORMAL, ATTRIBUTE_UV_0, ATTRIBUTE_UV_1, ATTRIBUTE_TANGENT, ATTRIBUTE_COLOR, type VertexFormat, type MeshAttribute } from "./3d";
export { MeshSequence, type MeshSequenceProps } from "@raea/physics/physics";
export { Mesh2d, type Mesh2dProps } from "@raea/render/bevy3d";
// one mesh or glTF drawn at many placements, batched by the GPU, and the seeded placements for it
Expand Down
4 changes: 2 additions & 2 deletions sdk/render/src/3d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// carries its name (data-3d) and props (data-props, JSON) for Bevy to draw; a Mesh also carries its Manifold
// expression (data-shape). Engine-safe: this module imports nothing beyond React.
import { toHex } from "./colour";
export { Canvas3D, Cuboid, Sphere, Plane3d, Cylinder, Torus, Cone, Capsule, Capsule3d, BufferMesh, Text3D, SurfaceShader, ThreeShaderMaterial, surfaceShader, samplerSpec, FramePass, Compute, PhaseItem, Atmosphere, eulerOf, Entity, Refinish, clipEvents, Model, ImagePlane, surfaceTurn, Decal, Plate, Bloom, Fog, ToneMapping, Grade, Environment, EnvironmentMapLight, Skybox, AmbientOcclusion, AntiAliasing, Shadows, VolumetricFog, FogVolume, Fire, dofOf, DepthOfField, Outline, Fisheye, LensDistortion, MotionBlur, checkPass, Look, Scene, Entities, BevyComponent, Gizmo, ShaderMesh, BevyResource, Span, RichText, Instances, scatter, Grass } from "./3d/all";
export type { Vec3, Canvas3DProps, CuboidProps, SphereProps, CylinderProps, TorusProps, Plane3dProps, ConeProps, CapsuleProps, Capsule3dProps, BufferMeshProps, Text3DProps, Animate3d, SurfaceDrawProps, ToonBand, ToonRim, ToonHighlight, ToonOutline, SurfaceShaderSpec, ThreeShaderMaterialProps, ThreeUniform, SamplerSpec, SamplerWrap, FramePassProps, ComputeProps, MeshSlab, PhaseItemProps, PhaseAttribute, AtmosphereProps, BevyParts, EntityProps, ModelProps, AnimGraphNode, ImagePlaneProps, DecalProps, PlateProps, BloomProps, FogProps, FogColor, FogFalloff, ToneMappingProps, GradeSection, GradeProps, EnvironmentProps, EnvironmentMapLightProps, SkyboxProps, AmbientOcclusionProps, AntiAliasingProps, ShadowsProps, VolumetricFogProps, FogVolumeProps, FireProps, DepthOfFieldProps, OutlineProps, LensCommon, FisheyeProps, LensDistortionProps, MotionBlurProps, LookProps, LookPass, SceneProps, BevyComponentProps, GizmoProps, ShaderMeshProps, SpanProps, GlyphInfo, GlyphStyle, RichTextProps, Instance, InstancesProps, PlanBox, ScatterOptions, GrassProps, GrassLod } from "./3d/all";
export { Canvas3D, Cuboid, Sphere, Plane3d, Cylinder, Torus, Cone, Capsule, Capsule3d, BufferMesh, Text3D, SurfaceShader, ThreeShaderMaterial, surfaceShader, samplerSpec, FramePass, Compute, PhaseItem, MeshVertexAttribute, ATTRIBUTE_POSITION, ATTRIBUTE_NORMAL, ATTRIBUTE_UV_0, ATTRIBUTE_UV_1, ATTRIBUTE_TANGENT, ATTRIBUTE_COLOR, Atmosphere, eulerOf, Entity, Refinish, clipEvents, Model, ImagePlane, surfaceTurn, Decal, Plate, Bloom, Fog, ToneMapping, Grade, Environment, EnvironmentMapLight, Skybox, AmbientOcclusion, AntiAliasing, Shadows, VolumetricFog, FogVolume, Fire, dofOf, DepthOfField, Outline, Fisheye, LensDistortion, MotionBlur, checkPass, Look, Scene, Entities, BevyComponent, Gizmo, ShaderMesh, BevyResource, Span, RichText, Instances, scatter, Grass } from "./3d/all";
export type { Vec3, Canvas3DProps, CuboidProps, SphereProps, CylinderProps, TorusProps, Plane3dProps, ConeProps, CapsuleProps, Capsule3dProps, BufferMeshProps, Text3DProps, Animate3d, SurfaceDrawProps, ToonBand, ToonRim, ToonHighlight, ToonOutline, SurfaceShaderSpec, ThreeShaderMaterialProps, ThreeUniform, SamplerSpec, SamplerWrap, FramePassProps, ComputeProps, MeshSlab, PhaseItemProps, PhaseAttribute, VertexFormat, MeshAttribute, AtmosphereProps, BevyParts, EntityProps, ModelProps, AnimGraphNode, ImagePlaneProps, DecalProps, PlateProps, BloomProps, FogProps, FogColor, FogFalloff, ToneMappingProps, GradeSection, GradeProps, EnvironmentProps, EnvironmentMapLightProps, SkyboxProps, AmbientOcclusionProps, AntiAliasingProps, ShadowsProps, VolumetricFogProps, FogVolumeProps, FireProps, DepthOfFieldProps, OutlineProps, LensCommon, FisheyeProps, LensDistortionProps, MotionBlurProps, LookProps, LookPass, SceneProps, BevyComponentProps, GizmoProps, ShaderMeshProps, SpanProps, GlyphInfo, GlyphStyle, RichTextProps, Instance, InstancesProps, PlanBox, ScatterOptions, GrassProps, GrassLod } from "./3d/all";

export { CrossSection, crossSection, manifold, outline, Solid, type Bounds, type Polygons, type Section } from "./solid";
// blended distance fields and generated growth (trees, lofts, terrain, boulders, rosettes), as Solids (grow.ts)
Expand Down
1 change: 1 addition & 0 deletions sdk/render/src/3d/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export * from "./bevy";
export * from "./compute";
export * from "./framepass";
export * from "./phase";
export * from "./attribute";
export * from "./text";
export * from "./shapes";
export * from "./sprite";
Expand Down
32 changes: 32 additions & 0 deletions sdk/render/src/3d/attribute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// A mesh's vertex attributes by Bevy's name, id and format (docs/control.feature FC2d): a mesh's own (Mesh3d
// `attributes`) and the ones a Material's vertex buffer reads (Material `vertex_attributes`).

/** A vertex attribute's format, as Bevy's VertexFormat names it. */
export type VertexFormat = "Float32" | "Float32x2" | "Float32x3" | "Float32x4" | "Uint32" | "Uint32x2" | "Uint32x3" | "Uint32x4" | "Sint32" | "Sint32x4";

/** A vertex attribute: its name, its unique id (a high random one for your own, as Bevy asks, so it sorts after the
* built-in ones) and its format. MeshVertexAttribute.new("BlendColor", 988540917, "Float32x4") is Bevy's
* MeshVertexAttribute::new; Mesh's own are ATTRIBUTE_POSITION and the rest.
* @bevy bevy_mesh::MeshVertexAttribute */
export interface MeshVertexAttribute { name: string; id: number; format: VertexFormat }

const FORMATS: VertexFormat[] = ["Float32", "Float32x2", "Float32x3", "Float32x4", "Uint32", "Uint32x2", "Uint32x3", "Uint32x4", "Sint32", "Sint32x4"];

export const MeshVertexAttribute = {
new(name: string, id: number, format: VertexFormat): MeshVertexAttribute {
if (!name || !Number.isSafeInteger(id) || id < 0) throw new TypeError(`MeshVertexAttribute: a name and a whole-number id, got ${JSON.stringify([name, id])}`);
if (!FORMATS.includes(format)) throw new TypeError(`MeshVertexAttribute ${name}: format is one of ${FORMATS.join(", ")}, got ${JSON.stringify(format)}`);
return { name, id, format };
},
};

/** Bevy's Mesh::ATTRIBUTE_* (ids 0 to 5), as a Material's vertex buffer names them. */
export const ATTRIBUTE_POSITION = MeshVertexAttribute.new("Vertex_Position", 0, "Float32x3");
export const ATTRIBUTE_NORMAL = MeshVertexAttribute.new("Vertex_Normal", 1, "Float32x3");
export const ATTRIBUTE_UV_0 = MeshVertexAttribute.new("Vertex_Uv", 2, "Float32x2");
export const ATTRIBUTE_UV_1 = MeshVertexAttribute.new("Vertex_Uv_1", 3, "Float32x2");
export const ATTRIBUTE_TANGENT = MeshVertexAttribute.new("Vertex_Tangent", 4, "Float32x4");
export const ATTRIBUTE_COLOR = MeshVertexAttribute.new("Vertex_Color", 5, "Float32x4");

/** One attribute's values on a mesh: one a vertex, each a number or a list of the format's size. */
export type MeshAttribute = [MeshVertexAttribute, (number | number[])[]];
6 changes: 5 additions & 1 deletion sdk/render/src/3d/shapes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useAnimation3d, type Keys, type Move, type TrackSpec } from "@raea/math
import { Place3d, usePlace3d, usePointer3d, type LocalBounds, type PointerHandlers3d } from "../events3d";
import { Canvas3DProps, Vec3, checkArgs, checkPass, checkVec, node3d, serialisable } from "./all";
import { InCanvas3D } from "./model";
import type { MeshAttribute } from "./attribute";

const FILL = { position: "absolute", left: 0, top: 0, width: "100%", height: "100%" } as const;

Expand Down Expand Up @@ -329,6 +330,9 @@ export interface MeshProps extends PointerHandlers3d {
/** false: no shadow falls on it (Bevy's NotShadowReceiver: a backdrop that stays clean under a floating product, a
* glowing sign). True by default */
receiveShadow?: boolean;
/** its geometry's own vertex attributes, as Bevy's Mesh::with_inserted_attribute adds them: [[attribute, values]],
* a value a vertex (a Cuboid has 24), for a Material whose vertex_attributes read them */
attributes?: MeshAttribute[];
/** the render layers it's on ([0] by default; Bevy's RenderLayers): a camera draws it only when they share a layer,
* and only lights sharing a layer light it */
layers?: number[];
Expand Down Expand Up @@ -405,5 +409,5 @@ export function Mesh(props: MeshProps) {
const id = useId();
const m = usePlace3d(position, rotation, scale, props.quaternion);
usePointer3d(props.name ?? id, m, () => (shape === undefined ? boundsFromChildren(props.children) : undefined), props as Record<string, unknown>);
return node3d("Mesh", { ...props, animate: undefined, shape: undefined, position, rotation, scale }, <Place3d.Provider value={m}>{props.children}</Place3d.Provider>, Object.keys(extra).length ? extra : undefined);
return node3d("Mesh", { ...props, animate: undefined, shape: undefined, position, rotation, scale, attributes: props.attributes && JSON.stringify(props.attributes) }, <Place3d.Provider value={m}>{props.children}</Place3d.Provider>, Object.keys(extra).length ? extra : undefined);
}
Loading
Loading