Skip to content

armgit / raea

Public Imported from GitHub
0

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.

Worn paint is a surface shader of raea's own; raea-sys-wear goes (docs/examples.feature EX9)

shinyobjectz84b7659b0918
diff --git a/Cargo.lock b/Cargo.lock
index 38ad9a82..523c5fee 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -14953,7 +14953,6 @@ dependencies = [
"raea-sys-three-shader",
"raea-sys-viewbox",
"raea-sys-volume",
- "raea-sys-wear",
"serde_json",
"wgpu",
]
@@ -15495,7 +15494,6 @@ dependencies = [
"raea-sys-frame",
"raea-sys-layers",
"raea-sys-procmat",
- "raea-sys-wear",
"serde_json",
]
@@ -16532,15 +16530,6 @@ dependencies = [
"serde_json",
]
-[[package]]
-name = "raea-sys-wear"
-version = "0.1.0"
-dependencies = [
- "bevy",
- "raea-core-program",
- "serde_json",
-]
-
[[package]]
name = "raea-sys-weathering"
version = "0.1.0"
diff --git a/Cargo.toml b/Cargo.toml
index e867c061..a9c85e6e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -102,7 +102,6 @@ members = [
"systems/canvas",
"systems/tweak",
"systems/filters",
- "systems/wear",
"systems/weathering",
"systems/runoff",
"systems/touch",
diff --git a/docs/manual/reference/sdk/pbr.md b/docs/manual/reference/sdk/pbr.md
index cc810dde..3509e9fe 100644
--- a/docs/manual/reference/sdk/pbr.md
+++ b/docs/manual/reference/sdk/pbr.md
@@ -271,9 +271,8 @@ Used in: [3d/fog_volumes](https://github.com/shinyobjectz/raea/blob/main/sdk/rae
### `WearExtension`
-raea's chips, grime and rust over a StandardMaterial, as an ExtendedMaterial's extension (systems/wear):
-
-Bevy: `bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::extended_material::ExtendedMaterial<bevy_pbr::pbr_material::StandardMaterial, raea_sys_wear::Wear>>`.
+raea's chips, grime and rust over a StandardMaterial, as an ExtendedMaterial's extension: a surface shader of
+raea's own (worn.ts) on the hook a ShaderExtension uses, so its Bevy type is ShaderExtension's.
| Prop | Type | What it does |
| --- | --- | --- |
@@ -792,7 +791,7 @@ where density and heat come in: a burner, or an engine moving `at` -> `to` (a co
### `WearExtensionProps`
-raea's extension of StandardMaterial that wears it (the engine's Wear MaterialExtension, systems/wear): its paint
+raea's extension of StandardMaterial that wears it (a surface shader of raea's own, worn.ts): its paint
mottled, chipped back to `chip_color` on edges and a few spots, `grime` gathered low and underneath and `rust` run
down in streaks, fixed in the part's own space as it moves. `amount` 0-1; `chips`, `grime` and `rust` each 0-1 of it
(0.6, 0.5, 0.25); `scale` a blotch's size in metres (0.08); `seed` moves the pattern. It goes in an
diff --git a/docs/sdk-coverage.md b/docs/sdk-coverage.md
index e554b8c1..4c9538b7 100644
--- a/docs/sdk-coverage.md
+++ b/docs/sdk-coverage.md
@@ -14,7 +14,7 @@ reaches it yet).
| area | kind | tier 1 | tier 2 | tier 3 | not rendered | SVG attribute only | blocked upstream | excluded | unmapped | total |
|---|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|
| bevy | asset | 9 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 9 |
-| bevy | component | 61 | 869 | 0 | 0 | 0 | 0 | 1 | 0 | 931 |
+| bevy | component | 60 | 869 | 0 | 0 | 0 | 0 | 1 | 0 | 930 |
| bevy | event | 0 | 13 | 0 | 0 | 0 | 0 | 0 | 0 | 13 |
| bevy | message | 0 | 40 | 0 | 0 | 0 | 0 | 0 | 0 | 40 |
| bevy | resource | 4 | 86 | 0 | 0 | 0 | 0 | 1 | 0 | 91 |
@@ -23,9 +23,9 @@ reaches it yet).
| css | shorthand | 60 | 0 | 0 | 11 | 0 | 0 | 0 | 0 | 71 |
| element | html | 113 | 0 | 0 | 0 | 0 | 0 | 18 | 0 | 131 |
| plugin | declared | 0 | 0 | 53 | 0 | 0 | 21 | 0 | 3 | 77 |
-| **all** | | **495** | **1009** | **53** | **55** | **14** | **21** | **21** | **3** | **1671** |
+| **all** | | **494** | **1009** | **53** | **55** | **14** | **21** | **21** | **3** | **1670** |
-Reached (tiers 1-3): **1557**. The ratchet (`tools/sdk-coverage --check`, in tools/agents/check) keeps it from dropping.
+Reached (tiers 1-3): **1556**. The ratchet (`tools/sdk-coverage --check`, in tools/agents/check) keeps it from dropping.
## Bevy types (the plugin build's TypeRegistry)
@@ -624,7 +624,6 @@ Reached (tiers 1-3): **1557**. The ratchet (`tools/sdk-coverage --check`, in too
| `bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::extended_material::ExtendedMaterial<bevy_pbr::pbr_material::StandardMaterial, raea_sys_look::paint::Paint>>` | component | 2 | bevy.MeshMaterial3dExtendedMaterialStandardMaterialPaint (raea/plugins/bevy) |
| `bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::extended_material::ExtendedMaterial<bevy_pbr::pbr_material::StandardMaterial, raea_sys_material::toon::ToonExt>>` | component | 2 | bevy.MeshMaterial3dExtendedMaterialStandardMaterialToonExt (raea/plugins/bevy) |
| `bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::extended_material::ExtendedMaterial<bevy_pbr::pbr_material::StandardMaterial, raea_sys_shader::ShaderExt>>` | component | 1 | SurfaceShader (sdk/render/src/3d/materials.tsx) |
-| `bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::extended_material::ExtendedMaterial<bevy_pbr::pbr_material::StandardMaterial, raea_sys_wear::Wear>>` | component | 1 | WearExtension (sdk/render/src/bevy3d/extensions.tsx) |
| `bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::pbr_material::StandardMaterial>` | component | 1 | Mesh3d (sdk/render/src/bevy3d/core.tsx) |
| `bevy_pbr::mesh_material::MeshMaterial3d<bevy_trenchbroom::special_textures::QuakeSkyMaterial>` | component | 2 | bevy.MeshMaterial3dQuakeSkyMaterial (raea/plugins/bevy) |
| `bevy_pbr::mesh_material::MeshMaterial3d<raea_sys_fog::fire::FireMaterial>` | component | 2 | bevy.MeshMaterial3dFireMaterial (raea/plugins/bevy) |
diff --git a/docs/sdk-coverage/bevy.tsv b/docs/sdk-coverage/bevy.tsv
index 4e89ef38..923347ff 100644
--- a/docs/sdk-coverage/bevy.tsv
+++ b/docs/sdk-coverage/bevy.tsv
@@ -593,7 +593,6 @@ bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::extended_material::ExtendedMat
bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::extended_material::ExtendedMaterial<bevy_pbr::pbr_material::StandardMaterial, raea_sys_look::paint::Paint>> component
bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::extended_material::ExtendedMaterial<bevy_pbr::pbr_material::StandardMaterial, raea_sys_material::toon::ToonExt>> component
bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::extended_material::ExtendedMaterial<bevy_pbr::pbr_material::StandardMaterial, raea_sys_shader::ShaderExt>> component
-bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::extended_material::ExtendedMaterial<bevy_pbr::pbr_material::StandardMaterial, raea_sys_wear::Wear>> component
bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::pbr_material::StandardMaterial> component
bevy_pbr::mesh_material::MeshMaterial3d<bevy_trenchbroom::special_textures::QuakeSkyMaterial> component
bevy_pbr::mesh_material::MeshMaterial3d<raea_sys_fog::fire::FireMaterial> component
diff --git a/engine/render/Cargo.toml b/engine/render/Cargo.toml
index 7fd27f73..32091951 100644
--- a/engine/render/Cargo.toml
+++ b/engine/render/Cargo.toml
@@ -21,8 +21,6 @@ bevy = { version = "=0.20.0", default-features = false, features = ["std", "defa
image = { version = "0.25", default-features = false, features = ["png", "jpeg", "hdr"] }
# an edit as rows keyed per frame, and 3D shapes as values (docs/media.feature M2)
raea-core-program = { path = "../../core/program" }
-# worn surfaces on a mesh row (`wear`)
-raea-sys-wear = { path = "../../systems/wear" }
# procedural surfaces on a mesh row (`proc`)
raea-sys-procmat = { path = "../../systems/procmat" }
raea-core-shape = { path = "../../core/shape" }
diff --git a/engine/render/src/engine/raea_plugins.rs b/engine/render/src/engine/raea_plugins.rs
index 59b3e80f..8d61b72a 100644
--- a/engine/render/src/engine/raea_plugins.rs
+++ b/engine/render/src/engine/raea_plugins.rs
@@ -55,7 +55,6 @@ raea_plugin! {
Draws2dPlugin: raea_sys_sprite::install, "Plugins' 2D drawing brings up the scene's 2D camera (raea-sys-sprite's Draws2d).";
ScreenPlugin: super::screen::install, "Live pictures on surfaces, drawn as CRTs (screen.rs).";
GridPlugin: super::grid::install, "Greybox surfaces: graph paper and outlines (grid.rs).";
- WearPlugin: raea_sys_wear::install, "Worn surfaces: chipped paint, grime and rust (systems/wear).";
ProcMatPlugin: raea_sys_procmat::install, "Procedural surfaces: wood, stone, brick, tiles and the rest, with dust and dirt (systems/procmat).";
PaintPlugin: super::paint::install, "The paint and cartoon looks' surfaces (paint.rs).";
PassesPlugin: super::passes::install, "Render passes per view (passes.rs).";
diff --git a/engine/render/src/engine/spawn.rs b/engine/render/src/engine/spawn.rs
index 7c1668af..476e5aae 100644
--- a/engine/render/src/engine/spawn.rs
+++ b/engine/render/src/engine/spawn.rs
@@ -281,9 +281,6 @@ pub(crate) fn spawn_3d(world: &mut World, e: Entity, t: &Tup, inserted: &[Tup],
} else if let Some(extension) = raea_sys_procmat::of(vals).filter(|_| !scene3d::clay::on()) {
// a procedural surface (systems/procmat): its pattern, bump and use made on the GPU; clay draws it plain
grid::put(world, e, mesh, raea_sys_procmat::ProcMaterial { base: mat, extension }, vals);
- } else if let Some(extension) = raea_sys_wear::of(vals).filter(|_| !scene3d::clay::on()) {
- // worn paint (systems/wear): chipped edges, grime and rust, fixed in the part's own space
- grid::put(world, e, mesh, raea_sys_wear::WearMaterial { base: mat, extension }, vals);
} else if vals.get("shader").is_none() {
// a plain surface, see-through too: one material per value, shared by the parts that have it (share.rs;
// froxel_glass's fog copy is per material, so equal panes share it; mesh_ray_cast's six walls are one)
diff --git a/examples/materials/wear/wear.test.ts b/examples/materials/wear/wear.test.ts
index 9ee734fa..d7d0110d 100644
--- a/examples/materials/wear/wear.test.ts
+++ b/examples/materials/wear/wear.test.ts
@@ -1,6 +1,6 @@
// The corner house (house.ts) and raea/wear's demo (wear.tsx): every part docs/wear.feature WR7 lists, openings cut
-// through the walls (where cracks start), a valid .glb with one material per class, and a still for every cause and
-// for each of WR9's eight conditions by day and at dusk.
+// through the walls (where cracks start), a valid .glb with one material per class, a still for every cause and for
+// each of WR9's eight conditions by day and at dusk, and worn paint (docs/examples.feature EX9).
import { describe, expect, test } from "bun:test";
import { readFileSync } from "node:fs";
import { join } from "node:path";
@@ -71,6 +71,12 @@ describe("the demo", () => {
const listed = src.match(/const CAUSES: WearCause\[\] = \[([^\]]+)\]/)![1].match(/"(\w+)"/g)!.map((s) => s.slice(1, -1));
expect(listed.sort()).toEqual(Object.keys(DEBUG_CAUSES).sort());
});
+ test("draws worn paint with no bake, as <WearExtension> (EX9), from light to heavy", () => {
+ expect(src).toContain("paint: () => <Paint />");
+ const amounts = [...src.matchAll(/shape: "\w+", wear: \{ amount: ([\d.]+)/g)].map((m) => Number(m[1]));
+ expect(amounts).toEqual([0.5, 0.8, 1]);
+ expect(src).toContain("extension={<WearExtension {...wear} />}");
+ });
test("draws each of WR9's eight conditions by day and at dusk", () => {
expect(Object.keys(WEAR_CONDITIONS)).toHaveLength(8);
expect(src).toContain("CONDITIONS.flatMap((c) => [");
diff --git a/examples/materials/wear/wear.tsx b/examples/materials/wear/wear.tsx
index 13a95076..6e802692 100644
--- a/examples/materials/wear/wear.tsx
+++ b/examples/materials/wear/wear.tsx
@@ -1,12 +1,13 @@
// raea/wear's demo (docs/wear.feature WR7): the corner house (house.ts) baked once and shaded. It is drawn new,
// after 80 years of a coal-burning city, and as a ruin. Each cause appears in false colour, and the house stands
-// under each of WR9's eight conditions by day and at dusk. A shower crosses it as a timelapse (rain-passes).
+// under each of WR9's eight conditions by day and at dusk. A shower crosses it as a timelapse (rain-passes). `paint`
+// is the other wear, worn paint with no bake (<WearExtension>, a material's `wear`; docs/examples.feature EX9).
// bun examples/materials/wear/make-house.ts (once: writes media/house.glb)
// raea render examples/materials/wear/wear.tsx --composition after
// The south front faces +z and the east front +x, so north is -z. The corner stands at (12, 0, 0).
import { AbsoluteFill, Composition, registerRoot, staticFile, useCurrentFrame } from "raea";
-import { Cuboid, Model, ToneMapping } from "raea/3d";
-import { ExtendedMaterial, ShaderExtension, StandardMaterial } from "raea/pbr";
+import { Cuboid, Cylinder, Model, ToneMapping } from "raea/3d";
+import { ExtendedMaterial, ShaderExtension, StandardMaterial, WearExtension, type WearExtensionProps } from "raea/pbr";
import { Camera3d } from "raea/camera";
import { AmbientLight, DirectionalLight } from "raea/light";
import { Mesh3d } from "raea/mesh";
@@ -121,6 +122,35 @@ function RainPasses() {
return <House look={{ ...old, weather }} sky={raining ? "overcast" : "clear"} />;
}
+/** Worn paint with no bake: street iron painted green, its edges chipped to the metal, grime low and rust run down,
+ * by how worn each is (a bollard, a cabinet turned on the walk, a railing post). */
+export const PAINTED: { at: V3; yaw: number; shape: "bollard" | "cabinet" | "post"; wear: WearExtensionProps }[] = [
+ { at: [-1.4, 0, 0], yaw: 0, shape: "bollard", wear: { amount: 0.5 } },
+ { at: [0.2, 0, -0.3], yaw: 0.6, shape: "cabinet", wear: { amount: 0.8, grime: 0.7, seed: 3 } },
+ { at: [1.6, 0, 0.2], yaw: 0, shape: "post", wear: { amount: 1, chips: 0.9, rust: 0.7, rust_color: "#7e4220", seed: 5 } },
+];
+
+function Paint() {
+ const green = <StandardMaterial base_color="#2e5a3c" perceptual_roughness={0.45} metallic={0.1} />;
+ return (
+ <AbsoluteFill style={{ background: "#b9c2cc" }}>
+ <>
+ <Camera3d transform={Transform.fromXyz(0.4, 1.6, 4.6).lookingAt([0.2, 0.6, 0])} projection={{ Perspective: { fov: 0.7, near: 0.05, far: 50 } }} />
+ <ToneMapping mode="agx" />
+ <AmbientLight brightness={500} color="#c4ccd6" />
+ <DirectionalLight transform={Transform.fromXyz(-3, 5, 4).lookingAt([0, 0, 0])} illuminance={9000} color="#f2ece0" shadow_maps_enabled />
+ {PAINTED.map(({ at, yaw, shape, wear }) => (
+ <Mesh3d key={shape} transform={Transform.fromXyz(at[0], at[1] + (shape === "cabinet" ? 0.6 : shape === "post" ? 0.55 : 0.45), at[2]).withRotation(Quat.fromEuler("XYZ", 0, yaw, 0))}>
+ {shape === "cabinet" ? <Cuboid half_size={[0.4, 0.6, 0.22]} /> : <Cylinder radius={shape === "post" ? 0.06 : 0.11} half_height={shape === "post" ? 0.55 : 0.45} />}
+ <ExtendedMaterial base={green} extension={<WearExtension {...wear} />} />
+ </Mesh3d>
+ ))}
+ <Mesh3d transform={Transform.fromXyz(0, -0.05, 0)}><Cuboid half_size={[4, 0.05, 3]} /><StandardMaterial base_color="#8d8a84" perceptual_roughness={0.9} /></Mesh3d>
+ </>
+ </AbsoluteFill>
+ );
+}
+
const CAUSES: WearCause[] = ["class", "sky", "sun", "cavity", "edge", "flow", "deposit", "touch", "ground", "element", "open", "winter", "drift", "litter", "crack", "loss"];
const CONDITIONS = Object.keys(WEAR_CONDITIONS) as WearCondition[];
@@ -131,6 +161,7 @@ export const SHOTS: Record<string, () => JSX.Element> = {
ruin: () => <House look={{ age: AGES.ruin, weather: { day: 172 } }} />,
"ruin-near": () => <House look={{ age: AGES.ruin, weather: { day: 172 } }} {...NEAR} />,
door: () => <House look={{ ...old, weather: { day: 172 } }} {...DOOR} />,
+ paint: () => <Paint />,
...Object.fromEntries(CAUSES.map((c) => [`debug-${c}`, () => <House debug={c} />])),
...Object.fromEntries(CONDITIONS.flatMap((c) => [
[c, () => <House look={{ ...old, weather: WEAR_CONDITIONS[c] }} sky={SKY[c]} />],
diff --git a/runtime/scene/Cargo.toml b/runtime/scene/Cargo.toml
index 1cc38104..12205b36 100644
--- a/runtime/scene/Cargo.toml
+++ b/runtime/scene/Cargo.toml
@@ -13,8 +13,6 @@ raea-runtime-look = { path = "../look" }
raea-runtime-scene2d = { path = "../scene2d" }
bevy = { version = "=0.20.0", default-features = false, features = ["std"] }
serde_json = "1"
-# a material's `wear` prop as its row's columns
-raea-sys-wear = { path = "../../systems/wear" }
# a material's `procedural` prop as its row's columns
raea-sys-procmat = { path = "../../systems/procmat" }
# a review's fixed camera (RAEA_CAMERA) in place of the scene's own
diff --git a/runtime/scene/src/parts.rs b/runtime/scene/src/parts.rs
index d9eb1ec9..7ee0bde0 100644
--- a/runtime/scene/src/parts.rs
+++ b/runtime/scene/src/parts.rs
@@ -231,7 +231,6 @@ pub(crate) fn meshes_rows(tr: &Tracks, names: &[String], p: &mut Program) {
}
grid_columns(&mut row, m0);
paint_columns(&mut row, m0);
- raea_sys_wear::columns(&mut row, m0);
raea_sys_procmat::columns(&mut row, m0);
placement(p, &mut row, &id, &its);
visible(p, &mut row, &id, &track);
diff --git a/sdk/plugins/src/bevy.gen.tsx b/sdk/plugins/src/bevy.gen.tsx
index c1f4ca9e..f6a9c82f 100644
--- a/sdk/plugins/src/bevy.gen.tsx
+++ b/sdk/plugins/src/bevy.gen.tsx
@@ -1,6 +1,6 @@
// Generated by raea-bevy-sdk from raea's Bevy App's TypeRegistry (bevy (bevy)); don't edit, regenerate
-// (tools/bevy-plugins.sh gen). 389 component, 12 event, 38 message, 53 resource.
-// - In a scene (TSX): 442 wrappers, each a <BevyComponent> (or <BevyResource>) naming its type path, which raea-render
+// (tools/bevy-plugins.sh gen). 388 component, 12 event, 38 message, 53 resource.
+// - In a scene (TSX): 441 wrappers, each a <BevyComponent> (or <BevyResource>) naming its type path, which raea-render
// applies with ReflectComponent::insert. Put a component inside the <Mesh3d> it belongs to; <BevySettings> sets the
// plugin's resources.
// - In a TypeScript program (raea/bevy's BevyApp): `bevy` holds a typed handle for every component,
@@ -2555,9 +2555,6 @@ export type MeshMaterial3dExtendedMaterialStandardMaterialProcedural = string |
/** bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::extended_material::ExtendedMaterial<bevy_pbr::pbr_material::StandardMaterial, raea_sys_shader::ShaderExt>> */
export type MeshMaterial3dExtendedMaterialStandardMaterialShaderExt = string | Record<string, unknown> /* bevy_asset::handle::Handle<bevy_pbr::extended_material::ExtendedMaterial<bevy_pbr::pbr_material::StandardMaterial, raea_sys_shader::ShaderExt>>: in a Canvas3D an asset path or the asset inline */;
-/** bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::extended_material::ExtendedMaterial<bevy_pbr::pbr_material::StandardMaterial, raea_sys_wear::Wear>> */
-export type MeshMaterial3dExtendedMaterialStandardMaterialWear = string | Record<string, unknown> /* bevy_asset::handle::Handle<bevy_pbr::extended_material::ExtendedMaterial<bevy_pbr::pbr_material::StandardMaterial, raea_sys_wear::Wear>>: in a Canvas3D an asset path or the asset inline */;
-
/** bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::pbr_material::StandardMaterial> */
export type MeshMaterial3dStandardMaterial = string | Record<string, unknown> /* bevy_asset::handle::Handle<bevy_pbr::pbr_material::StandardMaterial>: in a Canvas3D an asset path or the asset inline */;
@@ -6016,11 +6013,6 @@ export function MeshMaterial3dExtendedMaterialStandardMaterialShaderExt(props: {
return <BevyComponent type="bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::extended_material::ExtendedMaterial<bevy_pbr::pbr_material::StandardMaterial, raea_sys_shader::ShaderExt>>" value={props.value ?? {"Uuid":"97128bb1-2588-480b-bdc6-87b4adbec477"}} from={props.from} />;
}
-/** bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::extended_material::ExtendedMaterial<bevy_pbr::pbr_material::StandardMaterial, raea_sys_wear::Wear>> (component); default {"Uuid":"97128bb1-2588-480b-bdc6-87b4adbec477"} */
-export function MeshMaterial3dExtendedMaterialStandardMaterialWear(props: { value?: MeshMaterial3dExtendedMaterialStandardMaterialWear; from?: number }) {
- return <BevyComponent type="bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::extended_material::ExtendedMaterial<bevy_pbr::pbr_material::StandardMaterial, raea_sys_wear::Wear>>" value={props.value ?? {"Uuid":"97128bb1-2588-480b-bdc6-87b4adbec477"}} from={props.from} />;
-}
-
/** bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::pbr_material::StandardMaterial> (component); default {"Uuid":"97128bb1-2588-480b-bdc6-87b4adbec477"} */
export function MeshMaterial3dStandardMaterial(props: { value?: MeshMaterial3dStandardMaterial; from?: number }) {
return <BevyComponent type="bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::pbr_material::StandardMaterial>" value={props.value ?? {"Uuid":"97128bb1-2588-480b-bdc6-87b4adbec477"}} from={props.from} />;
@@ -7703,8 +7695,6 @@ export const bevy = {
MeshMaterial3dExtendedMaterialStandardMaterialProcedural: component<MeshMaterial3dExtendedMaterialStandardMaterialProcedural>("bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::extended_material::ExtendedMaterial<bevy_pbr::pbr_material::StandardMaterial, raea_sys_procmat::Procedural>>"),
/** bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::extended_material::ExtendedMaterial<bevy_pbr::pbr_material::StandardMaterial, raea_sys_shader::ShaderExt>> (component) */
MeshMaterial3dExtendedMaterialStandardMaterialShaderExt: component<MeshMaterial3dExtendedMaterialStandardMaterialShaderExt>("bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::extended_material::ExtendedMaterial<bevy_pbr::pbr_material::StandardMaterial, raea_sys_shader::ShaderExt>>"),
- /** bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::extended_material::ExtendedMaterial<bevy_pbr::pbr_material::StandardMaterial, raea_sys_wear::Wear>> (component) */
- MeshMaterial3dExtendedMaterialStandardMaterialWear: component<MeshMaterial3dExtendedMaterialStandardMaterialWear>("bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::extended_material::ExtendedMaterial<bevy_pbr::pbr_material::StandardMaterial, raea_sys_wear::Wear>>"),
/** bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::pbr_material::StandardMaterial> (component) */
MeshMaterial3dStandardMaterial: component<MeshMaterial3dStandardMaterial>("bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::pbr_material::StandardMaterial>"),
/** bevy_pbr::mesh_material::MeshMaterial3d<bevy_trenchbroom::special_textures::QuakeSkyMaterial> (component) */
diff --git a/sdk/raea/conformance/bevy3d.test.tsx b/sdk/raea/conformance/bevy3d.test.tsx
index 46be0234..4c7174b5 100644
--- a/sdk/raea/conformance/bevy3d.test.tsx
+++ b/sdk/raea/conformance/bevy3d.test.tsx
@@ -168,6 +168,18 @@ describe("Mesh3d, Camera3d and StandardMaterial", () => {
expect(() => html(<ExtendedMaterial base={<StandardMaterial unlit />} extension={<WearExtension amount={0.5} />} />)).toThrow(/unlit/);
});
+ test("wear is a surface shader of raea's own (EX9): its uniforms, none at amount 0, alone", () => {
+ const out = html(<MeshStandardMaterial color="#d9c69c" wear={{ amount: 0.6, seed: 2, chipColor: "#333333" }} />);
+ expect(out).not.toContain("wear&quot;:{");
+ expect(out).toContain("fn surface(in: VertexOutput, pbr: ptr&lt;function, PbrInput&gt;)");
+ expect(out).toContain("&quot;wear&quot;:[0.6,0.08,0.6,0.5]");
+ expect(out).toContain("&quot;wear2&quot;:[0.25,2,0,0]");
+ expect(out).toContain("&quot;chip_color&quot;:&quot;#333333&quot;");
+ expect(html(<MeshStandardMaterial color="#d9c69c" wear={{ amount: 0 }} />)).toBe(html(<MeshStandardMaterial color="#d9c69c" />));
+ expect(() => html(<MeshStandardMaterial wear={{ amount: 0.5 }} shader={{ wesl: "fn surface(in: VertexOutput, pbr: ptr<function, PbrInput>) {}" }} />)).toThrow(/wear or shader/);
+ expect(() => html(<MeshStandardMaterial wear={{ amount: 0.5 }} grid={{ cell: 0.5 }} />)).toThrow(/grid or wear/);
+ });
+
test("inside a Model a StandardMaterial re-covers with only the fields given, as the old material did", () => {
const m = (el: React.ReactElement) => html(<Model src="chair.glb">{el}</Model>);
expect(m(<StandardMaterial material="Fabric" base_color="#7a3b2e" />)).toBe(m(<MeshStandardMaterial color="#7a3b2e" material="Fabric" />));
diff --git a/sdk/render/src/3d/materials.tsx b/sdk/render/src/3d/materials.tsx
index 0a7c8d96..f9486637 100644
--- a/sdk/render/src/3d/materials.tsx
+++ b/sdk/render/src/3d/materials.tsx
@@ -1,6 +1,7 @@
// Materials: surfaces drawn on, standard and physical materials, toon bands and outlines.
import { toHex } from "../colour";
import { checkOverlays, type GridOverlay, type PaintOverlay, type ProceduralSurface, type WearOverlay } from "../overlays";
+import { wornShader } from "../worn";
import { useAnimation3d } from "@raea/math/animate";
import { Animate3d, apply3d, node3d } from "./all";
@@ -60,7 +61,8 @@ export interface MeshStandardMaterialProps extends SurfaceDrawProps {
grid?: GridOverlay;
/** under a paint look, the surface broken up by noise: PaintOverlay, overlays.ts */
paint?: PaintOverlay;
- /** a worn surface, fixed on the part as it moves (systems/wear): WearOverlay, overlays.ts */
+ /** a worn surface, fixed on the part as it moves (worn.ts, a surface shader; not with `shader` or `grid`):
+ * WearOverlay, overlays.ts */
wear?: WearOverlay;
/** a pattern made on the GPU with dust, dirt and worn edges (systems/procmat): ProceduralSurface, overlays.ts */
procedural?: ProceduralSurface;
@@ -301,6 +303,14 @@ export function checkMaterial(owner: string, props: Record<string, unknown>): vo
const v = props[k];
if (v !== undefined && !(k === "map" && v === null) && !(typeof v === "string" && v !== "")) throw new TypeError(`${owner}: ${k} must be a picture's path (staticFile("floor_diff.jpg")) or a data: URL, got ${JSON.stringify(v)}`);
}
+ // `wear` is a surface shader of raea's own (worn.ts, docs/examples.feature EX9); none at amount 0
+ if (props.wear !== undefined) {
+ if (props.shader !== undefined) throw new TypeError(`${owner}: wear is a surface shader of its own; give wear or shader, not both`);
+ if (props.grid !== undefined) throw new TypeError(`${owner}: grid draws alone; give grid or wear, not both`);
+ const w = props.wear as WearOverlay;
+ delete props.wear;
+ if (w.amount > 0) props.shader = wornShader(w);
+ }
if (props.shader !== undefined) props.shader = surfaceShader(owner, props.shader as SurfaceShaderSpec);
if (props.sampler !== undefined) samplerSpec(owner, props.sampler as SamplerSpec);
if (props.samplers !== undefined) {
@@ -318,7 +328,7 @@ export function checkMaterial(owner: string, props: Record<string, unknown>): vo
/** A physically based surface for the Mesh it's inside.
* `grid` draws graph paper over it (engine/render grid.rs):
- * `wear` chips, grimes and rusts it in the part's own space (systems/wear):
+ * `wear` chips, grimes and rusts it in the part's own space (worn.ts):
* @deprecated <StandardMaterial>, raea/pbr (Bevy's fields: base_color, perceptual_roughness, metallic)
*/
export function MeshStandardMaterial(props: MeshStandardMaterialProps) {
diff --git a/sdk/render/src/bevy3d/extensions.tsx b/sdk/render/src/bevy3d/extensions.tsx
index 4d7b4d07..9e2806b1 100644
--- a/sdk/render/src/bevy3d/extensions.tsx
+++ b/sdk/render/src/bevy3d/extensions.tsx
@@ -51,7 +51,7 @@ export function PaintExtension(_: PaintExtensionProps): ReactNode {
throw new TypeError("PaintExtension goes in an ExtendedMaterial: <ExtendedMaterial base={<StandardMaterial />} extension={<PaintExtension scale={0.5} />} />");
}
-/** raea's extension of StandardMaterial that wears it (the engine's Wear MaterialExtension, systems/wear): its paint
+/** raea's extension of StandardMaterial that wears it (a surface shader of raea's own, worn.ts): its paint
* mottled, chipped back to `chip_color` on edges and a few spots, `grime` gathered low and underneath and `rust` run
* down in streaks, fixed in the part's own space as it moves. `amount` 0-1; `chips`, `grime` and `rust` each 0-1 of it
* (0.6, 0.5, 0.25); `scale` a blotch's size in metres (0.08); `seed` moves the pattern. It goes in an
@@ -77,8 +77,8 @@ export interface WearExtensionProps {
rust_color?: string;
}
-/** raea's chips, grime and rust over a StandardMaterial, as an ExtendedMaterial's extension (systems/wear):
- * @bevy bevy_pbr::mesh_material::MeshMaterial3d<bevy_pbr::extended_material::ExtendedMaterial<bevy_pbr::pbr_material::StandardMaterial, raea_sys_wear::Wear>> */
+/** raea's chips, grime and rust over a StandardMaterial, as an ExtendedMaterial's extension: a surface shader of
+ * raea's own (worn.ts) on the hook a ShaderExtension uses, so its Bevy type is ShaderExtension's. */
export function WearExtension(_: WearExtensionProps): ReactNode {
throw new TypeError("WearExtension goes in an ExtendedMaterial: <ExtendedMaterial base={<StandardMaterial />} extension={<WearExtension amount={0.6} />} />");
}
diff --git a/sdk/render/src/overlays.ts b/sdk/render/src/overlays.ts
index bdb9a0e0..a59296e1 100644
--- a/sdk/render/src/overlays.ts
+++ b/sdk/render/src/overlays.ts
@@ -1,6 +1,6 @@
-// A material's overlays, drawn over its standard surface by the engine: graph paper (`grid`, raea-render's grid.rs),
-// a paint look's breakup (`paint`, paint.rs), wear (`wear`, systems/wear) and a procedural surface (`procedural`,
-// systems/procmat). Their props and checks; 3d.tsx's materials take them all, a Model takes `grid`.
+// A material's overlays, drawn over its standard surface: graph paper (`grid`, raea-render's grid.rs), a paint look's
+// breakup (`paint`, paint.rs), wear (`wear`, a surface shader of raea's own, worn.ts) and a procedural surface
+// (`procedural`, systems/procmat). Their props and checks; 3d.tsx's materials take them all, a Model takes `grid`.
import { toHex } from "./colour";
/** graph paper over the surface (greybox levels): lines every `cell` world units (fixed in the world, so they run on
@@ -13,7 +13,7 @@ export interface GridOverlay { cell: number; major?: number; color?: string; edg
* uneven paint */
export interface PaintOverlay { breakup?: number; scale?: number; color?: string; amount?: number }
-/** a worn surface (systems/wear), fixed in the part's own space so it rides with a moving part: `amount` 0..1 of
+/** a worn surface (worn.ts), fixed in the part's own space so it rides with a moving part: `amount` 0..1 of
* wear, its paint chipped back to `chipColor` at edges (`chips`), `grime` low and underneath, `rust` run down in
* streaks (each 0..1 of the amount), in blotches of `scale` metres (0.08); `seed` moves the pattern */
export interface WearOverlay { amount: number; scale?: number; chips?: number; grime?: number; rust?: number; seed?: number; chipColor?: string; grimeColor?: string; rustColor?: string }
diff --git a/sdk/render/src/worn.ts b/sdk/render/src/worn.ts
new file mode 100644
index 00000000..7766e497
--- /dev/null
+++ b/sdk/render/src/worn.ts
@@ -0,0 +1,119 @@
+// Worn paint (docs/examples.feature EX9): the standard material with use written over it, as a surface shader on
+// raea's public hook (raea-sys-shader), where it was the engine's own MaterialExtension (raea-sys-wear) until 11-19.
+// MeshStandardMaterial's `wear` and raea/pbr's <WearExtension> draw it. Paint mottled by noise, its edges chipped back
+// to `chipColor` (the metal under the paint, shinier), grime gathered low and on undersides, and rust run down in
+// streaks. The noise is taken in the mesh's own space, not the world's, so a walking robot's wear stays where it is on
+// each part instead of swimming over it; parts built in one space (a rigged build's pieces, in the rest pose) share
+// it, so their wear lines up across a seam. Edges are found from how fast the surface's normal turns on screen
+// against how fast its position does (its curvature, 1 / radius), so a rounded edge of a few millimetres chips and a
+// broad face doesn't. raea/wear's wearShader is the other wear: the weather's, baked from a building's own shape.
+import type { WearOverlay } from "./overlays";
+
+/** The surface hook. Its uniforms: `wear` (amount, a blotch's size in metres, chips, grime), `wear2` (rust, seed),
+ * and the chips', grime's and rust's colours. */
+export const WORN_WESL = /* wgsl */ `
+fn worn_hash(p: vec3<f32>) -> f32 {
+ let q = fract(p * 0.3183099 + vec3(0.1, 0.2, 0.3));
+ let r = q * 17.0;
+ return fract(r.x * r.y * r.z * (r.x + r.y + r.z));
+}
+
+fn worn_vnoise(p: vec3<f32>) -> f32 {
+ let i = floor(p);
+ let f = fract(p);
+ let u = f * f * (3.0 - 2.0 * f);
+ let a = mix(mix(worn_hash(i), worn_hash(i + vec3(1.0, 0.0, 0.0)), u.x), mix(worn_hash(i + vec3(0.0, 1.0, 0.0)), worn_hash(i + vec3(1.0, 1.0, 0.0)), u.x), u.y);
+ let b = mix(mix(worn_hash(i + vec3(0.0, 0.0, 1.0)), worn_hash(i + vec3(1.0, 0.0, 1.0)), u.x), mix(worn_hash(i + vec3(0.0, 1.0, 1.0)), worn_hash(i + vec3(1.0, 1.0, 1.0)), u.x), u.y);
+ return mix(a, b, u.z);
+}
+
+// four octaves, 0..1
+fn worn_fbm(p: vec3<f32>) -> f32 {
+ var s = 0.0;
+ var w = 0.5;
+ var q = p;
+ for (var k = 0; k < 4; k++) {
+ s += w * worn_vnoise(q);
+ q = q * 2.03 + vec3(1.7, 9.2, 3.1);
+ w *= 0.5;
+ }
+ return s / 0.9375;
+}
+
+fn surface(in: VertexOutput, pbr: ptr<function, PbrInput>) {
+ let amount = u_wear().x;
+ let scale = u_wear().y;
+ let chips = u_wear().z;
+ let grimes = u_wear().w;
+ let rusts = u_wear2().x;
+ let seed = u_wear2().y;
+
+ var p = in.world_position.xyz;
+ var n = normalize(in.world_normal);
+@if(VERTEX_OUTPUT_INSTANCE_INDEX) {
+ // the mesh's own space, so the wear rides with the part
+ let m = bevy_pbr::render::mesh_functions::get_local_from_world(in.instance_index);
+ p = (m * vec4(in.world_position.xyz, 1.0)).xyz;
+ n = normalize((m * vec4(n, 0.0)).xyz);
+}
+ let q = p / scale + vec3(seed * 13.1);
+
+ // curvature (1 / metres): how fast the normal turns against how fast the position moves, on screen
+ let curve = length(fwidth(in.world_normal)) / max(length(fwidth(in.world_position.xyz)), 1e-5);
+ let edge = smoothstep(25.0, 90.0, curve) + 0.5 * smoothstep(0.12, 0.35, 1.0 - max(abs(n.x), max(abs(n.y), abs(n.z))));
+ let a = amount;
+
+ var c = (*pbr).material.base_color.rgb;
+ var rough = (*pbr).material.perceptual_roughness;
+ var metal = (*pbr).material.metallic;
+
+ // paint: mottled a little, and duller where it's thin
+ let mottle = worn_fbm(q * 0.6);
+ c *= 1.0 + (mottle - 0.5) * 0.22 * a;
+ rough = clamp(rough + (worn_fbm(q * 1.7 + 5.0) - 0.5) * 0.3 * a, 0.04, 1.0);
+
+ // grime: low, in hollows and undersides, broken up
+ let low = clamp(-n.y, 0.0, 1.0) * 0.6 + smoothstep(0.55, 0.85, worn_fbm(q * 0.35 + 20.0));
+ let g = clamp(low * grimes * a, 0.0, 0.85) * smoothstep(0.3, 0.7, worn_fbm(q * 2.3 + 40.0) + 0.25);
+ c = mix(c, u_grime_color().rgb, g);
+ rough = mix(rough, 0.9, g);
+
+ // rust: streaks run down from blotches (noise squashed along local y)
+ let streak = worn_fbm(vec3(q.x * 3.0, q.y * 0.25, q.z * 3.0) + 60.0);
+ let blotch = smoothstep(0.6, 0.8, worn_fbm(q * 0.5 + 80.0));
+ let r = clamp((blotch + smoothstep(0.62, 0.8, streak) * 0.6) * rusts * a, 0.0, 0.9);
+ c = mix(c, u_rust_color().rgb * (0.7 + 0.6 * worn_vnoise(q * 6.0)), r);
+ rough = mix(rough, 0.95, r);
+ metal = mix(metal, 0.0, r);
+
+ // chips: the paint gone at edges and a few scattered spots, the metal under it showing, shinier; an edge lowers
+ // the bar a long way, so at full wear most edges chip and only the odd spot on a broad face does
+ let s = chips * a;
+ let field = worn_fbm(q * 2.5 + 100.0) + edge * 0.5 - 0.2;
+ let chip = smoothstep(1.0 - s * 0.55, 1.04 - s * 0.55, field);
+ c = mix(c, u_chip_color().rgb, chip);
+ rough = mix(rough, 0.32, chip);
+ metal = mix(metal, 0.85, chip);
+
+ (*pbr).material.base_color = vec4(c, (*pbr).material.base_color.a);
+ (*pbr).material.perceptual_roughness = rough;
+ (*pbr).material.metallic = metal;
+}
+`;
+
+const share = (v: number | undefined, d: number) => Math.min(1, Math.max(0, v ?? d));
+
+/** A material's `wear` as the surface shader that draws it: `{ wesl, uniforms }` for its `shader`. */
+export function wornShader(w: WearOverlay): { wesl: string; uniforms: Record<string, number[] | string> } {
+ const amount = Math.min(1, w.amount);
+ return {
+ wesl: WORN_WESL,
+ uniforms: {
+ wear: [amount, w.scale !== undefined && w.scale > 0 ? w.scale : 0.08, share(w.chips, 0.6), share(w.grime, 0.5)],
+ wear2: [share(w.rust, 0.25), w.seed ?? 0, 0, 0],
+ chip_color: w.chipColor ?? "#3a3c40",
+ grime_color: w.grimeColor ?? "#3b3226",
+ rust_color: w.rustColor ?? "#7a3f1c",
+ },
+ };
+}
diff --git a/systems/wear/Cargo.toml b/systems/wear/Cargo.toml
deleted file mode 100644
index a9a6b7e9..00000000
--- a/systems/wear/Cargo.toml
+++ /dev/null
@@ -1,14 +0,0 @@
-[package]
-name = "raea-sys-wear"
-version = "0.1.0"
-edition = "2024"
-license = "FSL-1.1-ALv2"
-publish = false
-description = "Worn surfaces: the standard material with chipped edges, grime, rust streaks and mottled paint over it, its noise in the mesh's own space so the wear stays on a moving part"
-
-[dependencies]
-bevy = { version = "=0.20.0", default-features = false, features = ["std", "bevy_pbr"] }
-# a mesh row's values
-raea-core-program = { path = "../../core/program" }
-# a material's `wear` prop, as the SDK sends it
-serde_json = "1"
diff --git a/systems/wear/src/lib.rs b/systems/wear/src/lib.rs
deleted file mode 100644
index d03127f3..00000000
--- a/systems/wear/src/lib.rs
+++ /dev/null
@@ -1,106 +0,0 @@
-//! Worn surfaces: the standard material with use written over it. Paint mottled by noise, its edges chipped back to
-//! `chip_color` (the metal under the paint, shinier), grime gathered low and on undersides, and rust run down in
-//! streaks. The noise is taken in the mesh's own space, not the world's, so a walking robot's wear stays where it is
-//! on each part instead of swimming over it; a part built in rest-pose coordinates (as a rigged build's pieces are)
-//! shares one space with its neighbours, so their wear lines up across a seam. Edges are found from how fast the
-//! surface's normal turns on screen against how fast its position does (its curvature, 1 / radius), so a rounded edge
-//! of a few millimetres chips and a broad face doesn't.
-//!
-//! A mesh row's columns (all optional but wear_amount): wear_amount (0..1, how worn; on when > 0), wear_scale (metres
-//! across a blotch, 0.08), wear_chips, wear_grime, wear_rust (each 0..1 of the amount: 0.6, 0.5, 0.25), wear_seed,
-//! wear_chip_color ('#3a3c40'), wear_grime_color ('#3b3226'), wear_rust_color ('#7a3f1c'). `columns` makes them from
-//! a material's `wear` prop (raea-runtime-react's scene3d); `of` reads them back where the engine spawns the mesh.
-
-use bevy::pbr::{ExtendedMaterial, MaterialExtension};
-use bevy::prelude::*;
-use bevy::render::render_resource::{AsBindGroup, ShaderType};
-use bevy::shader::ShaderRef;
-use raea_core_program::ir::V;
-use serde_json::{Map, Value};
-use std::collections::BTreeMap;
-
-pub type WearMaterial = ExtendedMaterial<StandardMaterial, Wear>;
-
-pub fn install(app: &mut App) {
- bevy::asset::embedded_asset!(app, "wear.wesl");
- app.add_plugins(MaterialPlugin::<WearMaterial>::default());
-}
-
-#[derive(Asset, TypePath, AsBindGroup, Clone, Debug)]
-pub struct Wear {
- #[uniform(100)]
- p: WearParams,
-}
-
-#[derive(ShaderType, Clone, Copy, Default, PartialEq, Debug)]
-struct WearParams {
- chip: Vec4,
- grime: Vec4,
- rust: Vec4,
- amount: f32,
- scale: f32,
- chips: f32,
- grimes: f32,
- rusts: f32,
- seed: f32,
-}
-
-impl MaterialExtension for Wear {
- fn fragment_shader() -> ShaderRef {
- "embedded://raea_sys_wear/wear.wesl".into()
- }
-}
-
-/// The prop's keys and the columns they become; colours pass through as the hex the SDK checked
-const NUMS: [(&str, &str); 6] =
- [("amount", "wear_amount"), ("scale", "wear_scale"), ("chips", "wear_chips"), ("grime", "wear_grime"), ("rust", "wear_rust"), ("seed", "wear_seed")];
-const COLOURS: [(&str, &str); 3] = [("chipColor", "wear_chip_color"), ("grimeColor", "wear_grime_color"), ("rustColor", "wear_rust_color")];
-
-/// A material's `wear` prop as its row's columns (the first frame's, as a grid's are)
-pub fn columns(row: &mut BTreeMap<String, V>, props: &Map<String, Value>) {
- let Some(w) = props.get("wear").and_then(Value::as_object) else { return };
- for (k, col) in NUMS {
- if let Some(n) = w.get(k).and_then(Value::as_f64) {
- row.insert(col.into(), V::N(n));
- }
- }
- for (k, col) in COLOURS {
- if let Some(s) = w.get(k).and_then(Value::as_str) {
- row.insert(col.into(), V::S(s.into()));
- }
- }
-}
-
-/// The wear a mesh row asks for, or None (no wear_amount above 0)
-pub fn of(vals: &BTreeMap<String, V>) -> Option<Wear> {
- let num = |col: &str| vals.get(col).map(|v| v.num() as f32);
- let amount = num("wear_amount").unwrap_or(0.0).min(1.0);
- if amount <= 0.0 {
- return None;
- }
- let rgb = |col: &str, d: Srgba| {
- let c = match vals.get(col) {
- Some(V::S(s)) => Srgba::hex(s.trim()).unwrap_or(d),
- _ => d,
- };
- let l = LinearRgba::from(c);
- Vec4::new(l.red, l.green, l.blue, 1.0)
- };
- let share = |col: &str, d: f32| num(col).unwrap_or(d).clamp(0.0, 1.0);
- Some(Wear {
- p: WearParams {
- chip: rgb("wear_chip_color", Srgba::rgb(0.227, 0.235, 0.251)),
- grime: rgb("wear_grime_color", Srgba::rgb(0.231, 0.196, 0.149)),
- rust: rgb("wear_rust_color", Srgba::rgb(0.478, 0.247, 0.11)),
- amount,
- scale: num("wear_scale").filter(|s| *s > 0.0).unwrap_or(0.08),
- chips: share("wear_chips", 0.6),
- grimes: share("wear_grime", 0.5),
- rusts: share("wear_rust", 0.25),
- seed: num("wear_seed").unwrap_or(0.0),
- },
- })
-}
-
-#[cfg(test)]
-mod tests;
diff --git a/systems/wear/src/tests.rs b/systems/wear/src/tests.rs
deleted file mode 100644
index 172423fd..00000000
--- a/systems/wear/src/tests.rs
+++ /dev/null
@@ -1,31 +0,0 @@
-use super::*;
-use serde_json::json;
-
-fn row(v: Value) -> BTreeMap<String, V> {
- let mut row = BTreeMap::new();
- columns(&mut row, v.as_object().unwrap());
- row
-}
-
-#[test]
-fn a_prop_becomes_columns() {
- let r = row(json!({ "wear": { "amount": 0.7, "rust": 0.4, "chipColor": "#202020", "bogus": 1 } }));
- assert_eq!(r.len(), 3);
- assert!(matches!(r.get("wear_amount"), Some(V::N(n)) if *n == 0.7));
- assert!(matches!(r.get("wear_chip_color"), Some(V::S(s)) if s == "#202020"));
- assert!(row(json!({ "color": "#fff" })).is_empty());
-}
-
-#[test]
-fn off_without_an_amount() {
- assert!(of(&BTreeMap::new()).is_none());
- assert!(of(&row(json!({ "wear": { "amount": 0 } }))).is_none());
-}
-
-#[test]
-fn defaults_and_clamps() {
- let w = of(&row(json!({ "wear": { "amount": 3, "chips": -1, "scale": 0 } }))).unwrap();
- assert_eq!((w.p.amount, w.p.chips, w.p.scale, w.p.grimes), (1.0, 0.0, 0.08, 0.5));
- let red = of(&row(json!({ "wear": { "amount": 0.5, "rustColor": "#ff0000" } }))).unwrap();
- assert_eq!(red.p.rust, Vec4::new(1.0, 0.0, 0.0, 1.0));
-}
diff --git a/systems/wear/src/wear.wesl b/systems/wear/src/wear.wesl
deleted file mode 100644
index 8c15cfe7..00000000
--- a/systems/wear/src/wear.wesl
+++ /dev/null
@@ -1,121 +0,0 @@
-// lib.rs: wear over the standard material (Bevy's extended-material fragment, its lighting kept). Noise in the mesh's
-// own space; edges from screen-space curvature; the paint's colour, roughness and metalness changed before the light.
-import bevy_pbr::render::pbr_fragment::pbr_input_from_standard_material;
-import bevy_pbr::render::pbr_functions::alpha_discard;
-import bevy_pbr::render::mesh_functions::get_local_from_world;
-@if(PREPASS_PIPELINE) import bevy_pbr::prepass::io::{VertexOutput, FragmentOutput};
-@if(PREPASS_PIPELINE) import bevy_pbr::deferred::functions::deferred_output;
-@if(!PREPASS_PIPELINE) import bevy_pbr::render::forward_io::{VertexOutput, FragmentOutput};
-@if(!PREPASS_PIPELINE) import bevy_pbr::render::pbr_functions::{apply_pbr_lighting, main_pass_post_lighting_processing};
-
-struct Wear {
- chip: vec4<f32>,
- grime: vec4<f32>,
- rust: vec4<f32>,
- amount: f32,
- scale: f32,
- chips: f32,
- grimes: f32,
- rusts: f32,
- seed: f32,
-}
-
-@group(constants::MATERIAL_BIND_GROUP) @binding(100)
-var<uniform> wear: Wear;
-
-fn hash(p: vec3<f32>) -> f32 {
- let q = fract(p * 0.3183099 + vec3(0.1, 0.2, 0.3));
- let r = q * 17.0;
- return fract(r.x * r.y * r.z * (r.x + r.y + r.z));
-}
-
-fn vnoise(p: vec3<f32>) -> f32 {
- let i = floor(p);
- let f = fract(p);
- let u = f * f * (3.0 - 2.0 * f);
- let a = mix(mix(hash(i), hash(i + vec3(1.0, 0.0, 0.0)), u.x), mix(hash(i + vec3(0.0, 1.0, 0.0)), hash(i + vec3(1.0, 1.0, 0.0)), u.x), u.y);
- let b = mix(mix(hash(i + vec3(0.0, 0.0, 1.0)), hash(i + vec3(1.0, 0.0, 1.0)), u.x), mix(hash(i + vec3(0.0, 1.0, 1.0)), hash(i + vec3(1.0, 1.0, 1.0)), u.x), u.y);
- return mix(a, b, u.z);
-}
-
-// four octaves, 0..1
-fn fbm(p: vec3<f32>) -> f32 {
- var s = 0.0;
- var w = 0.5;
- var q = p;
- for (var k = 0; k < 4; k++) {
- s += w * vnoise(q);
- q = q * 2.03 + vec3(1.7, 9.2, 3.1);
- w *= 0.5;
- }
- return s / 0.9375;
-}
-
-@fragment
-fn fragment(
- in: VertexOutput,
- @builtin(front_facing) is_front: bool,
-) -> FragmentOutput {
- var pbr_input = pbr_input_from_standard_material(in, is_front);
-
- var p = in.world_position.xyz;
- var n = normalize(in.world_normal);
-@if(VERTEX_OUTPUT_INSTANCE_INDEX) {
- // the mesh's own space, so the wear rides with the part
- let m = get_local_from_world(in.instance_index);
- p = (m * vec4(in.world_position.xyz, 1.0)).xyz;
- n = normalize((m * vec4(n, 0.0)).xyz);
-}
- let q = p / wear.scale + vec3(wear.seed * 13.1);
-
- // curvature (1 / metres): how fast the normal turns against how fast the position moves, on screen
- let curve = length(fwidth(in.world_normal)) / max(length(fwidth(in.world_position.xyz)), 1e-5);
- let edge = smoothstep(25.0, 90.0, curve) + 0.5 * smoothstep(0.12, 0.35, 1.0 - max(abs(n.x), max(abs(n.y), abs(n.z))));
- let a = wear.amount;
-
- var c = pbr_input.material.base_color.rgb;
- var rough = pbr_input.material.perceptual_roughness;
- var metal = pbr_input.material.metallic;
-
- // paint: mottled a little, and duller where it's thin
- let mottle = fbm(q * 0.6);
- c *= 1.0 + (mottle - 0.5) * 0.22 * a;
- rough = clamp(rough + (fbm(q * 1.7 + 5.0) - 0.5) * 0.3 * a, 0.04, 1.0);
-
- // grime: low, in hollows and undersides, broken up
- let low = clamp(-n.y, 0.0, 1.0) * 0.6 + smoothstep(0.55, 0.85, fbm(q * 0.35 + 20.0));
- let g = clamp(low * wear.grimes * a, 0.0, 0.85) * smoothstep(0.3, 0.7, fbm(q * 2.3 + 40.0) + 0.25);
- c = mix(c, wear.grime.rgb, g);
- rough = mix(rough, 0.9, g);
-
- // rust: streaks run down from blotches (noise squashed along local y)
- let streak = fbm(vec3(q.x * 3.0, q.y * 0.25, q.z * 3.0) + 60.0);
- let blotch = smoothstep(0.6, 0.8, fbm(q * 0.5 + 80.0));
- let r = clamp((blotch + smoothstep(0.62, 0.8, streak) * 0.6) * wear.rusts * a, 0.0, 0.9);
- c = mix(c, wear.rust.rgb * (0.7 + 0.6 * vnoise(q * 6.0)), r);
- rough = mix(rough, 0.95, r);
- metal = mix(metal, 0.0, r);
-
- // chips: the paint gone at edges and a few scattered spots, the metal under it showing, shinier
- // an edge lowers the bar a long way, so at full wear most edges chip and only the odd spot on a broad face does
- let s = wear.chips * a;
- let field = fbm(q * 2.5 + 100.0) + edge * 0.5 - 0.2;
- let chip = smoothstep(1.0 - s * 0.55, 1.04 - s * 0.55, field);
- c = mix(c, wear.chip.rgb, chip);
- rough = mix(rough, 0.32, chip);
- metal = mix(metal, 0.85, chip);
-
- pbr_input.material.base_color = vec4(c, pbr_input.material.base_color.a);
- pbr_input.material.perceptual_roughness = rough;
- pbr_input.material.metallic = metal;
- pbr_input.material.base_color = alpha_discard(pbr_input.material.flags, pbr_input.material.alpha_cutoff, pbr_input.material.base_color);
-
-@if(PREPASS_PIPELINE) {
- return deferred_output(in, pbr_input);
-} @else {
- var out: FragmentOutput;
- out.color = apply_pbr_lighting(pbr_input);
- out.color = main_pass_post_lighting_processing(pbr_input, out.color);
- return out;
-}
-}
diff --git a/tools/layers.toml b/tools/layers.toml
index 83145beb..d6cb16eb 100644
--- a/tools/layers.toml
+++ b/tools/layers.toml
@@ -98,7 +98,6 @@ raea-sys-measure = "systems"
raea-sys-canvas = "systems"
raea-sys-tweak = "systems"
raea-sys-filters = "systems"
-raea-sys-wear = "systems"
raea-sys-weathering = "systems"
raea-sys-runoff = "systems"
raea-sys-touch = "systems"
@@ -275,7 +274,6 @@ raea-sys-fingerprint = true
raea-sys-fingerprint-use = true
raea-sys-song = true
raea-sys-k = true
-raea-sys-wear = true
raea-sys-procmat = true
# trees grown by species as meshes: crowns, leaves, bark and roots (the city's tree LODs build on them)
raea-sys-foliage = true
diff --git a/tools/sdk-coverage.min b/tools/sdk-coverage.min
index 1fa85e6c..78c91685 100644
--- a/tools/sdk-coverage.min
+++ b/tools/sdk-coverage.min
@@ -1 +1 @@
-1557
+1556
diff --git a/tools/taxonomy.list b/tools/taxonomy.list
index 5df465b6..a579540f 100644
--- a/tools/taxonomy.list
+++ b/tools/taxonomy.list
@@ -56,7 +56,7 @@ raea Compute a compute shader run once a frame before the cameras draw (
raea ShaderExtension raea's MaterialExtension running a surface shader (ExtendedMaterial's extension)
raea GridExtension raea's MaterialExtension drawing a grid (ExtendedMaterial's extension)
raea PaintExtension raea's MaterialExtension for the paint look (ExtendedMaterial's extension)
-raea WearExtension raea's MaterialExtension that chips, grimes and rusts a StandardMaterial in the part's own space (systems/wear); Bevy has none
+raea WearExtension raea's surface shader that chips, grimes and rusts a StandardMaterial in the part's own space (sdk/render worn.ts, on the ShaderExtension hook); Bevy has none
raea ProceduralExtension raea's MaterialExtension that draws wood, stone, brick, tiles and the rest on a StandardMaterial with dust, dirt and worn edges (systems/procmat); Bevy has none
raea ToonExtension raea's MaterialExtension for toon bands (ExtendedMaterial's extension)
raea ToonMaterial StandardMaterial with ToonExtension (S2a's table: raea's)