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
The paint look takes soft (its light as a gradient instead of flat bands), cuts (up to four balls, each a world: a mesh is drawn only in its own, cut per pixel in the main pass and the prepass, with nine styles for what is inside) and a rim and a terminator colour. All default off: at the defaults every shader branch is the code before it. Its docs, tests and the skills reference are still to come
shinyobjectz30c26b919c7e
diff --git a/runtime/look/src/cuts.rs b/runtime/look/src/cuts.rsnew file mode 100644index 00000000..877b955a--- /dev/null+++ b/runtime/look/src/cuts.rs@@ -0,0 +1,53 @@+//! The paint look's worlds on the camera row (a <Look cuts>): split from lib.rs, which is at its 500-line limit.+use super::*;++/// The paint look's worlds (a <Look cuts>: raea-render's paint.rs, paint_world.wesl): each of up to four cuts' centre,+/// radius, style, scale and amount on the camera row, one value a frame. No columns while no look has cuts.+pub fn paint_cut_rows(looks: &[Option<&Map<String, Value>>], p: &mut Program, row: &mut BTreeMap<String, V>, first: &Map<String, Value>) {+ if !looks.iter().flatten().any(|l| l.get("cuts").is_some_and(Value::is_array)) {+ return;+ }+ for i in 0..4 {+ for (k, or) in [("x", 0.0), ("y", 0.0), ("z", 0.0), ("r", 0.0), ("style", 0.0), ("scale", 0.1), ("amount", 1.0)] {+ let vals: Vec<f64> = looks+ .iter()+ .map(|l| {+ let l = l.filter(|l| is_paint(l)).unwrap_or(first);+ l.get("cuts").and_then(Value::as_array).and_then(|a| a.get(i)).and_then(Value::as_object).and_then(|c| num(c, k)).unwrap_or(or)+ })+ .collect();+ column(p, row, "cam", &format!("paint_cut{i}_{k}"), &vals);+ }+ }+}++/// Each cut's two colours, fixed for a look (paint_cut_rows has its keyed values).+pub fn cut_colours(row: &mut BTreeMap<String, V>, first: &Map<String, Value>) {+ if let Some(Value::Array(cuts)) = first.get("cuts") {+ for (i, c) in cuts.iter().take(4).enumerate() {+ for k in ["a", "b"] {+ if let Some(h) = hex(c.get(k)) {+ row.insert(format!("paint_cut{i}_{k}"), V::S(h));+ }+ }+ }+ }+}++/// a material's `paint` (under a paint look): its breakup, patches of noise in their own colour (raea-render's paint.rs)+pub fn paint_columns(row: &mut BTreeMap<String, V>, props: &Map<String, Value>) {+ let Some(g) = props.get("paint").and_then(Value::as_object) else { return };+ // its world (a <Look cuts>): alone, it leaves the breakup off+ if let Some(w) = num(g, "world") {+ row.insert("paint_world".into(), V::N(w));+ if g.keys().all(|k| k == "world") {+ return;+ }+ }+ row.insert("paint_breakup".into(), V::N(n(g, "breakup", 0.5)));+ row.insert("paint_breakup_scale".into(), V::N(n(g, "scale", 1.0)));+ if let Some(h) = hex(g.get("color")) {+ row.insert("paint_patch".into(), V::S(h));+ row.insert("paint_patch_amount".into(), V::N(n(g, "amount", 0.6)));+ }+}diff --git a/runtime/look/src/lib.rs b/runtime/look/src/lib.rsindex b7af2f32..a74ce2c3 100644--- a/runtime/look/src/lib.rs+++ b/runtime/look/src/lib.rs@@ -8,6 +8,8 @@ use raea_core_scene::*;use serde_json::{Map, Value};mod camera;+mod cuts;+pub use cuts::*;pub use camera::*;mod instances;mod post;@@ -205,16 +207,17 @@ pub fn is_paint(l: &Map<String, Value>) -> bool {pub fn paint_fixed(row: &mut BTreeMap<String, V>, first: &Map<String, Value>) {row.insert("paint_rag_scale".into(), V::N(n(first, "ragScale", 24.0)));// ambient occlusion and ground bounce as a band, the water's foam, the shadows' torn edge (paint.rs)- for (k, col) in [("aoHeight", "paint_ao_height"), ("ground", "paint_ground"), ("ssao", "paint_ssao"), ("water", "paint_water"), ("foam", "paint_foam"), ("edge", "paint_edge"), ("edgeScale", "paint_edge_scale"), ("wash", "paint_wash"), ("washSize", "paint_wash_size"), ("stroke", "paint_stroke"), ("strokeScale", "paint_stroke_scale"), ("saturate", "paint_saturate"), ("foliage", "paint_foliage"), ("foliageHeight", "paint_foliage_height"), ("calmFrom", "paint_calm_from"), ("calmTo", "paint_calm_to"), ("calmAmount", "paint_calm_amount"), ("texel", "paint_texel"), ("texelJitter", "paint_texel_jitter"), ("cloudShadows", "paint_cloud_shadows"), ("cloudShadowSize", "paint_cloud_shadow_size"), ("wind", "paint_wind"), ("windX", "paint_wind_x"), ("windZ", "paint_wind_z"), ("hazeDensity", "paint_haze_density"), ("hazeHeight", "paint_haze_height"), ("hazeStart", "paint_haze_start"), ("hazeMost", "paint_haze_most")] {+ for (k, col) in [("aoHeight", "paint_ao_height"), ("ground", "paint_ground"), ("ssao", "paint_ssao"), ("water", "paint_water"), ("foam", "paint_foam"), ("edge", "paint_edge"), ("edgeScale", "paint_edge_scale"), ("wash", "paint_wash"), ("washSize", "paint_wash_size"), ("stroke", "paint_stroke"), ("strokeScale", "paint_stroke_scale"), ("saturate", "paint_saturate"), ("foliage", "paint_foliage"), ("foliageHeight", "paint_foliage_height"), ("calmFrom", "paint_calm_from"), ("calmTo", "paint_calm_to"), ("calmAmount", "paint_calm_amount"), ("texel", "paint_texel"), ("texelJitter", "paint_texel_jitter"), ("cloudShadows", "paint_cloud_shadows"), ("cloudShadowSize", "paint_cloud_shadow_size"), ("soft", "paint_soft"), ("cutRag", "paint_cut_rag"), ("cutRim", "paint_cut_rim_width"), ("rimAmount", "paint_rim_amount"), ("rimPower", "paint_rim_power"), ("terminatorAmount", "paint_term_amount"), ("wind", "paint_wind"), ("windX", "paint_wind_x"), ("windZ", "paint_wind_z"), ("hazeDensity", "paint_haze_density"), ("hazeHeight", "paint_haze_height"), ("hazeStart", "paint_haze_start"), ("hazeMost", "paint_haze_most")] {if let Some(v) = num(first, k) {row.insert(col.into(), V::N(v));}}- for (k, col) in [("shadow", "paint_shadow"), ("mid", "paint_mid"), ("ao", "paint_ao"), ("foamColor", "paint_foam_color"), ("calm", "paint_calm"), ("haze", "paint_haze"), ("hazeSun", "paint_haze_sun")] {+ for (k, col) in [("shadow", "paint_shadow"), ("mid", "paint_mid"), ("ao", "paint_ao"), ("foamColor", "paint_foam_color"), ("calm", "paint_calm"), ("haze", "paint_haze"), ("hazeSun", "paint_haze_sun"), ("cutRimColor", "paint_cut_rim"), ("rim", "paint_rim"), ("terminator", "paint_term")] {if let Some(h) = hex(first.get(k)) {row.insert(col.into(), V::S(h));}}+ cut_colours(row, first);// the sky: one colour, or [top, bottom]match first.get("sky") {Some(Value::Array(a)) => {@@ -301,6 +304,7 @@ pub fn frame_looks(all: &[Vec<Item>], p: &mut Program, row: &mut BTreeMap<Stringlet lines: Vec<Option<&Map<String, Value>>> = all.iter().map(|its| its.iter().find(|i| i.kind == "outline").map(|i| &*i.props)).collect();if let Some(first) = looks.iter().flatten().find(|l| is_paint(l)) {paint_keyed_rows(&looks, p, row, first);+ paint_cut_rows(&looks, p, row, first);}let mut kinds: Vec<BTreeMap<String, V>> = Vec::new();let idx: Vec<f64> = looks@@ -341,17 +345,6 @@ pub fn frame_looks(all: &[Vec<Item>], p: &mut Program, row: &mut BTreeMap<String}}-/// a material's `paint` (under a paint look): its breakup, patches of noise in their own colour (raea-render's paint.rs)-pub fn paint_columns(row: &mut BTreeMap<String, V>, props: &Map<String, Value>) {- let Some(g) = props.get("paint").and_then(Value::as_object) else { return };- row.insert("paint_breakup".into(), V::N(n(g, "breakup", 0.5)));- row.insert("paint_breakup_scale".into(), V::N(n(g, "scale", 1.0)));- if let Some(h) = hex(g.get("color")) {- row.insert("paint_patch".into(), V::S(h));- row.insert("paint_patch_amount".into(), V::N(n(g, "amount", 0.6)));- }-}-pub fn grid_columns(row: &mut BTreeMap<String, V>, props: &Map<String, Value>) {let Some(g) = props.get("grid").and_then(Value::as_object) else { return };let Some(cell) = g.get("cell").and_then(Value::as_f64).filter(|c| *c > 0.0) else { return };diff --git a/runtime/scene/src/live.rs b/runtime/scene/src/live.rsindex b595b675..ddae6c36 100644--- a/runtime/scene/src/live.rs+++ b/runtime/scene/src/live.rs@@ -77,6 +77,8 @@ pub fn cam_keyed(k: &str) -> bool {["lens_", "mb_", "up_", "view_"].iter().any(|p| k.starts_with(p))|| ["_qx", "_qy", "_qz", "_qw"].iter().any(|q| k.ends_with(q))|| matches!(k, "x" | "y" | "z" | "look_x" | "look_y" | "look_z" | "fov" | "focus" | "ortho" | "ambient" | "skybox_k" | "env_srcs" | "env_i" | "env_k" | "env_rot" | "sky_k" | "aberration" | "dof_aperture" | "paint_bands" | "paint_grain" | "paint_rag" | "paint_seed")+ // the paint look's worlds: each cut's centre, radius and style move frame by frame (raea-runtime-look paint_cut_rows)+ || k.starts_with("paint_cut")}impl LiveScene {diff --git a/sdk/render/src/3d/look.tsx b/sdk/render/src/3d/look.tsxindex 3119735d..719ff48b 100644--- a/sdk/render/src/3d/look.tsx+++ b/sdk/render/src/3d/look.tsx@@ -34,6 +34,32 @@ export interface LookProps {/** paint, cartoon: how many flat tones the suns' light makes on a surface, 1-8 (3 for paint: shadow, mid and lit;* 2 for cartoon: shade and fill); keyed per frame */bands?: number;+ /** paint, cartoon: the light as a gradient instead of flat bands, 0 (bands, the default) to 1: the form shadow+ * turns into the light over this much of the turn, a cast shadow keeps its filtered edge, the AO fades in, and a+ * `paint` light falls off from its centre (half at its band's edge) instead of stopping at a line. The colours+ * stay the look's own (`shadow`, `mid`), and so do the outline, grain and flat sky */+ soft?: number;+ /** paint, cartoon: worlds. Up to four cuts, each a ball in the scene (`at`, `r` metres). A point is in the last cut+ * that holds it; a mesh is drawn only in its own world (a PaintExtension's `world`: 0, outside every cut, by+ * default; n, inside cut n; -1, everywhere), cut pixel by pixel in depth, so a room and what replaces it meet along+ * the ball's surface. `style` redraws everything inside a cut: "pixel" (cells `scale` metres across), "ink" (ink+ * `a` on paper `b`, hatched `scale` pixels apart), "blueprint" and "neon" (ground `a`, lines `b` ruled every `scale`+ * metres), "halftone" (dots `scale` pixels apart), "thermal" (`a` to `b` to white by tone), "poster" (three flat+ * tones of `a` and `b`), "wash" (watercolour let down to paper `b`) or "mono" (`a` to `b` by tone); `amount` 0-1 of+ * it. Keyed per frame (the colours are the first frame's) */+ cuts?: LookCut[];+ /** worlds: how far the cuts' edges tear (m; 0 a clean ball), and a lit rim just inside them (its width in m, its+ * colour) */+ cutRag?: number;+ cutRim?: number;+ cutRimColor?: string;+ /** paint, cartoon: a rim of light on what turns from the eye (its colour, how much, how tight: 3), fuller on the+ * lit side; and with `soft`, a colour the tone takes where it turns out of the light (`terminator`, how much) */+ rim?: string;+ rimAmount?: number;+ rimPower?: number;+ terminator?: string;+ terminatorAmount?: number;/** paint, cartoon: the darkest tone (turned from the sun, or in a cast shadow), as a colour the surface's own is* multiplied by (a cool grey-blue by default; a warm blush for a cartoon) */shadow?: string;@@ -182,6 +208,21 @@ export function checkShares(owner: string, skip: unknown, passes: unknown, setti}}+const CUT_STYLES = ["pixel", "ink", "blueprint", "halftone", "neon", "thermal", "poster", "wash", "mono"] as const;+/** One world of a paint look (<Look cuts>): a ball, and how everything inside it is drawn. */+export interface LookCut {+ at: [number, number, number];+ /** metres; 0: closed */+ r: number;+ style?: (typeof CUT_STYLES)[number];+ /** the style's size: metres for pixel, blueprint, neon and wash; pixels for ink and halftone (0.1) */+ scale?: number;+ /** how much of the style, 0-1 (1) */+ amount?: number;+ /** the style's two colours */+ a?: string;+ b?: string;+}const PAINT = { bands: 3, grain: 0.3, rag: 2, boil: 0 };const CARTOON = { bands: 2, grain: 0.06, rag: 1.5, boil: 2, shadow: "#f2c7b8" };@@ -212,10 +253,16 @@ function paintLook(props: LookProps, frame: number, fps: number) {const d: Record<string, unknown> = cartoon ? CARTOON : PAINT;const p = { ...d, ...props } as LookProps & typeof PAINT;if (!(Number.isInteger(p.bands) && p.bands >= 1 && p.bands <= 8)) throw new RangeError(`Look: bands must be a whole number from 1 to 8, got ${p.bands}`);- for (const k of ["grain", "rag", "ragScale", "seed", "boil", "outlineWidth", "aoHeight", "ssao", "foam", "edge", "edgeScale", "wash", "washSize", "stroke", "strokeScale", "saturate", "foliage", "foliageHeight", "calmFrom", "calmTo", "calmAmount", "texel", "texelJitter", "cloudShadows", "cloudShadowSize", "wind", "windTime", "hazeDensity", "hazeHeight", "hazeStart", "hazeMost"] as const) {+ for (const k of ["grain", "rag", "ragScale", "seed", "boil", "outlineWidth", "aoHeight", "ssao", "foam", "edge", "edgeScale", "wash", "washSize", "stroke", "strokeScale", "saturate", "foliage", "foliageHeight", "calmFrom", "calmTo", "calmAmount", "texel", "texelJitter", "cloudShadows", "cloudShadowSize", "wind", "windTime", "hazeDensity", "hazeHeight", "hazeStart", "hazeMost", "soft", "cutRag", "cutRim", "rimAmount", "rimPower", "terminatorAmount"] as const) {const v = p[k];if (v !== undefined && !(typeof v === "number" && Number.isFinite(v) && v >= 0)) throw new RangeError(`Look: ${k} must be a number 0 or more, got ${JSON.stringify(v)}`);}+ if (p.cuts !== undefined && !(Array.isArray(p.cuts) && p.cuts.length <= 4)) throw new RangeError(`Look: cuts is up to 4 cuts, got ${JSON.stringify(p.cuts)}`);+ for (const c of p.cuts ?? []) {+ if (!(Array.isArray(c.at) && c.at.length === 3 && c.at.every(Number.isFinite) && Number.isFinite(c.r) && c.r >= 0)) throw new RangeError(`Look: a cut is { at: [x, y, z], r } with r 0 or more, got ${JSON.stringify(c)}`);+ if (c.style !== undefined && !CUT_STYLES.includes(c.style)) throw new RangeError(`Look: a cut's style is one of ${CUT_STYLES.join(", ")}, got ${JSON.stringify(c.style)}`);+ }+ if (p.soft !== undefined && p.soft > 1) throw new RangeError(`Look: soft must be from 0 to 1, got ${p.soft}`);if (p.grain !== undefined && p.grain > 1) throw new RangeError(`Look: grain must be from 0 to 1, got ${p.grain}`);if (p.ragScale !== undefined && p.ragScale < 1) throw new RangeError(`Look: ragScale must be 1 pixel or more, got ${p.ragScale}`);if (p.pixelSize !== undefined && !(p.pixelSize >= 1)) throw new RangeError(`Look: pixelSize must be 1 or more, got ${p.pixelSize}`);@@ -233,7 +280,11 @@ function paintLook(props: LookProps, frame: number, fps: number) {ao: p.ao === undefined ? undefined : toHex("Look", "ao", p.ao),foamColor: p.foamColor === undefined ? undefined : toHex("Look", "foamColor", p.foamColor),calm: p.calm === undefined ? undefined : toHex("Look", "calm", p.calm), haze: p.haze === undefined ? undefined : toHex("Look", "haze", p.haze), hazeDensity: p.hazeDensity, hazeHeight: p.hazeHeight, hazeStart: p.hazeStart, hazeMost: p.hazeMost,- hazeSun: p.hazeSun === undefined ? undefined : toHex("Look", "hazeSun", p.hazeSun), calmFrom: p.calmFrom, calmTo: p.calmTo, calmAmount: p.calmAmount, texel: p.texel, texelJitter: p.texelJitter, cloudShadows: p.cloudShadows, cloudShadowSize: p.cloudShadowSize,+ hazeSun: p.hazeSun === undefined ? undefined : toHex("Look", "hazeSun", p.hazeSun), calmFrom: p.calmFrom, calmTo: p.calmTo, calmAmount: p.calmAmount, texel: p.texel, texelJitter: p.texelJitter, cloudShadows: p.cloudShadows, cloudShadowSize: p.cloudShadowSize, soft: p.soft,+ cuts: p.cuts?.map((c) => ({ x: c.at[0], y: c.at[1], z: c.at[2], r: c.r, style: c.style ? CUT_STYLES.indexOf(c.style) + 1 : 0, scale: c.scale, amount: c.amount, a: c.a === undefined ? undefined : toHex("Look", "cuts.a", c.a), b: c.b === undefined ? undefined : toHex("Look", "cuts.b", c.b) })),+ cutRag: p.cutRag, cutRim: p.cutRim, cutRimColor: p.cutRimColor === undefined ? undefined : toHex("Look", "cutRimColor", p.cutRimColor),+ rim: p.rim === undefined ? undefined : toHex("Look", "rim", p.rim), rimAmount: p.rimAmount, rimPower: p.rimPower,+ terminator: p.terminator === undefined ? undefined : toHex("Look", "terminator", p.terminator), terminatorAmount: p.terminatorAmount,cloudShadowX: p.cloudShadowDrift?.[0], cloudShadowZ: p.cloudShadowDrift?.[1],wind: p.wind, windX: p.windDirection?.[0], windZ: p.windDirection?.[1], windTime: p.windTime ?? (p.wind ? frameTime : undefined),aoHeight: p.aoHeight, ground: p.ground, ssao: p.ssao, water: p.water, foam: p.foam, edge: p.edge, edgeScale: p.edgeScale,diff --git a/sdk/render/src/bevy3d/extensions.tsx b/sdk/render/src/bevy3d/extensions.tsxindex a92a0ce4..4d7b4d07 100644--- a/sdk/render/src/bevy3d/extensions.tsx+++ b/sdk/render/src/bevy3d/extensions.tsx@@ -42,6 +42,9 @@ export interface PaintExtensionProps {color?: string;/** how far toward `color` the patches go (0.6) */amount?: number;+ /** under a <Look cuts>: the world this mesh is in. 0 (the default): outside every cut. 1 to 4: inside that cut and+ * no later one. -1: everywhere. Given alone it leaves the breakup off */+ world?: number;}export function PaintExtension(_: PaintExtensionProps): ReactNode {diff --git a/sdk/render/src/bevy3d/materials.tsx b/sdk/render/src/bevy3d/materials.tsxindex 91413b00..b60872e6 100644--- a/sdk/render/src/bevy3d/materials.tsx+++ b/sdk/render/src/bevy3d/materials.tsx@@ -276,11 +276,13 @@ function maps(p: StandardMaterialProps): { maps: Record<string, string | null>;function standard(p: StandardMaterialProps, ext: Extended) {const color = baseOf(p.base_color).color;- if (p.unlit && (ext.grid || ext.paint || ext.wear || ext.procedural || ext.shader)) throw new TypeError("ExtendedMaterial: an unlit StandardMaterial takes no GridExtension, PaintExtension, WearExtension or ShaderExtension");+ // (a PaintExtension that only names the mesh's world is fine on an unlit one: the cut is the paint shader's, lit or not)+ const worldOnly = ext.paint !== undefined && Object.keys(ext.paint).every((k) => k === "world" || k === "children");+ if (p.unlit && (ext.grid || (ext.paint && !worldOnly) || ext.wear || ext.procedural || ext.shader)) throw new TypeError("ExtendedMaterial: an unlit StandardMaterial takes no GridExtension, PaintExtension, WearExtension or ShaderExtension");if (ext.shader && (ext.grid || ext.paint || ext.wear || ext.procedural)) throw new TypeError("ExtendedMaterial: a ShaderExtension goes alone over its StandardMaterial (no other extension with it)");const m = maps(p);if (p.unlit && p.animate) throw new TypeError("StandardMaterial: an unlit material takes no animate yet");- if (p.unlit) return <MeshBasicMaterial color={color} {...(m.maps.map ? { map: m.maps.map } : {})} {...(m.samplers?.map ? { sampler: m.samplers.map } : {})} {...draw(p)} />;+ if (p.unlit) return <MeshBasicMaterial color={color} {...(m.maps.map ? { map: m.maps.map } : {})} {...(m.samplers?.map ? { sampler: m.samplers.map } : {})} {...draw(p)} {...(p.fog_enabled !== undefined ? { fog: p.fog_enabled } : {})} {...(ext.paint ? { paint: ext.paint } : {})} />;// inside a Model only the fields given re-cover its material; on a Mesh3d the rest are Bevy's defaultsconst own = useContext(InModel);const anim = animateOf("StandardMaterial", p.animate, STANDARD_ANIMATE, STANDARD_FIELDS);diff --git a/systems/look/src/paint.rs b/systems/look/src/paint.rsindex 328e423e..4bf9f71d 100644--- a/systems/look/src/paint.rs+++ b/systems/look/src/paint.rs@@ -23,7 +23,9 @@ pub type PaintMaterial = ExtendedMaterial<StandardMaterial, Paint>;pub fn install(app: &mut App) {bevy::asset::embedded_asset!(app, "paint.wesl");bevy::asset::embedded_asset!(app, "paint_vertex.wesl");+ bevy::asset::embedded_asset!(app, "paint_prepass.wesl");bevy::shader::load_shader_library!(app, "paint_lights.wesl");+ bevy::shader::load_shader_library!(app, "paint_world.wesl");app.add_plugins(MaterialPlugin::<PaintMaterial>::default());}@@ -93,7 +95,8 @@ pub struct PaintParams {calm: Vec4,/// texel (m; 0: none), each cell's shade jitter, cloud shadows' drift (x, z: m)k5: Vec4,- /// cloud shadows' cover (0: none), their size (m), this material sways (1: cut-out, set per mesh), -+ /// cloud shadows' cover (0: none), their size (m), this material sways (1: cut-out, set per mesh), soft (0: flat+ /// bands; above it the light as a gradient that wide)k6: Vec4,/// wind: a blade's tip's bend (m; 0: none), its direction (x, z), the time it has blown (s)k7: Vec4,@@ -102,6 +105,21 @@ pub struct PaintParams {/// the haze's colour (a: on), and its colour toward the sun (a: on)haze: Vec4,haze_sun: Vec4,+ /// worlds (paint_world.wesl): up to four cuts, each a ball (its centre, its radius in m; 0: off)+ cut: [Vec4; 4],+ /// inside each cut: its style (0: the look's own), the style's scale, how much of it, -; and its two colours+ style: [Vec4; 4],+ style_a: [Vec4; 4],+ style_b: [Vec4; 4],+ /// this mesh's world (0: outside every cut; 1 to 4: inside that cut alone; -1: everywhere; set per mesh), the+ /// cuts' torn edge (m), their lit rim's width (m), -+ kw: Vec4,+ /// the cuts' rim colour (a: on)+ cut_rim: Vec4,+ /// the eye-side rim's amount and power, the terminator's amount, -+ k9: Vec4,+ rim: Vec4,+ term: Vec4,}impl MaterialExtension for Paint {@@ -116,6 +134,10 @@ impl MaterialExtension for Paint {fn prepass_vertex_shader() -> ShaderRef {"embedded://raea_sys_look/paint_vertex.wesl".into()}+ // the worlds' cut in the prepass too (Bevy's own prepass fragment otherwise)+ fn prepass_fragment_shader() -> ShaderRef {+ "embedded://raea_sys_look/paint_prepass.wesl".into()+ }}/// a mesh's paint with its material's own part: whether it sways in the wind (a cut-out: masked, blended or to@@ -174,7 +196,18 @@ fn params(v: &BTreeMap<String, V>) -> PaintParams {haze.w = on("paint_haze");let mut haze_sun = lin(v.get("paint_haze_sun"), [1.0, 0.9, 0.75, 1.0]);haze_sun.w = on("paint_haze_sun");+ let mut cut_rim = lin(v.get("paint_cut_rim"), [1.0, 1.0, 1.0, 1.0]);+ cut_rim.w = on("paint_cut_rim_width");PaintParams {+ cut: std::array::from_fn(|i| Vec4::new(num(v, &format!("paint_cut{i}_x"), 0.0), num(v, &format!("paint_cut{i}_y"), 0.0), num(v, &format!("paint_cut{i}_z"), 0.0), num(v, &format!("paint_cut{i}_r"), 0.0).max(0.0))),+ style: std::array::from_fn(|i| Vec4::new(num(v, &format!("paint_cut{i}_style"), 0.0), num(v, &format!("paint_cut{i}_scale"), 0.1).max(1e-4), num(v, &format!("paint_cut{i}_amount"), 1.0).clamp(0.0, 1.0), 0.0)),+ style_a: std::array::from_fn(|i| lin(v.get(&format!("paint_cut{i}_a")), [0.05, 0.05, 0.08, 1.0])),+ style_b: std::array::from_fn(|i| lin(v.get(&format!("paint_cut{i}_b")), [1.0, 1.0, 1.0, 1.0])),+ kw: Vec4::new(0.0, num(v, "paint_cut_rag", 0.0).max(0.0), num(v, "paint_cut_rim_width", 0.0).max(0.0), 0.0),+ cut_rim,+ k9: Vec4::new(num(v, "paint_rim_amount", 0.0).max(0.0), num(v, "paint_rim_power", 3.0).max(0.1), num(v, "paint_term_amount", 0.0).clamp(0.0, 1.0), 0.0),+ rim: lin(v.get("paint_rim"), [1.0, 1.0, 1.0, 1.0]),+ term: lin(v.get("paint_term"), [1.0, 0.8, 0.7, 1.0]),shadow: lin(v.get("paint_shadow"), [0.55, 0.58, 0.68, 1.0]),mid: lin(v.get("paint_mid"), [0.80, 0.76, 0.78, 1.0]),ao,@@ -187,7 +220,7 @@ fn params(v: &BTreeMap<String, V>) -> PaintParams {k4: Vec4::new(num(v, "paint_foliage_height", 0.6), num(v, "paint_calm_from", 8.0), num(v, "paint_calm_to", 40.0).max(num(v, "paint_calm_from", 8.0) + 0.01), num(v, "paint_calm_amount", 0.85).clamp(0.0, 1.0)),calm,k5: Vec4::new(num(v, "paint_texel", 0.0).max(0.0), num(v, "paint_texel_jitter", 0.08).clamp(0.0, 0.5), num(v, "paint_cloud_shadow_x", 0.0), num(v, "paint_cloud_shadow_z", 0.0)),- k6: Vec4::new(num(v, "paint_cloud_shadows", 0.0).clamp(0.0, 1.0), num(v, "paint_cloud_shadow_size", 40.0).max(1.0), 0.0, 0.0),+ k6: Vec4::new(num(v, "paint_cloud_shadows", 0.0).clamp(0.0, 1.0), num(v, "paint_cloud_shadow_size", 40.0).max(1.0), 0.0, num(v, "paint_soft", 0.0).clamp(0.0, 1.0)),k7: Vec4::new(num(v, "paint_wind", 0.0).max(0.0), num(v, "paint_wind_x", 1.0), num(v, "paint_wind_z", 0.0), num(v, "paint_wind_time", 0.0)),k8: Vec4::new(num(v, "paint_haze_density", 0.02).max(0.0), num(v, "paint_haze_height", 3.0).max(0.01), num(v, "paint_haze_start", 8.0).max(0.0), num(v, "paint_haze_most", 0.7).clamp(0.0, 1.0)),haze,@@ -198,6 +231,9 @@ fn params(v: &BTreeMap<String, V>) -> PaintParams {/// one mesh's own paint on top of the camera's: its breakup (paint_breakup, paint_breakup_scale, paint_patch)fn mesh_params(mut p: PaintParams, v: Option<&BTreeMap<String, V>>) -> PaintParams {let Some(v) = v else { return p };+ if v.contains_key("paint_world") {+ p.kw.x = num(v, "paint_world", 0.0);+ }if v.contains_key("paint_breakup") {p.k1.w = num(v, "paint_breakup", 0.0);p.k2.x = num(v, "paint_breakup_scale", 1.0).max(0.001);diff --git a/systems/look/src/paint.wesl b/systems/look/src/paint.weslindex 5dc43c75..0a1e77c8 100644--- a/systems/look/src/paint.wesl+++ b/systems/look/src/paint.wesl@@ -14,6 +14,7 @@ import bevy_pbr::render::mesh_view_types;import bevy_pbr::render::shadows;import bevy_pbr::render::mesh_types::MESH_FLAGS_SHADOW_RECEIVER_BIT;import raea_sys_look::paint_lights::light_bands;+import raea_sys_look::paint_world::{world_at, world_shows};@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};@@ -38,7 +39,8 @@ struct Paint {calm: vec4<f32>,// texel (m: surfaces as pixel art, 0 for none), each cell's shade jitter, cloud shadows' drift (x, z, m)k5: vec4<f32>,- // cloud shadows: cover (0 none to 1), size (m); this material sways in the wind (1: a cut-out leaf or blade), -+ // cloud shadows: cover (0 none to 1), size (m); this material sways in the wind (1: a cut-out leaf or blade); soft+ // (0: the light in flat bands; above it the light as a gradient this wide)k6: vec4<f32>,// wind: how far a blade's tip bends (m, 0 none), its direction (x, z), the time it has blown (s)k7: vec4<f32>,@@ -47,6 +49,21 @@ struct Paint {k8: vec4<f32>,haze: vec4<f32>,haze_sun: vec4<f32>,+ // worlds (paint_world.wesl): up to four cuts, each a ball (its centre, its radius in m; 0: off)+ cut: array<vec4<f32>, 4>,+ // what's inside each cut: its style (0: the look's own), the style's scale, how much of it (0 to 1), -+ style: array<vec4<f32>, 4>,+ style_a: array<vec4<f32>, 4>,+ style_b: array<vec4<f32>, 4>,+ // this mesh's world (0: outside every cut; 1 to 4: inside that cut alone; -1: everywhere), the cuts' torn edge+ // (m), their lit rim's width (m), -+ kw: vec4<f32>,+ // the rim's colour (a: on)+ cut_rim: vec4<f32>,+ // the eye-side rim's amount and power, the terminator's amount, -+ k9: vec4<f32>,+ rim: vec4<f32>,+ term: vec4<f32>,}@group(constants::MATERIAL_BIND_GROUP) @binding(100)@@ -93,8 +110,24 @@ fn fragment(// the centre of its cell in a world grid `texel` across (nudged a quarter cell off the surface first, so a face// lying on a grid plane doesn't flicker between cells), and everything the shading reads from the point (the// texture, the shadow, strokes, grades) is read there: each cell one colour, the frame still full resolution- let texel = paint.k5.x;+ var texel = paint.k5.x;let fine = pbr_input.world_position.xyz;+ // the world the point is in (a <Look cuts>: paint_world.wesl), and that world's style and two colours+ let world = world_at(fine, paint.cut[0], paint.cut[1], paint.cut[2], paint.cut[3], paint.kw.y);+ var wstyle = vec4<f32>(0.0);+ var wa = vec3<f32>(0.0);+ var wb = vec3<f32>(1.0);+ if world.x > 0.5 {+ let wi = u32(world.x) - 1u;+ wstyle = paint.style[wi];+ wa = paint.style_a[wi].rgb;+ wb = paint.style_b[wi].rgb;+ // pixels: the world's surfaces in cells of its own size (not a mesh that is in every world: the cast keeps+ // its own detail, and takes the world's short ramp of colour)+ if wstyle.x > 0.5 && wstyle.x < 1.5 && paint.kw.x > -0.5 {+ texel = wstyle.y;+ }+ }var wp = fine;if texel > 0.0 {wp = (floor((fine + pbr_input.world_normal * texel * 0.25) / texel) + 0.5) * texel;@@ -113,6 +146,10 @@ fn fragment(ux = dpdx(uv0);uy = dpdy(uv0);}+ // a mesh of another world isn't here+ if !world_shows(world.x, paint.kw.x) {+ discard;+ }// unlit (a MeshBasicMaterial, `unlit`): its own colour, as drawnif (pbr_input.material.flags & STANDARD_MATERIAL_FLAGS_UNLIT_BIT) != 0u {out.color = main_pass_post_lighting_processing(pbr_input, vec4<f32>(c.rgb + pbr_input.material.emissive.rgb * view_bindings::view.exposure, c.a));@@ -200,9 +237,20 @@ fn fragment(// how square the surface faces the suns (`ndl`), and whether a sun that it faces reaches it (`lit`)var ndl = 0.0;var lit = false;+ // soft: how far the surface is turned to a sun (`face`, 0 to 1 over `soft` of the turn) and how much of that+ // light arrives past the cast shadows (`reach`), both as gradients+ var soft = paint.k6.w;+ // a world of pixels or of poster tones keeps its light flat+ if (wstyle.x > 0.5 && wstyle.x < 1.5) || (wstyle.x > 6.5 && wstyle.x < 7.5) {+ soft = 0.0;+ }+ var face = 0.0;+ var reach = 0.0;if suns == 0u {ndl = 1.0;lit = true;+ face = 1.0;+ reach = 1.0;}for (var i: u32 = 0u; i < suns; i = i + 1u) {let light = &view_bindings::lights.directional_lights[i];@@ -220,6 +268,16 @@ fn fragment(}s = shadows::fetch_directional_shadow(i, sp, pbr_input.world_normal, view_z, pbr_input.frag_coord.xy);}+ // inside a cut the sun's shadows are the other world's (its walls and furniture still stand in the shadow+ // map): the world is lit by how it faces the sun alone+ if world.x > 0.5 {+ s = 1.0;+ }+ if soft > 0.0 {+ let e = smoothstep(0.0, soft, d);+ face = max(face, e);+ reach = max(reach, e * s);+ }// the shadow's filtered edge cut at half: a shadow is a shape, not a gradientif s >= 0.5 + edge {lit = true;@@ -245,6 +303,20 @@ fn fragment(let j = min(steps, 1.0 + floor(clamp(ndl, 0.0, 1.0) * steps));tint = mix(paint.mid.rgb, vec3<f32>(1.0), j / steps);}+ // soft: the same tones as a gradient, the form shadow turning into the light over `soft` and the cast shadow as+ // soft as its filtered edge+ if soft > 0.0 && n > 1.5 {+ var turned = paint.mid.rgb;+ if n < 2.5 {+ turned = paint.shadow.rgb;+ }+ tint = mix(mix(turned, vec3<f32>(1.0), face), paint.shadow.rgb, clamp(face - reach, 0.0, 1.0));+ // the terminator: where the surface turns out of the light its tone takes a colour of its own (a warm+ // bleed, as light through skin or paint), most at the half turn+ if paint.k9.z > 0.0 {+ tint = mix(tint, tint * paint.term.rgb, 4.0 * face * (1.0 - face) * paint.k9.z);+ }+ }// cloud shadows: big soft-edged shapes of shade drifting over the land, cut hard like the cast shadowsif lit && paint.k6.x > 0.0 {let q = vec2<f32>(wp.x - paint.k5.z, wp.z - paint.k5.w) / max(paint.k6.y, 1.0);@@ -256,7 +328,7 @@ fn fragment(}}// the point and spot lights that ask for paint, in bands of their own colour (paint_lights.wesl)- tint = light_bands(tint, lit, pbr_input.world_position, pbr_input.N, pbr_input.world_normal, pbr_input.frag_coord, view_z, pbr_input.is_orthographic, pbr_input.flags, wobble, edge);+ tint = light_bands(tint, lit, pbr_input.world_position, pbr_input.N, pbr_input.world_normal, pbr_input.frag_coord, view_z, pbr_input.is_orthographic, pbr_input.flags, wobble, edge, soft);let up = abs(pbr_input.N.y);// ambient occlusion as one band: walls near the ground (ao height, ragged) and creases the SSAO findsif paint.ao.w > 0.0 {@@ -266,7 +338,17 @@ fn fragment(if paint.k1.y > 0.0 && pbr_input.diffuse_occlusion.r < paint.k1.y + (n2 - 0.5) * 0.15 {occluded = true;}- if occluded {+ if soft > 0.0 {+ // soft: the band's edges as gradients (up the wall, and over the SSAO's last `soft` before its threshold)+ var o = 0.0;+ if !lit && paint.k0.y > 0.0 && up < 0.7 {+ o = 1.0 - smoothstep(0.0, paint.k0.y * (0.6 + 0.8 * n2), wp.y - paint.k0.z);+ }+ if paint.k1.y > 0.0 {+ o = max(o, 1.0 - smoothstep(paint.k1.y * (1.0 - soft), paint.k1.y + 1e-3, pbr_input.diffuse_occlusion.r));+ }+ tint = mix(tint, tint * paint.ao.rgb, o);+ } else if occluded {tint = tint * paint.ao.rgb;}}@@ -290,6 +372,92 @@ fn fragment(if texel > 0.0 && paint.k5.y > 0.0 {rgb = rgb * (1.0 + (hash3(wp / texel + vec3<f32>(0.37)) - 0.5) * 2.0 * paint.k5.y);}+ let to_eye = normalize(view_bindings::view.world_position.xyz - fine);+ let fres = 1.0 - saturate(dot(pbr_input.N, to_eye));+ // the rim: what turns from the eye takes an edge of light in the look's rim colour, fuller on the lit side+ if paint.k9.x > 0.0 {+ var lightk = reach;+ if soft <= 0.0 {+ lightk = f32(lit);+ }+ rgb = rgb + c.rgb * paint.rim.rgb * pow(fres, paint.k9.y) * paint.k9.x * mix(0.3, 1.0, lightk);+ }+ // the world's style: the lit colour redrawn as that world draws things+ if wstyle.x > 0.5 && wstyle.z > 0.0 {+ let kind = u32(wstyle.x + 0.5);+ let sc = max(wstyle.y, 1e-4);+ let lum = clamp(dot(rgb, vec3<f32>(0.2126, 0.7152, 0.0722)), 0.0, 1.0);+ let fc = pbr_input.frag_coord.xy;+ var styled = rgb;+ if kind == 1u {+ // pixels: each cell's colour from a short ramp+ styled = floor(rgb * 5.0 + vec3<f32>(0.5)) / 5.0;+ } else if kind == 2u {+ // ink: paper and ink, the half tones hatched by lines `scale` pixels apart+ let h1 = fract((fc.x + fc.y) / sc);+ let h2 = fract((fc.x - fc.y) / sc);+ var ink = 0.0;+ if lum < 0.16 || (lum < 0.36 && (h1 < 0.38 || h2 < 0.38)) || (lum < 0.6 && h1 < 0.3) {+ ink = 1.0;+ }+ styled = mix(wb, wa, ink);+ } else if kind == 3u || kind == 5u {+ // blueprint and neon: lines ruled through the world every `scale` metres, and an edge of light+ let g = abs(fract(fine / sc + vec3<f32>(0.5)) - vec3<f32>(0.5)) * sc;+ let lw = max(0.0016 * length(view_bindings::view.world_position.xyz - fine), sc * 0.012);+ let an = abs(pbr_input.world_normal);+ var ruled = 0.0;+ if (an.x < 0.92 && g.x < lw) || (an.y < 0.92 && g.y < lw) || (an.z < 0.92 && g.z < lw) {+ ruled = 1.0;+ }+ if kind == 3u {+ styled = mix(wa * (0.45 + 0.75 * lum), wb, max(ruled, pow(fres, 2.5) * 0.7));+ } else {+ styled = wa * 0.05 + c.rgb * lum * 0.22 + wb * (ruled * 1.6 + pow(fres, 2.0) * 1.8);+ }+ } else if kind == 4u {+ // halftone: flat colour, its shade a screen of dots `scale` pixels apart+ let q = vec2<f32>(0.866 * fc.x - 0.5 * fc.y, 0.5 * fc.x + 0.866 * fc.y) / sc;+ let dd = length(fract(q) - vec2<f32>(0.5));+ let rad = sqrt(1.0 - lum) * 0.66;+ let dots = 1.0 - smoothstep(rad - 0.06, rad + 0.06, dd);+ styled = mix(c.rgb * wb, c.rgb * wa, dots);+ } else if kind == 6u {+ // thermal: the tone as heat+ if lum < 0.5 {+ styled = mix(wa, wb, lum * 2.0);+ } else {+ styled = mix(wb, vec3<f32>(1.0, 0.96, 0.75), lum * 2.0 - 1.0);+ }+ } else if kind == 7u {+ // poster: three flat tones of two colours+ if lum < 0.22 {+ styled = wa;+ } else if lum < 0.55 {+ styled = mix(wa, wb, 0.55);+ } else {+ styled = wb;+ }+ } else if kind == 8u {+ // wash: watercolour, the colour let down toward the paper and pooled by a noise `scale` metres wide+ let pool = fbm3(fine / sc);+ styled = mix(rgb, wb, 0.1 + 0.3 * pow(fres, 2.0)) * (0.84 + 0.32 * pool);+ } else if kind == 9u {+ // mono: one ink's tones on one paper+ styled = mix(wa, wb, smoothstep(0.04, 0.85, lum));+ }+ // (a mesh that is in every world, the cast, takes less than half of a world's style: it has to read in all of them)+ var much = wstyle.z;+ if paint.kw.x < -0.5 {+ much = much * 0.4;+ }+ rgb = mix(rgb, styled, much);+ }+ // a cut's edge, lit: the last `rim width` metres inside it go to the rim's colour+ if paint.cut_rim.w > 0.0 && world.x > 0.5 && world.y < paint.kw.z {+ let k = 1.0 - world.y / paint.kw.z;+ rgb = mix(rgb, paint.cut_rim.rgb * 2.5, k * k);+ }// saturation: painted colour is fuller than photographed colourlet grey = dot(rgb, vec3<f32>(0.2126, 0.7152, 0.0722));rgb = max(vec3<f32>(grey) + (rgb - vec3<f32>(grey)) * paint.k3.z, vec3<f32>(0.0));diff --git a/systems/look/src/paint_lights.wesl b/systems/look/src/paint_lights.weslindex cd6b5dc2..f5418360 100644--- a/systems/look/src/paint_lights.wesl+++ b/systems/look/src/paint_lights.wesl@@ -7,7 +7,9 @@// the surface's own colour, as the sun lights it; a coloured one as bright, its hue; at most 3 a channel). The band// takes the place of a shade (`mid`, `shadow`); on a surface a sun lights it adds only what's above the sun's band. At// `k.z` times the band's lux it steps once more, times `k.w` (brighter with intensity). Lights that didn't ask, and-// every light while none did (`k.x` = 0), change nothing.+// every light while none did (`k.x` = 0), change nothing. With the look's `soft` above 0 a light is a gradient+// instead: each asking light weighs in by its lux over the band's (0 at none, half at the band's lux, all of it at+// 1 + soft times that), times its filtered shadow, and the surface's tint goes that far to the lights' colours.import bevy_pbr::render::mesh_view_bindings as view_bindings;import bevy_pbr::render::mesh_view_types;import bevy_pbr::render::clustered_forward as clustering;@@ -36,10 +38,14 @@ fn asked(p: vec3<f32>) -> bool {}/// the tint a surface's bands give it (`tint`), raised by each asking light that reaches it to that light's band-fn light_bands(tint: vec3<f32>, sunlit: bool, P: vec4<f32>, N: vec3<f32>, world_normal: vec3<f32>, frag_coord: vec4<f32>, view_z: f32, is_orthographic: bool, mesh_flags: u32, wobble: f32, edge: f32) -> vec3<f32> {+fn light_bands(tint: vec3<f32>, sunlit: bool, P: vec4<f32>, N: vec3<f32>, world_normal: vec3<f32>, frag_coord: vec4<f32>, view_z: f32, is_orthographic: bool, mesh_flags: u32, wobble: f32, edge: f32, soft: f32) -> vec3<f32> {if paint_lights.k.x < 0.5 {return tint;}+ // soft: the lights' colours summed by weight, the weights' sum, and how much of the surface no light reaches+ var sum = vec3<f32>(0.0);+ var wsum = 0.0;+ var dark = 1.0;// the brightest band of the lights that reach it (none: -1)var best = vec3<f32>(-1.0);let receives = (mesh_flags & MESH_FLAGS_SHADOW_RECEIVER_BIT) != 0u;@@ -79,6 +85,23 @@ fn light_bands(tint: vec3<f32>, sunlit: bool, P: vec4<f32>, N: vec3<f32>, world_}// the light on it, the band's cut wandering by the edge noiselet lux = cd * window * window / max(d2, 1e-4) * min(facing, 1.0) * cone * (1.0 + 2.0 * edge);+ if soft > 0.0 {+ let a = lux / max(paint_lights.k.y, 1e-6);+ var w = smoothstep(1.0 - soft, 1.0 + soft, a);+ if w > 0.0 && receives && ((*light).flags & mesh_view_types::POINT_LIGHT_FLAGS_SHADOWS_ENABLED_BIT) != 0u {+ if i >= ranges.first_spot_light_index_offset {+ w = w * shadows::fetch_spot_shadow(id, P, world_normal, (*light).shadow_map_near_z, frag_coord.xy);+ } else {+ w = w * shadows::fetch_point_shadow(id, P, world_normal, frag_coord.xy);+ }+ }+ let hot = smoothstep(paint_lights.k.z * (1.0 - 0.7 * soft), paint_lights.k.z * (1.0 + soft), a);+ let b = min(rgb / max(dot(rgb, vec3<f32>(0.2126, 0.7152, 0.0722)), 1e-6), vec3<f32>(3.0)) * mix(1.0, paint_lights.k.w, hot);+ sum = sum + b * w;+ wsum = wsum + w;+ dark = dark * (1.0 - w);+ continue;+ }if lux < paint_lights.k.y {continue;}@@ -100,6 +123,15 @@ fn light_bands(tint: vec3<f32>, sunlit: bool, P: vec4<f32>, N: vec3<f32>, world_}best = max(best, band);}+ if soft > 0.0 {+ if wsum <= 0.0 {+ return tint;+ }+ // in the sun's light a light adds only what's above the sun's; in shade it takes the shade's place+ let b = sum / wsum;+ let sun = saturate(dot(tint, vec3<f32>(0.2126, 0.7152, 0.0722)));+ return mix(tint, mix(b, max(tint, b), sun), 1.0 - dark);+ }if best.x < 0.0 {return tint;}diff --git a/systems/look/src/paint_prepass.wesl b/systems/look/src/paint_prepass.weslnew file mode 100644index 00000000..6a393df8--- /dev/null+++ b/systems/look/src/paint_prepass.wesl@@ -0,0 +1,176 @@+// paint.rs: the paint look's prepass fragment stage (depth, normals, motion vectors; a masked material's shadow+// maps): Bevy 0.20's own (bevy_pbr render/pbr_prepass.wesl, without its meshlet path) with one change: a mesh of+// another world (paint_world.wesl) isn't drawn, as in the main pass, so the outline, the ambient occlusion and+// whatever stands behind it see the cut. The Paint struct is paint.wesl's (keep the three the same).+import bevy_pbr::render::{+ pbr_prepass_functions,+ pbr_bindings,+ pbr_types,+ pbr_functions,+ pbr_functions::SampleBias,+ mesh_bindings::mesh,+ mesh_view_bindings::view,+};+import bevy_pbr::prepass::io as prepass_io;+import bevy_render::bindless::{bindless_samplers_filtering, bindless_textures_2d};+import raea_sys_look::paint_world::{world_at, world_shows};++@if(BINDLESS)+import bevy_pbr::render::pbr_bindings::material_indices;++struct Paint {+ shadow: vec4<f32>,+ mid: vec4<f32>,+ ao: vec4<f32>,+ foam: vec4<f32>,+ patch_: vec4<f32>,+ // bands, ao height, ground y, water y+ k0: vec4<f32>,+ // foam height, ssao threshold, shadow-edge raggedness, breakup amount+ k1: vec4<f32>,+ // breakup scale, edge scale, wash, wash patch size (uv)+ k2: vec4<f32>,+ // stroke amount, stroke length, saturation, foliage+ k3: vec4<f32>,+ // foliage height, calm from, calm to, calm amount+ k4: vec4<f32>,+ calm: vec4<f32>,+ // texel (m: surfaces as pixel art, 0 for none), each cell's shade jitter, cloud shadows' drift (x, z, m)+ k5: vec4<f32>,+ // cloud shadows: cover (0 none to 1), size (m); this material sways in the wind (1: a cut-out leaf or blade), -+ k6: vec4<f32>,+ // wind: how far a blade's tip bends (m, 0 none), its direction (x, z), the time it has blown (s)+ k7: vec4<f32>,+ // haze: how thick (per metre), how fast it thins with height (m), where it starts (m), its most (0 to 1); its+ // colour (a: on), and its colour toward the sun (a: on)+ k8: vec4<f32>,+ haze: vec4<f32>,+ haze_sun: vec4<f32>,+ // worlds (paint_world.wesl): up to four cuts, each a ball (its centre, its radius in m; 0: off)+ cut: array<vec4<f32>, 4>,+ // what's inside each cut: its style (0: the look's own), the style's scale, how much of it (0 to 1), -+ style: array<vec4<f32>, 4>,+ style_a: array<vec4<f32>, 4>,+ style_b: array<vec4<f32>, 4>,+ // this mesh's world (0: outside every cut; 1 to 4: inside that cut alone; -1: everywhere), the cuts' torn edge+ // (m), their lit rim's width (m), -+ kw: vec4<f32>,+ // the rim's colour (a: on)+ cut_rim: vec4<f32>,+ // the eye-side rim's amount and power, the terminator's amount, -+ k9: vec4<f32>,+ rim: vec4<f32>,+ term: vec4<f32>,+}++@group(constants::MATERIAL_BIND_GROUP) @binding(100)+var<uniform> paint: Paint;++fn cut_away(p: vec3<f32>) -> bool {+ let world = world_at(p, paint.cut[0], paint.cut[1], paint.cut[2], paint.cut[3], paint.kw.y);+ return !world_shows(world.x, paint.kw.x);+}++@if(PREPASS_FRAGMENT)+@fragment+fn fragment(+ in: prepass_io::VertexOutput,+ @builtin(front_facing) is_front: bool,+) -> prepass_io::FragmentOutput {+ if cut_away(in.world_position.xyz) {+ discard;+ }+@if(BINDLESS)+ let slot = mesh[in.instance_index].material_and_lightmap_bind_group_slot & 0xffffu;+@if(BINDLESS)+ let flags = pbr_bindings::material_array[material_indices[slot].material].flags;+@if(BINDLESS)+ let uv_transform = pbr_bindings::material_array[material_indices[slot].material].uv_transform;+@if(!BINDLESS)+ let flags = pbr_bindings::material.flags;+@if(!BINDLESS)+ let uv_transform = pbr_bindings::material.uv_transform;++@if(VISIBILITY_RANGE_DITHER)+ pbr_functions::visibility_range_dither(in.position, in.visibility_range_dither);++ pbr_prepass_functions::prepass_sample_color_and_alpha_discard(in);++ var out: prepass_io::FragmentOutput;++@if(UNCLIPPED_DEPTH_ORTHO_EMULATION)+ out.frag_depth = in.unclipped_depth;++@if(NORMAL_PREPASS)+ if (flags & pbr_types::STANDARD_MATERIAL_FLAGS_UNLIT_BIT) == 0u {+ let double_sided = (flags & pbr_types::STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT) != 0u;+ let mesh_flags = mesh[in.instance_index].flags;+ let is_logically_front = pbr_functions::winding_corrected_front_facing(mesh_flags, is_front);++ let world_normal = pbr_functions::prepare_world_normal(+ in.world_normal,+ double_sided,+ is_logically_front,+ );++ var normal = world_normal;++@if(VERTEX_UVS) {+@if(VERTEX_TANGENTS) {+@if(STANDARD_MATERIAL_NORMAL_MAP) {++@if(STANDARD_MATERIAL_NORMAL_MAP_UV_B)+ let uv = (uv_transform * vec3(in.uv_b, 1.0)).xy;+@else+ let uv = (uv_transform * vec3(in.uv, 1.0)).xy;++ var bias: SampleBias;+ bias.mip_bias = view.mip_bias;++@if(BINDLESS)+ let texture = bindless_textures_2d[material_indices[slot].normal_map_texture];+@else+ let texture = pbr_bindings::normal_map_texture;+@if(BINDLESS)+ let sampler_ = bindless_samplers_filtering[material_indices[slot].normal_map_sampler];+@else+ let sampler_ = pbr_bindings::normal_map_sampler;+ let Nt =+ textureSampleBias(+ texture,+ sampler_,+ uv,+ bias.mip_bias,+ ).rgb;+ let TBN = pbr_functions::calculate_tbn_mikktspace(normal, in.world_tangent);++ normal = pbr_functions::apply_normal_mapping(+ flags,+ TBN,+ double_sided,+ is_logically_front,+ Nt,+ );++}+}+}++ out.normal = vec4(normal * 0.5 + vec3(0.5), 1.0);+ } else {+ out.normal = vec4(in.world_normal * 0.5 + vec3(0.5), 1.0);+ }++@if(MOTION_VECTOR_PREPASS)+ out.motion_vector = pbr_prepass_functions::calculate_motion_vector(in.world_position, in.previous_world_position);++ return out;+}+@else+@fragment+fn fragment(in: prepass_io::VertexOutput) {+ if cut_away(in.world_position.xyz) {+ discard;+ }+ pbr_prepass_functions::prepass_sample_color_and_alpha_discard(in);+}diff --git a/systems/look/src/paint_vertex.wesl b/systems/look/src/paint_vertex.weslindex 7c5c64fa..31dc059d 100644--- a/systems/look/src/paint_vertex.wesl+++ b/systems/look/src/paint_vertex.wesl@@ -40,6 +40,21 @@ struct Paint {k8: vec4<f32>,haze: vec4<f32>,haze_sun: vec4<f32>,+ // worlds (paint_world.wesl): up to four cuts, each a ball (its centre, its radius in m; 0: off)+ cut: array<vec4<f32>, 4>,+ // what's inside each cut: its style (0: the look's own), the style's scale, how much of it (0 to 1), -+ style: array<vec4<f32>, 4>,+ style_a: array<vec4<f32>, 4>,+ style_b: array<vec4<f32>, 4>,+ // this mesh's world (0: outside every cut; 1 to 4: inside that cut alone; -1: everywhere), the cuts' torn edge+ // (m), their lit rim's width (m), -+ kw: vec4<f32>,+ // the rim's colour (a: on)+ cut_rim: vec4<f32>,+ // the eye-side rim's amount and power, the terminator's amount, -+ k9: vec4<f32>,+ rim: vec4<f32>,+ term: vec4<f32>,}@group(constants::MATERIAL_BIND_GROUP) @binding(100)diff --git a/systems/look/src/paint_world.wesl b/systems/look/src/paint_world.weslnew file mode 100644index 00000000..e9fafb1f--- /dev/null+++ b/systems/look/src/paint_world.wesl@@ -0,0 +1,63 @@+// paint_world.wesl: the paint look's worlds (a <Look cuts>). A cut is a ball in the world; a point is in the last cut+// that holds it (world 1 to 4), or in none (world 0). A mesh is drawn only where the point is in its own world (a+// PaintExtension's `world`; 0 by default, so the scene outside every cut; -1: everywhere), in the main pass and the+// prepass alike (paint.wesl, paint_prepass.wesl), so one world is cut against the next pixel by pixel, in depth, and+// the outline and the ambient occlusion follow the cut. `rag` (m) tears the cuts' edges by a noise fixed in the world.++fn wh3(p: vec3<f32>) -> f32 {+ var q = bitcast<vec3<u32>>(vec3<i32>(floor(p)));+ q = q * 1664525u + 1013904223u;+ q.x += q.y * q.z;+ q.y += q.z * q.x;+ q.z += q.x * q.y;+ q = q ^ (q >> vec3<u32>(16u));+ return f32(q.x + q.y + q.z) * (1.0 / 4294967295.0);+}++fn wnoise(x: vec3<f32>) -> f32 {+ let i = floor(x);+ let f = fract(x);+ let u = f * f * (3.0 - 2.0 * f);+ let a = mix(mix(wh3(i), wh3(i + vec3(1.0, 0.0, 0.0)), u.x), mix(wh3(i + vec3(0.0, 1.0, 0.0)), wh3(i + vec3(1.0, 1.0, 0.0)), u.x), u.y);+ let b = mix(mix(wh3(i + vec3(0.0, 0.0, 1.0)), wh3(i + vec3(1.0, 0.0, 1.0)), u.x), mix(wh3(i + vec3(0.0, 1.0, 1.0)), wh3(i + vec3(1.0, 1.0, 1.0)), u.x), u.y);+ return mix(a, b, u.z);+}++/// how far inside a cut a point is (m; negative outside), its edge torn by `n` (less while the cut is small)+fn cut_depth(p: vec3<f32>, c: vec4<f32>, n: f32) -> f32 {+ return c.w - length(p - c.xyz) + n * saturate(c.w * 0.5);+}++/// the world a point is in: x the last cut that holds it (1 to 4; 0: none), y how far inside that cut's edge (m)+fn world_at(p: vec3<f32>, c0: vec4<f32>, c1: vec4<f32>, c2: vec4<f32>, c3: vec4<f32>, rag: f32) -> vec2<f32> {+ var w = vec2<f32>(0.0, 0.0);+ if c0.w <= 0.0 && c1.w <= 0.0 && c2.w <= 0.0 && c3.w <= 0.0 {+ return w;+ }+ var n = 0.0;+ if rag > 0.0 {+ n = (wnoise(p * 1.9) * 0.65 + wnoise(p * 5.3 + vec3<f32>(3.7)) * 0.35 - 0.5) * 2.0 * rag;+ }+ var d = cut_depth(p, c0, n);+ if c0.w > 0.0 && d > 0.0 {+ w = vec2<f32>(1.0, d);+ }+ d = cut_depth(p, c1, n);+ if c1.w > 0.0 && d > 0.0 {+ w = vec2<f32>(2.0, d);+ }+ d = cut_depth(p, c2, n);+ if c2.w > 0.0 && d > 0.0 {+ w = vec2<f32>(3.0, d);+ }+ d = cut_depth(p, c3, n);+ if c3.w > 0.0 && d > 0.0 {+ w = vec2<f32>(4.0, d);+ }+ return w;+}++/// whether a mesh of world `mesh` is drawn at a point in world `world`+fn world_shows(world: f32, mesh: f32) -> bool {+ return mesh < -0.5 || abs(world - mesh) < 0.5;+}