Merge remote-tracking branch 'origin/main' into feat/cross-app-materials
No files matched your search
@@ -18,9 +18,10 @@ images, materials, sample graphs, presets, environments) may ever be added.
|
||||
| `assets/app-icon/LICENSE.txt` | App icon licence | MaterialCraft contributors | original | MIT OR Apache-2.0 |
|
||||
| `docs/images/materialcraft-workspace.png` | README screenshot: the workspace with the brick wall sample | MaterialCraft contributors | Offscreen render of MaterialCraft's UI (`crates/ui-egui/tests/snapshot.rs`) | MIT OR Apache-2.0 |
|
||||
| `docs/images/materialcraft-wood.png` | README screenshot: the wood planks template | MaterialCraft contributors | Offscreen render of MaterialCraft's UI | MIT OR Apache-2.0 |
|
||||
| `docs/images/materialcraft-fabric.png` | README screenshot: the woven fabric template | MaterialCraft contributors | Offscreen render of MaterialCraft's UI | MIT OR Apache-2.0 |
|
||||
| `docs/images/materialcraft-lava.png` | README screenshot: the lava rock template | MaterialCraft contributors | Offscreen render of MaterialCraft's UI | MIT OR Apache-2.0 |
|
||||
| `docs/images/materialcraft-ground.png` | README screenshot: the mossy ground template | MaterialCraft contributors | Offscreen render of MaterialCraft's UI | MIT OR Apache-2.0 |
|
||||
| `docs/images/materialcraft-new-graph.png` | README screenshot: the New graph dialog | MaterialCraft contributors | Offscreen render of MaterialCraft's UI | MIT OR Apache-2.0 |
|
||||
| `docs/images/materialcraft-materials.png` | README render: six sample materials on the material ball | MaterialCraft contributors | `materialcraft-cli render --scene material_ball --full`, six renders side by side | MIT OR Apache-2.0 |
|
||||
| `docs/images/materialcraft-materials.png` | README render: eight sample materials on spheres | MaterialCraft contributors | `materialcraft-cli render --scene sphere --full --hq` of the templates, eight renders in a grid | MIT OR Apache-2.0 |
|
||||
| `docs/brand/artcraft-*.svg`, `docs/brand/artcraft-*.png` | ArtCraft logo and mark | ArtCraft Team | storytold/craftrules `assets/brand/` | ArtCraft brand terms, not open source ([`docs/brand/LICENSE-brand.txt`](docs/brand/LICENSE-brand.txt)) |
|
||||
| `crates/nodes/src/text.rs` (`GLYPHS`) | Single-stroke vector font of the Text node (A–Z, a–z, 0–9, punctuation) | MaterialCraft contributors | Original, designed as stroke data in code | MIT OR Apache-2.0 |
|
||||
|
||||
|
||||
@@ -70,18 +70,18 @@
|
||||
<p align="center"><sub><b>Wood planks</b>: anisotropic grain, warped and laid over planks</sub></p>
|
||||
</td>
|
||||
<td width="50%" valign="top">
|
||||
<img src="docs/images/materialcraft-fabric.png" alt="A woven fabric graph: a weave pattern with soft fuzz, as a blue cloth on the rounded cube and in the 2D view" width="100%">
|
||||
<p align="center"><sub><b>Woven fabric</b>: a weave pattern with fuzz and a color ramp</sub></p>
|
||||
<img src="docs/images/materialcraft-lava.png" alt="A lava rock graph: Voronoi plates with cracks and glowing seams, as dark rock with orange emissive cracks on the rounded cube" width="100%">
|
||||
<p align="center"><sub><b>Lava rock</b>: cracked plates over glowing emissive seams</sub></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="50%" valign="top">
|
||||
<img src="docs/images/materialcraft-new-graph.png" alt="The New graph dialog: template spheres for empty, PBR, brick wall, stone tiles, wood planks, rusty metal, woven fabric and stone ground, with the graph name and size" width="100%">
|
||||
<img src="docs/images/materialcraft-new-graph.png" alt="The New graph dialog: template spheres for empty, PBR, brick wall, stone tiles, wood planks, painted metal plates, rusty metal, lava rock, polished marble, wicker weave, woven fabric and mossy ground, with the graph name and size" width="100%">
|
||||
<p align="center"><sub><b>New graph</b>: start from a PBR template or a sample material</sub></p>
|
||||
</td>
|
||||
<td width="50%" valign="top">
|
||||
<img src="docs/images/materialcraft-materials.png" alt="Six material balls rendered by MaterialCraft: red brick, wood planks, rusty metal, stone tiles, blue woven fabric and stone ground" width="100%">
|
||||
<p align="center"><sub><b>Six sample materials</b> on the material ball, rendered by <code>materialcraft-cli render</code></sub></p>
|
||||
<img src="docs/images/materialcraft-ground.png" alt="A mossy ground graph: stones height-blended with dirt and moss grown in the crevices, on the rounded cube and in the 2D view" width="100%">
|
||||
<p align="center"><sub><b>Mossy ground</b>: stones and dirt height-blended, with moss in the gaps</sub></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -90,11 +90,13 @@
|
||||
|
||||
Every material below is a node graph that ships with MaterialCraft as a template, built only from
|
||||
its own procedural nodes (no photos, scans or textures from anywhere else) and rendered by
|
||||
`materialcraft-cli render --scene material_ball --full`.
|
||||
`materialcraft-cli render --scene sphere --full --hq` (the height output displaces the mesh, with
|
||||
ray-traced ambient occlusion and a shadowed key light).
|
||||
|
||||
<p align="center">
|
||||
<img src="docs/images/materialcraft-materials.png" alt="Brick, wood planks, rusty metal, stone tiles, woven fabric and stone ground on material balls" width="100%">
|
||||
<img src="docs/images/materialcraft-materials.png" alt="Eight material spheres: red brick, lava rock with glowing cracks, blue painted metal plates with rivets, wood planks, wicker weave, mossy ground, cracked stone tiles and polished white marble" width="100%">
|
||||
</p>
|
||||
<p align="center"><sub>Brick wall · Lava rock · Painted metal plates · Wood planks<br>Wicker weave · Mossy ground · Stone tiles · Polished marble</sub></p>
|
||||
|
||||
## Why MaterialCraft
|
||||
|
||||
@@ -130,7 +132,7 @@ cargo run --release -p materialcraft -- package.mcraft # open a package
|
||||
cargo run --release -p materialcraft -- --control 7878 # + JSON control channel
|
||||
cargo run --release -p materialcraft-cli -- mcp # MCP server (stdio)
|
||||
cargo run --release -p materialcraft-cli -- new wood wood.mcraft
|
||||
cargo run --release -p materialcraft-cli -- render wood.mcraft wood.png --scene material_ball --full
|
||||
cargo run --release -p materialcraft-cli -- render wood.mcraft wood.png --scene sphere --full --hq
|
||||
cargo run --release -p materialcraft-cli -- export wood.mcraft textures --format png --depth 16
|
||||
cargo run --release -p materialcraft-cli -- export my.mcraft out --set wear=0.7 # with a graph input "wear" set first
|
||||
cargo run --release -p materialcraft-cli -- run my.mcraft file.exportMaterial '{"path": "my.mcmat", "size": 2048}' # for TextureCraft
|
||||
|
||||
@@ -26,7 +26,7 @@ USAGE:
|
||||
Run [{\"id\", \"params\"}, ...] or {\"open\": <input>, \"steps\": [...], \"save\": <out.mcraft>}.
|
||||
materialcraft-cli new <template> <out.mcraft> [--size <px>] [--name <name>]
|
||||
A new package with one graph from a template (empty, pbr, bricks, stone_tiles, wood,
|
||||
rusty_metal, fabric, ground).
|
||||
metal_plates, rusty_metal, lava, marble, wicker, fabric, ground).
|
||||
materialcraft-cli cook <input> [--graph <index>] [--set <input>=<value>]... [--full]
|
||||
Cook a graph and print per-node timings and errors.
|
||||
materialcraft-cli export <input> <dir> [--graph <index>] [--set <input>=<value>]... [--format <ext>]
|
||||
@@ -34,8 +34,10 @@ USAGE:
|
||||
Cook at full size and write every output (png, jpg, tga, tif, bmp, webp, exr, hdr).
|
||||
materialcraft-cli render <input> <out.png> [--size <W>x<H>] [--view 3d|2d] [--scene <id>] [--node <id>]
|
||||
[--yaw <deg>] [--pitch <deg>] [--graph <index>] [--set <input>=<value>]... [--full]
|
||||
[--tiling <n>] [--hq [--displacement <radii>]]
|
||||
Render the material on a 3D scene (rounded_cube, cube, sphere, cylinder, plane, torus,
|
||||
material_ball), or one node's output (--view 2d), to PNG. No GPU needed.
|
||||
material_ball), or one node's output (--view 2d), to PNG. No GPU needed. --hq is a beauty
|
||||
render: real displacement from the height output, ambient occlusion and a key light.
|
||||
materialcraft-cli mcp [--bridge <port>] [--token <token>] [--read-root <dir>] [--write-root <dir>]
|
||||
MCP server on stdio: headless (file access only below the roots), or bridged to
|
||||
`materialcraft --control <port>`.
|
||||
@@ -56,7 +58,7 @@ const SUBCOMMANDS: &[(&str, &[&str], &[&str])] = &[
|
||||
("new", &["--size", "--name"], &[]),
|
||||
("cook", &["--graph", "--set"], &["--full"]),
|
||||
("export", &["--graph", "--set", "--format", "--depth", "--pattern"], &[]),
|
||||
("render", &["--size", "--view", "--scene", "--node", "--yaw", "--pitch", "--graph", "--set"], &["--full"]),
|
||||
("render", &["--size", "--view", "--scene", "--node", "--yaw", "--pitch", "--graph", "--set", "--tiling", "--displacement"], &["--full", "--hq"]),
|
||||
("mcp", &["--bridge", "--token", "--read-root", "--write-root"], &[]),
|
||||
("serve", &["--port", "--read-root", "--write-root"], &[]),
|
||||
];
|
||||
@@ -249,6 +251,9 @@ fn run(cmd: &str, a: &Args) -> Result<(), String> {
|
||||
node: a.num("--node")?,
|
||||
port: None,
|
||||
full: a.has("--full"),
|
||||
tiling: a.num("--tiling")?,
|
||||
hq: a.has("--hq"),
|
||||
displacement: a.num("--displacement")?,
|
||||
};
|
||||
let r = h.render_png(&o).map_err(|e| e.to_string())?;
|
||||
materialcraft_engine::formats::write_atomic(std::path::Path::new(out), &r.png).map_err(|e| e.to_string())?;
|
||||
|
||||
@@ -12,6 +12,8 @@ pub const MAX_PNG_BYTES: usize = 5 << 20;
|
||||
pub const MAX_PNG_SIDE: u32 = 2048;
|
||||
/// Largest render edge for local CLI renders.
|
||||
pub const MAX_LOCAL_RENDER_SIDE: u32 = 4096;
|
||||
/// Triangle budget of an `hq` render's displaced mesh (~100 bytes each with its BVH).
|
||||
pub const HQ_TRIANGLES: usize = 1_200_000;
|
||||
/// Largest reply line read from the app (full-window screenshots are big).
|
||||
pub const MAX_BRIDGE_REPLY_BYTES: usize = 64 << 20;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use materialcraft_engine::{Session, commands, file_cmds, inspect};
|
||||
use materialcraft_render::{Lighting, Maps, Scene, Settings};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::budgets::{MAX_LOCAL_RENDER_SIDE, MAX_PNG_SIDE, check_png, encode_png};
|
||||
use crate::budgets::{HQ_TRIANGLES, MAX_LOCAL_RENDER_SIDE, MAX_PNG_SIDE, check_png, encode_png};
|
||||
use crate::workspace::{MAX_READ_BYTES, authorize_command};
|
||||
use crate::{AuthorizedWorkspace, AutomationError, bad};
|
||||
|
||||
@@ -40,6 +40,13 @@ pub struct RenderOptions {
|
||||
pub port: Option<usize>,
|
||||
/// Cook at full size instead of the preview size.
|
||||
pub full: bool,
|
||||
/// 3D: UV repeats override (the session's view is not changed).
|
||||
pub tiling: Option<f32>,
|
||||
/// 3D: beauty render: the height output displaces a subdivided mesh, with ray-traced
|
||||
/// ambient occlusion, a shadowed key light and 3×3 supersampling. Slower; for stills.
|
||||
pub hq: bool,
|
||||
/// 3D, with `hq`: displacement depth in scene radii (default 0.04).
|
||||
pub displacement: Option<f32>,
|
||||
}
|
||||
|
||||
/// A PNG render.
|
||||
@@ -224,21 +231,35 @@ impl Headless {
|
||||
if self.light.as_ref().is_none_or(|l| l.name != v.environment) {
|
||||
self.light = Some(Lighting::new(&v.environment));
|
||||
}
|
||||
let settings = Settings {
|
||||
let tiling = o.tiling.unwrap_or(v.tiling).clamp(0.1, 64.0);
|
||||
let mut settings = Settings {
|
||||
yaw: o.yaw.unwrap_or(v.yaw),
|
||||
pitch: o.pitch.unwrap_or(v.pitch),
|
||||
distance: v.distance,
|
||||
tiling: v.tiling,
|
||||
tiling,
|
||||
exposure: v.exposure,
|
||||
env_rotation: v.env_rotation,
|
||||
height_scale: v.height_scale,
|
||||
show_env: false,
|
||||
supersample: 2,
|
||||
..Settings::default()
|
||||
};
|
||||
let (w, h) = (o.width.unwrap_or(1024).clamp(16, max), o.height.unwrap_or(768).clamp(16, max));
|
||||
let maps = Maps::from_usages(self.session.material_maps());
|
||||
let (Some((_, scene)), Some(light)) = (&self.scene, &self.light) else { return (w, h, vec![0; (w * h * 4) as usize]) };
|
||||
(w, h, materialcraft_render::render(scene, &maps, light, &settings, w, h))
|
||||
let displaced = match (o.hq, &maps.height) {
|
||||
(true, Some(height)) => {
|
||||
settings.height_scale = 0.0;
|
||||
Some(Scene::displaced(&scene.mesh, height, tiling, o.displacement.unwrap_or(0.04).clamp(0.0, 0.5) * scene.radius, HQ_TRIANGLES))
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
if o.hq {
|
||||
settings.supersample = 3;
|
||||
settings.ao_rays = 8;
|
||||
settings.key_light = 2.5;
|
||||
}
|
||||
(w, h, materialcraft_render::render(displaced.as_ref().unwrap_or(scene), &maps, light, &settings, w, h))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,6 +95,9 @@ impl Headless {
|
||||
node: u32_of(p, "node")?.map(u64::from),
|
||||
port: u32_of(p, "port")?.map(|v| v as usize),
|
||||
full: bool_of(p, "full")?,
|
||||
tiling: f32_of(p, "tiling")?,
|
||||
hq: bool_of(p, "hq")?,
|
||||
displacement: f32_of(p, "displacement")?,
|
||||
};
|
||||
let r = self.render_png(&o)?;
|
||||
Ok(json!({ "width": r.width, "height": r.height, "png": base64::engine::general_purpose::STANDARD.encode(r.png) }))
|
||||
|
||||
@@ -69,7 +69,7 @@ pub struct BatchParams {
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, JsonSchema)]
|
||||
pub struct NewGraphParams {
|
||||
/// Template id: empty, pbr (default: six material outputs), bricks, stone_tiles, wood, rusty_metal, fabric, ground.
|
||||
/// Template id: empty, pbr (default: six material outputs), bricks, stone_tiles, wood, metal_plates, rusty_metal, lava, marble, wicker, fabric, ground.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub template: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
@@ -186,6 +186,16 @@ pub struct RenderParams {
|
||||
/// Cook at the full graph size instead of the preview size.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub full: Option<bool>,
|
||||
/// 3D: UV repeats of the material on the scene for this render only.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub tiling: Option<f32>,
|
||||
/// 3D beauty render: real displacement from the height output, ambient occlusion and a
|
||||
/// shadowed key light (slower).
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub hq: Option<bool>,
|
||||
/// With `hq`: displacement depth in scene radii (default 0.04).
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub displacement: Option<f32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, JsonSchema)]
|
||||
|
||||
@@ -10,9 +10,13 @@ pub const TEMPLATES: &[(&str, &str)] = &[
|
||||
("bricks", "Brick wall"),
|
||||
("stone_tiles", "Stone tiles"),
|
||||
("wood", "Wood planks"),
|
||||
("metal_plates", "Painted metal plates"),
|
||||
("rusty_metal", "Rusty metal"),
|
||||
("lava", "Lava rock"),
|
||||
("marble", "Polished marble"),
|
||||
("wicker", "Wicker weave"),
|
||||
("fabric", "Woven fabric"),
|
||||
("ground", "Stone ground"),
|
||||
("ground", "Mossy ground"),
|
||||
];
|
||||
|
||||
struct B<'g> {
|
||||
@@ -37,7 +41,7 @@ impl B<'_> {
|
||||
// Sample graphs are acyclic by construction; a failure would only drop a wire.
|
||||
let _ = self.g.connect(from, from_port, to, port);
|
||||
}
|
||||
/// The six PBR outputs at `x`, fed by the given nodes.
|
||||
/// The PBR outputs at `x`, fed by the given nodes.
|
||||
fn outputs(&mut self, x: f32, feeds: &[(NodeId, &str, u32, &str)]) {
|
||||
for (i, (from, port, usage, ident)) in feeds.iter().enumerate() {
|
||||
let o = self.n("output", x, i as f32 * 125.0, &[("usage", Value::Enum(*usage)), ("identifier", Value::Text((*ident).into()))]);
|
||||
@@ -91,7 +95,11 @@ pub fn template(id: &str, name: &str, size_log2: u32) -> Graph {
|
||||
"bricks" => bricks(&mut b),
|
||||
"stone_tiles" => stone_tiles(&mut b),
|
||||
"wood" => wood(&mut b),
|
||||
"metal_plates" => metal_plates(&mut b),
|
||||
"rusty_metal" => rusty_metal(&mut b),
|
||||
"lava" => lava(&mut b),
|
||||
"marble" => marble(&mut b),
|
||||
"wicker" => wicker(&mut b),
|
||||
"fabric" => fabric(&mut b),
|
||||
"ground" => ground(&mut b),
|
||||
_ => {}
|
||||
@@ -100,46 +108,53 @@ pub fn template(id: &str, name: &str, size_log2: u32) -> Graph {
|
||||
}
|
||||
|
||||
fn bricks(b: &mut B) {
|
||||
let bricks = b.n(
|
||||
let layout = b.n("brick_generator", 0.0, 0.0, &[("bricks_x", i(4)), ("bricks_y", i(12)), ("gap", f(0.05)), ("bevel", f(0.3)), ("height_random", f(0.12))]);
|
||||
let ids = b.n(
|
||||
"brick_generator",
|
||||
0.0,
|
||||
0.0,
|
||||
&[("bricks_x", i(4)), ("bricks_y", i(10)), ("gap", f(0.06)), ("bevel", f(0.18)), ("height_random", f(0.25)), ("lum_random", f(0.0))],
|
||||
160.0,
|
||||
&[("bricks_x", i(4)), ("bricks_y", i(12)), ("gap", f(0.05)), ("bevel", f(0.0)), ("height_random", f(0.0)), ("lum_random", f(1.0))],
|
||||
);
|
||||
let cells = b.n("cells_1", 0.0, 180.0, &[("scale", f(24.0))]);
|
||||
let grunge = b.n("grunge_map_1", 0.0, 360.0, &[("scale", f(4.0))]);
|
||||
let chip = b.n("blend", 180.0, 90.0, &[("mode", e(3)), ("opacity", f(0.35))]);
|
||||
b.c(cells, chip, "foreground");
|
||||
b.c(bricks, chip, "background");
|
||||
let erode = b.n("slope_blur", 360.0, 90.0, &[("intensity", f(1.2)), ("mode", e(1))]);
|
||||
b.c(chip, erode, "input");
|
||||
b.c(grunge, erode, "slope");
|
||||
let height = b.n("levels", 540.0, 90.0, &[("in_high", f(0.9))]);
|
||||
b.c(erode, height, "input");
|
||||
let normal = b.n("normal", 720.0, 0.0, &[("intensity", f(2.2))]);
|
||||
let pores = b.n("clouds_2", 0.0, 320.0, &[("scale", f(16.0))]);
|
||||
let grunge = b.n("grunge_map_1", 0.0, 480.0, &[("scale", f(4.0))]);
|
||||
let dirt = b.n("clouds_2", 0.0, 640.0, &[("scale", f(24.0))]);
|
||||
let chipped = b.n("edge_damage", 180.0, 0.0, &[("width", f(6.0)), ("amount", f(0.6)), ("scale", f(14.0))]);
|
||||
b.c(layout, chipped, "height");
|
||||
let porous = b.n("blend", 360.0, 0.0, &[("mode", e(3)), ("opacity", f(0.3))]);
|
||||
b.c(pores, porous, "foreground");
|
||||
b.c(chipped, porous, "background");
|
||||
let mortar_h = b.n("levels", 360.0, 160.0, &[("out_low", f(0.08)), ("out_high", f(0.16))]);
|
||||
b.c(dirt, mortar_h, "input");
|
||||
let height = b.n("blend", 540.0, 80.0, &[("mode", e(5))]);
|
||||
b.c(mortar_h, height, "foreground");
|
||||
b.c(porous, height, "background");
|
||||
let normal = b.n("normal", 720.0, 0.0, &[("intensity", f(2.5))]);
|
||||
b.c(height, normal, "input");
|
||||
let ao = b.n("ambient_occlusion", 720.0, 120.0, &[("spread", f(0.05)), ("intensity", f(0.6))]);
|
||||
let ao = b.n("ambient_occlusion", 720.0, 120.0, &[("spread", f(0.05)), ("intensity", f(0.7))]);
|
||||
b.c(height, ao, "height");
|
||||
// Color: per-brick tint from cells, mortar from the height mask.
|
||||
let tint = b.n("cells_3", 360.0, 300.0, &[("scale", f(10.0))]);
|
||||
let mix = b.n("blend", 540.0, 300.0, &[("mode", e(3)), ("opacity", f(0.6))]);
|
||||
b.c(grunge, mix, "foreground");
|
||||
b.c(tint, mix, "background");
|
||||
let brick_col =
|
||||
b.n("gradient_map", 720.0, 300.0, &[("gradient", grad(&[(0.0, [0.18, 0.05, 0.03]), (0.5, [0.42, 0.12, 0.06]), (1.0, [0.62, 0.28, 0.16])]))]);
|
||||
b.c(mix, brick_col, "input");
|
||||
let mortar = b.n("uniform", 720.0, 440.0, &[("color", col(0.42, 0.40, 0.36))]);
|
||||
let mask = b.n("histogram_scan", 720.0, 560.0, &[("position", f(0.92)), ("contrast", f(0.85))]);
|
||||
b.c(height, mask, "input");
|
||||
let base = b.n("blend", 900.0, 360.0, &[("mode", e(0))]);
|
||||
let tone = b.n("blend", 360.0, 320.0, &[("mode", e(9)), ("opacity", f(0.6))]);
|
||||
b.c(grunge, tone, "foreground");
|
||||
b.c(ids, tone, "background");
|
||||
let brick_col = b.n(
|
||||
"gradient_map",
|
||||
540.0,
|
||||
320.0,
|
||||
&[("gradient", grad(&[(0.0, [0.09, 0.022, 0.012]), (0.5, [0.2, 0.05, 0.022]), (0.85, [0.3, 0.09, 0.04]), (1.0, [0.36, 0.15, 0.08])]))],
|
||||
);
|
||||
b.c(tone, brick_col, "input");
|
||||
let mortar_col = b.n("gradient_map", 540.0, 480.0, &[("gradient", grad(&[(0.0, [0.2, 0.19, 0.17]), (1.0, [0.3, 0.28, 0.25])]))]);
|
||||
b.c(dirt, mortar_col, "input");
|
||||
let mask = b.n("histogram_scan", 540.0, 640.0, &[("position", f(0.9)), ("contrast", f(0.9))]);
|
||||
b.c(chipped, mask, "input");
|
||||
let base = b.n("blend", 720.0, 400.0, &[]);
|
||||
b.c(brick_col, base, "foreground");
|
||||
b.c(mortar, base, "background");
|
||||
b.c(mortar_col, base, "background");
|
||||
b.c(mask, base, "mask");
|
||||
let rough = b.n("levels", 900.0, 520.0, &[("out_low", f(0.65)), ("out_high", f(0.95))]);
|
||||
let rough = b.n("levels", 720.0, 560.0, &[("out_low", f(0.7)), ("out_high", f(0.95))]);
|
||||
b.c(grunge, rough, "input");
|
||||
let metal = b.n("uniform", 900.0, 640.0, &[("mode", e(1)), ("color", col(0.0, 0.0, 0.0))]);
|
||||
let metal = b.n("uniform", 720.0, 680.0, &[("mode", e(1)), ("color", col(0.0, 0.0, 0.0))]);
|
||||
b.outputs(
|
||||
1120.0,
|
||||
940.0,
|
||||
&[
|
||||
(base, "output", 0, "basecolor"),
|
||||
(normal, "output", 1, "normal"),
|
||||
@@ -151,85 +166,335 @@ fn bricks(b: &mut B) {
|
||||
);
|
||||
}
|
||||
|
||||
fn stone_tiles(b: &mut B) {
|
||||
let tiles = b.n(
|
||||
"tile_generator",
|
||||
0.0,
|
||||
0.0,
|
||||
&[("pattern", e(7)), ("x_amount", i(6)), ("y_amount", i(6)), ("scale", f(0.95)), ("offset", f(0.5)), ("lum_random", f(0.3))],
|
||||
fn lava(b: &mut B) {
|
||||
let cells = b.n("voronoi", 0.0, 0.0, &[("scale", f(6.0)), ("style", e(2))]);
|
||||
let rock = b.n("clouds_2", 0.0, 160.0, &[("scale", f(12.0)), ("roughness", f(0.6))]);
|
||||
let fine = b.n("cracks", 0.0, 320.0, &[("scale", f(9.0)), ("width", f(1.0))]);
|
||||
let plates = b.n("levels", 180.0, 0.0, &[("in_low", f(0.02)), ("in_high", f(0.3))]);
|
||||
b.c(cells, plates, "input");
|
||||
let rough_h = b.n("blend", 360.0, 0.0, &[("mode", e(3)), ("opacity", f(0.4))]);
|
||||
b.c(rock, rough_h, "foreground");
|
||||
b.c(plates, rough_h, "background");
|
||||
let height = b.n("blend", 540.0, 0.0, &[("mode", e(2)), ("opacity", f(0.25))]);
|
||||
b.c(fine, height, "foreground");
|
||||
b.c(rough_h, height, "background");
|
||||
let normal = b.n("normal", 720.0, 0.0, &[("intensity", f(3.0))]);
|
||||
b.c(height, normal, "input");
|
||||
let ao = b.n("ambient_occlusion", 720.0, 120.0, &[("spread", f(0.06)), ("intensity", f(0.8))]);
|
||||
b.c(height, ao, "height");
|
||||
let seams = b.n("invert", 180.0, 160.0, &[]);
|
||||
b.c(plates, seams, "input");
|
||||
let seam_mask = b.n("levels", 360.0, 160.0, &[("in_low", f(0.6)), ("in_high", f(1.0))]);
|
||||
b.c(seams, seam_mask, "input");
|
||||
let glow = b.n("blur", 540.0, 160.0, &[("intensity", f(0.6))]);
|
||||
b.c(seam_mask, glow, "input");
|
||||
let emissive = b.n(
|
||||
"gradient_map",
|
||||
720.0,
|
||||
240.0,
|
||||
&[("gradient", grad(&[(0.0, [0.0, 0.0, 0.0]), (0.35, [0.35, 0.02, 0.0]), (0.7, [1.0, 0.28, 0.02]), (1.0, [1.0, 0.75, 0.3])]))],
|
||||
);
|
||||
let clouds = b.n("clouds_2", 0.0, 180.0, &[("scale", f(8.0))]);
|
||||
let grunge = b.n("grunge_map_1", 0.0, 360.0, &[("scale", f(5.0))]);
|
||||
let detail = b.n("blend", 200.0, 80.0, &[("mode", e(3)), ("opacity", f(0.35))]);
|
||||
b.c(clouds, detail, "foreground");
|
||||
b.c(tiles, detail, "background");
|
||||
// Chipped edges: blur the tiles down the grunge's slopes.
|
||||
let worn = b.n("slope_blur", 380.0, 80.0, &[("intensity", f(1.0)), ("mode", e(1))]);
|
||||
b.c(detail, worn, "input");
|
||||
b.c(grunge, worn, "slope");
|
||||
let normal = b.n("normal", 560.0, 0.0, &[("intensity", f(1.4))]);
|
||||
b.c(worn, normal, "input");
|
||||
let ao = b.n("ambient_occlusion", 560.0, 120.0, &[("spread", f(0.06)), ("intensity", f(0.5))]);
|
||||
b.c(worn, ao, "height");
|
||||
let stone = b.n("gradient_map", 560.0, 240.0, &[("gradient", grad(&[(0.0, [0.05, 0.045, 0.04]), (0.5, [0.16, 0.14, 0.11]), (1.0, [0.30, 0.27, 0.22])]))]);
|
||||
b.c(worn, stone, "input");
|
||||
let grout = b.n("uniform", 560.0, 360.0, &[("color", col(0.06, 0.055, 0.05))]);
|
||||
let mask = b.n("histogram_scan", 560.0, 480.0, &[("position", f(0.9)), ("contrast", f(0.9))]);
|
||||
b.c(tiles, mask, "input");
|
||||
let base = b.n("blend", 740.0, 300.0, &[]);
|
||||
b.c(stone, base, "foreground");
|
||||
b.c(grout, base, "background");
|
||||
b.c(mask, base, "mask");
|
||||
let rough = b.n("levels", 740.0, 440.0, &[("out_low", f(0.55)), ("out_high", f(0.9))]);
|
||||
b.c(grunge, rough, "input");
|
||||
let metal = b.n("uniform", 740.0, 560.0, &[("mode", e(1)), ("color", col(0.0, 0.0, 0.0))]);
|
||||
b.c(glow, emissive, "input");
|
||||
let base =
|
||||
b.n("gradient_map", 720.0, 360.0, &[("gradient", grad(&[(0.0, [0.006, 0.005, 0.005]), (0.6, [0.018, 0.016, 0.016]), (1.0, [0.04, 0.036, 0.034])]))]);
|
||||
b.c(height, base, "input");
|
||||
let rough = b.n("levels", 720.0, 480.0, &[("out_low", f(0.72)), ("out_high", f(0.95))]);
|
||||
b.c(rock, rough, "input");
|
||||
let metal = b.n("uniform", 720.0, 600.0, &[("mode", e(1)), ("color", col(0.0, 0.0, 0.0))]);
|
||||
b.outputs(
|
||||
960.0,
|
||||
940.0,
|
||||
&[
|
||||
(base, "output", 0, "basecolor"),
|
||||
(normal, "output", 1, "normal"),
|
||||
(rough, "output", 2, "roughness"),
|
||||
(metal, "output", 3, "metallic"),
|
||||
(worn, "output", 4, "height"),
|
||||
(height, "output", 4, "height"),
|
||||
(ao, "output", 5, "ambientocclusion"),
|
||||
(emissive, "output", 6, "emissive"),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
fn metal_plates(b: &mut B) {
|
||||
let plates = b.n("tile_generator", 0.0, 0.0, &[("pattern", e(0)), ("x_amount", i(3)), ("y_amount", i(3)), ("scale", f(0.985))]);
|
||||
let inner = b.n("tile_generator", 0.0, 160.0, &[("pattern", e(0)), ("x_amount", i(3)), ("y_amount", i(3)), ("scale", f(0.88))]);
|
||||
let rivets = b.n("tile_generator", 0.0, 320.0, &[("pattern", e(2)), ("x_amount", i(27)), ("y_amount", i(27)), ("scale", f(0.42))]);
|
||||
let grunge = b.n("grunge_map_1", 0.0, 480.0, &[("scale", f(3.0)), ("contrast", f(0.45))]);
|
||||
let bevelled = b.n("bevel", 180.0, 0.0, &[("distance", f(0.02)), ("smoothing", f(0.5))]);
|
||||
b.c(plates, bevelled, "input");
|
||||
let band = b.n("blend", 180.0, 160.0, &[("mode", e(2))]);
|
||||
b.c(inner, band, "foreground");
|
||||
b.c(plates, band, "background");
|
||||
let rivet_band = b.n("blend", 360.0, 240.0, &[("mode", e(3))]);
|
||||
b.c(rivets, rivet_band, "foreground");
|
||||
b.c(band, rivet_band, "background");
|
||||
let plate_h = b.n("levels", 360.0, 0.0, &[("out_high", f(0.6))]);
|
||||
b.c(bevelled, plate_h, "input");
|
||||
let height = b.n("blend", 540.0, 0.0, &[("mode", e(1)), ("opacity", f(0.4))]);
|
||||
b.c(rivet_band, height, "foreground");
|
||||
b.c(plate_h, height, "background");
|
||||
let normal = b.n("normal", 720.0, 0.0, &[("intensity", f(2.5))]);
|
||||
b.c(height, normal, "input");
|
||||
let ao = b.n("ambient_occlusion", 720.0, 120.0, &[("spread", f(0.04)), ("intensity", f(0.7))]);
|
||||
b.c(height, ao, "height");
|
||||
let worn = b.n("edge_damage", 540.0, 160.0, &[("width", f(5.0)), ("amount", f(0.5)), ("scale", f(16.0))]);
|
||||
b.c(height, worn, "height");
|
||||
let scratches = b.n("scratches_generator", 360.0, 400.0, &[("count", i(70)), ("length", f(0.05)), ("width", f(0.4))]);
|
||||
let scratch_mask = b.n("levels", 540.0, 400.0, &[("in_low", f(0.5)), ("in_high", f(0.9)), ("out_high", f(0.5))]);
|
||||
b.c(scratches, scratch_mask, "input");
|
||||
let wear = b.n("blend", 720.0, 280.0, &[("mode", e(5))]);
|
||||
b.c(scratch_mask, wear, "foreground");
|
||||
b.cp(worn, "mask", wear, "background");
|
||||
let paint = b.n("gradient_map", 540.0, 520.0, &[("gradient", grad(&[(0.0, [0.012, 0.035, 0.08]), (1.0, [0.035, 0.085, 0.17])]))]);
|
||||
b.c(grunge, paint, "input");
|
||||
let steel = b.n("uniform", 540.0, 640.0, &[("color", col(0.56, 0.56, 0.57))]);
|
||||
let base = b.n("blend", 720.0, 480.0, &[]);
|
||||
b.c(steel, base, "foreground");
|
||||
b.c(paint, base, "background");
|
||||
b.c(wear, base, "mask");
|
||||
let rough_paint = b.n("uniform", 540.0, 760.0, &[("mode", e(1)), ("color", col(0.5, 0.5, 0.5))]);
|
||||
let rough_steel = b.n("uniform", 540.0, 880.0, &[("mode", e(1)), ("color", col(0.25, 0.25, 0.25))]);
|
||||
let rough = b.n("blend", 720.0, 640.0, &[]);
|
||||
b.c(rough_steel, rough, "foreground");
|
||||
b.c(rough_paint, rough, "background");
|
||||
b.c(wear, rough, "mask");
|
||||
b.outputs(
|
||||
940.0,
|
||||
&[
|
||||
(base, "output", 0, "basecolor"),
|
||||
(normal, "output", 1, "normal"),
|
||||
(rough, "output", 2, "roughness"),
|
||||
(wear, "output", 3, "metallic"),
|
||||
(height, "output", 4, "height"),
|
||||
(ao, "output", 5, "ambientocclusion"),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
fn wood(b: &mut B) {
|
||||
let grain = b.n("anisotropic_noise", 0.0, 0.0, &[("scale", f(3.0)), ("scale_y", f(96.0)), ("smoothness", f(0.3))]);
|
||||
let planks = b.n(
|
||||
"brick_generator",
|
||||
0.0,
|
||||
180.0,
|
||||
&[("bricks_x", i(1)), ("bricks_y", i(6)), ("offset", f(0.0)), ("gap", f(0.015)), ("bevel", f(0.05)), ("height_random", f(0.1))],
|
||||
0.0,
|
||||
&[("bricks_x", i(2)), ("bricks_y", i(7)), ("offset", f(0.37)), ("gap", f(0.012)), ("bevel", f(0.05)), ("height_random", f(0.06))],
|
||||
);
|
||||
let warp_src = b.n("perlin_noise", 0.0, 360.0, &[("scale", f(4.0))]);
|
||||
let warped = b.n("directional_warp", 200.0, 0.0, &[("intensity", f(6.0)), ("angle", f(0.25))]);
|
||||
let ids = b.n(
|
||||
"brick_generator",
|
||||
0.0,
|
||||
160.0,
|
||||
&[("bricks_x", i(2)), ("bricks_y", i(7)), ("offset", f(0.37)), ("gap", f(0.012)), ("bevel", f(0.0)), ("height_random", f(0.0)), ("lum_random", f(1.0))],
|
||||
);
|
||||
let grain = b.n("anisotropic_noise", 0.0, 320.0, &[("scale", f(3.0)), ("scale_y", f(110.0)), ("smoothness", f(0.25))]);
|
||||
let warp_src = b.n("perlin_noise", 0.0, 480.0, &[("scale", f(5.0))]);
|
||||
let warped = b.n("directional_warp", 180.0, 320.0, &[("intensity", f(5.0)), ("angle", f(0.25))]);
|
||||
b.c(grain, warped, "input");
|
||||
b.c(warp_src, warped, "intensity_input");
|
||||
let rot = b.n("transformation", 380.0, 0.0, &[("scale", Value::Float2([1.0, 1.0]))]);
|
||||
b.c(warped, rot, "input");
|
||||
let h = b.n("blend", 560.0, 90.0, &[("mode", e(3))]);
|
||||
b.c(rot, h, "foreground");
|
||||
b.c(planks, h, "background");
|
||||
let normal = b.n("normal", 740.0, 0.0, &[("intensity", f(1.2))]);
|
||||
b.c(h, normal, "input");
|
||||
let ao = b.n("ambient_occlusion", 740.0, 120.0, &[("spread", f(0.03))]);
|
||||
b.c(h, ao, "height");
|
||||
let cmap = b.n("gradient_map", 740.0, 240.0, &[("gradient", grad(&[(0.0, [0.10, 0.04, 0.015]), (0.45, [0.33, 0.15, 0.05]), (1.0, [0.62, 0.36, 0.15])]))]);
|
||||
b.c(h, cmap, "input");
|
||||
let rough = b.n("levels", 740.0, 360.0, &[("out_low", f(0.45)), ("out_high", f(0.75))]);
|
||||
b.c(rot, rough, "input");
|
||||
let metal = b.n("uniform", 740.0, 480.0, &[("mode", e(1)), ("color", col(0.0, 0.0, 0.0))]);
|
||||
let height = b.n("blend", 360.0, 80.0, &[("mode", e(3)), ("opacity", f(0.18))]);
|
||||
b.c(warped, height, "foreground");
|
||||
b.c(planks, height, "background");
|
||||
let normal = b.n("normal", 540.0, 0.0, &[("intensity", f(1.6))]);
|
||||
b.c(height, normal, "input");
|
||||
let ao = b.n("ambient_occlusion", 540.0, 120.0, &[("spread", f(0.03)), ("intensity", f(0.6))]);
|
||||
b.c(height, ao, "height");
|
||||
let tone = b.n("blend", 360.0, 240.0, &[("mode", e(9)), ("opacity", f(0.55))]);
|
||||
b.c(ids, tone, "foreground");
|
||||
b.c(warped, tone, "background");
|
||||
let wood_col = b.n(
|
||||
"gradient_map",
|
||||
540.0,
|
||||
240.0,
|
||||
&[("gradient", grad(&[(0.0, [0.045, 0.018, 0.007]), (0.4, [0.15, 0.065, 0.024]), (0.75, [0.3, 0.15, 0.06]), (1.0, [0.42, 0.24, 0.11])]))],
|
||||
);
|
||||
b.c(tone, wood_col, "input");
|
||||
let gaps = b.n("histogram_scan", 540.0, 400.0, &[("position", f(0.97)), ("contrast", f(0.95))]);
|
||||
b.c(planks, gaps, "input");
|
||||
let base = b.n("blend", 720.0, 300.0, &[("mode", e(3))]);
|
||||
b.c(gaps, base, "foreground");
|
||||
b.c(wood_col, base, "background");
|
||||
let rough = b.n("levels", 720.0, 440.0, &[("out_low", f(0.32)), ("out_high", f(0.55))]);
|
||||
b.c(warped, rough, "input");
|
||||
let metal = b.n("uniform", 720.0, 560.0, &[("mode", e(1)), ("color", col(0.0, 0.0, 0.0))]);
|
||||
b.outputs(
|
||||
1000.0,
|
||||
940.0,
|
||||
&[
|
||||
(cmap, "output", 0, "basecolor"),
|
||||
(base, "output", 0, "basecolor"),
|
||||
(normal, "output", 1, "normal"),
|
||||
(rough, "output", 2, "roughness"),
|
||||
(metal, "output", 3, "metallic"),
|
||||
(h, "output", 4, "height"),
|
||||
(height, "output", 4, "height"),
|
||||
(ao, "output", 5, "ambientocclusion"),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
fn wicker(b: &mut B) {
|
||||
let weave = b.n("weave", 0.0, 0.0, &[("tiling", i(7)), ("width", f(0.92))]);
|
||||
let fibers = b.n("anisotropic_noise", 0.0, 160.0, &[("scale", f(2.0)), ("scale_y", f(160.0)), ("smoothness", f(0.2))]);
|
||||
let tint = b.n("clouds_2", 0.0, 320.0, &[("scale", f(10.0))]);
|
||||
let height = b.n("blend", 180.0, 0.0, &[("mode", e(3)), ("opacity", f(0.12))]);
|
||||
b.c(fibers, height, "foreground");
|
||||
b.c(weave, height, "background");
|
||||
let normal = b.n("normal", 360.0, 0.0, &[("intensity", f(2.2))]);
|
||||
b.c(height, normal, "input");
|
||||
let ao = b.n("ambient_occlusion", 360.0, 120.0, &[("spread", f(0.03)), ("intensity", f(0.9))]);
|
||||
b.c(height, ao, "height");
|
||||
let tone = b.n("blend", 180.0, 240.0, &[("mode", e(9)), ("opacity", f(0.35))]);
|
||||
b.c(tint, tone, "foreground");
|
||||
b.c(height, tone, "background");
|
||||
let base = b.n(
|
||||
"gradient_map",
|
||||
360.0,
|
||||
240.0,
|
||||
&[("gradient", grad(&[(0.0, [0.015, 0.008, 0.003]), (0.45, [0.14, 0.075, 0.025]), (0.8, [0.34, 0.21, 0.08]), (1.0, [0.46, 0.32, 0.14])]))],
|
||||
);
|
||||
b.c(tone, base, "input");
|
||||
let rough = b.n("levels", 360.0, 400.0, &[("out_low", f(0.6)), ("out_high", f(0.8))]);
|
||||
b.c(fibers, rough, "input");
|
||||
let metal = b.n("uniform", 360.0, 520.0, &[("mode", e(1)), ("color", col(0.0, 0.0, 0.0))]);
|
||||
b.outputs(
|
||||
600.0,
|
||||
&[
|
||||
(base, "output", 0, "basecolor"),
|
||||
(normal, "output", 1, "normal"),
|
||||
(rough, "output", 2, "roughness"),
|
||||
(metal, "output", 3, "metallic"),
|
||||
(height, "output", 4, "height"),
|
||||
(ao, "output", 5, "ambientocclusion"),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
fn ground(b: &mut B) {
|
||||
let stones = b.n("stones", 0.0, 0.0, &[("scale", f(6.0)), ("gap", f(0.1)), ("bevel", f(0.45)), ("height_random", f(0.35)), ("detail", f(0.25))]);
|
||||
let dirt = b.n("dirt", 0.0, 160.0, &[("scale", f(6.0))]);
|
||||
let clouds = b.n("clouds_2", 0.0, 320.0, &[("scale", f(10.0))]);
|
||||
let hb = b.n("height_blend", 180.0, 80.0, &[("offset", f(0.22)), ("contrast", f(0.85))]);
|
||||
b.c(stones, hb, "top");
|
||||
b.c(dirt, hb, "bottom");
|
||||
let moss = b.n("moss", 360.0, 240.0, &[("amount", f(0.4)), ("scale", f(8.0)), ("height_bias", f(0.35))]);
|
||||
b.cp(hb, "height", moss, "height");
|
||||
let normal = b.n("normal", 360.0, 0.0, &[("intensity", f(2.0))]);
|
||||
b.cp(hb, "height", normal, "input");
|
||||
let ao = b.n("ambient_occlusion", 360.0, 120.0, &[("spread", f(0.07)), ("intensity", f(0.7))]);
|
||||
b.cp(hb, "height", ao, "height");
|
||||
let stone_h = b.n("blend", 180.0, 320.0, &[("mode", e(9)), ("opacity", f(0.6))]);
|
||||
b.c(clouds, stone_h, "foreground");
|
||||
b.c(stones, stone_h, "background");
|
||||
let stone_col =
|
||||
b.n("gradient_map", 360.0, 360.0, &[("gradient", grad(&[(0.0, [0.03, 0.03, 0.032]), (0.55, [0.11, 0.105, 0.1]), (1.0, [0.24, 0.22, 0.2])]))]);
|
||||
b.c(stone_h, stone_col, "input");
|
||||
let dirt_col = b.n("gradient_map", 360.0, 480.0, &[("gradient", grad(&[(0.0, [0.02, 0.013, 0.008]), (1.0, [0.1, 0.065, 0.04])]))]);
|
||||
b.c(dirt, dirt_col, "input");
|
||||
let moss_col = b.n("gradient_map", 360.0, 600.0, &[("gradient", grad(&[(0.0, [0.02, 0.04, 0.008]), (1.0, [0.07, 0.14, 0.02])]))]);
|
||||
b.c(clouds, moss_col, "input");
|
||||
let ground_col = b.n("blend", 540.0, 360.0, &[]);
|
||||
b.c(dirt_col, ground_col, "foreground");
|
||||
b.c(stone_col, ground_col, "background");
|
||||
b.cp(hb, "blend_mask", ground_col, "mask");
|
||||
let base = b.n("blend", 720.0, 360.0, &[]);
|
||||
b.c(moss_col, base, "foreground");
|
||||
b.c(ground_col, base, "background");
|
||||
b.c(moss, base, "mask");
|
||||
let rough = b.n("levels", 720.0, 480.0, &[("out_low", f(0.7)), ("out_high", f(0.95))]);
|
||||
b.c(clouds, rough, "input");
|
||||
let metal = b.n("uniform", 720.0, 600.0, &[("mode", e(1)), ("color", col(0.0, 0.0, 0.0))]);
|
||||
b.outputs(
|
||||
940.0,
|
||||
&[
|
||||
(base, "output", 0, "basecolor"),
|
||||
(normal, "output", 1, "normal"),
|
||||
(rough, "output", 2, "roughness"),
|
||||
(metal, "output", 3, "metallic"),
|
||||
(hb, "height", 4, "height"),
|
||||
(ao, "output", 5, "ambientocclusion"),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
fn stone_tiles(b: &mut B) {
|
||||
let layout = b.n(
|
||||
"brick_generator",
|
||||
0.0,
|
||||
0.0,
|
||||
&[("bricks_x", i(3)), ("bricks_y", i(3)), ("offset", f(0.5)), ("gap", f(0.025)), ("bevel", f(0.12)), ("height_random", f(0.2))],
|
||||
);
|
||||
let ids = b.n(
|
||||
"brick_generator",
|
||||
0.0,
|
||||
160.0,
|
||||
&[("bricks_x", i(3)), ("bricks_y", i(3)), ("offset", f(0.5)), ("gap", f(0.025)), ("bevel", f(0.0)), ("height_random", f(0.0)), ("lum_random", f(1.0))],
|
||||
);
|
||||
let cracks = b.n("cracks", 0.0, 320.0, &[("scale", f(4.0)), ("width", f(1.0))]);
|
||||
let clouds = b.n("clouds_2", 0.0, 480.0, &[("scale", f(12.0))]);
|
||||
let chipped = b.n("edge_damage", 180.0, 0.0, &[("width", f(10.0)), ("amount", f(0.5)), ("scale", f(10.0))]);
|
||||
b.c(layout, chipped, "height");
|
||||
let cracked = b.n("blend", 360.0, 0.0, &[("mode", e(2)), ("opacity", f(0.35))]);
|
||||
b.c(cracks, cracked, "foreground");
|
||||
b.c(chipped, cracked, "background");
|
||||
let height = b.n("blend", 540.0, 0.0, &[("mode", e(3)), ("opacity", f(0.2))]);
|
||||
b.c(clouds, height, "foreground");
|
||||
b.c(cracked, height, "background");
|
||||
let normal = b.n("normal", 720.0, 0.0, &[("intensity", f(2.0))]);
|
||||
b.c(height, normal, "input");
|
||||
let ao = b.n("ambient_occlusion", 720.0, 120.0, &[("spread", f(0.05)), ("intensity", f(0.7))]);
|
||||
b.c(height, ao, "height");
|
||||
let tone = b.n("blend", 360.0, 240.0, &[("mode", e(9)), ("opacity", f(0.45))]);
|
||||
b.c(clouds, tone, "foreground");
|
||||
b.c(ids, tone, "background");
|
||||
let stone_col =
|
||||
b.n("gradient_map", 540.0, 240.0, &[("gradient", grad(&[(0.0, [0.09, 0.08, 0.065]), (0.5, [0.2, 0.18, 0.14]), (1.0, [0.34, 0.31, 0.25])]))]);
|
||||
b.c(tone, stone_col, "input");
|
||||
let mask = b.n("histogram_scan", 540.0, 400.0, &[("position", f(0.9)), ("contrast", f(0.9))]);
|
||||
b.c(cracked, mask, "input");
|
||||
let grout = b.n("uniform", 540.0, 520.0, &[("color", col(0.04, 0.035, 0.03))]);
|
||||
let base = b.n("blend", 720.0, 320.0, &[]);
|
||||
b.c(stone_col, base, "foreground");
|
||||
b.c(grout, base, "background");
|
||||
b.c(mask, base, "mask");
|
||||
let rough = b.n("levels", 720.0, 460.0, &[("out_low", f(0.6)), ("out_high", f(0.9))]);
|
||||
b.c(clouds, rough, "input");
|
||||
let metal = b.n("uniform", 720.0, 580.0, &[("mode", e(1)), ("color", col(0.0, 0.0, 0.0))]);
|
||||
b.outputs(
|
||||
940.0,
|
||||
&[
|
||||
(base, "output", 0, "basecolor"),
|
||||
(normal, "output", 1, "normal"),
|
||||
(rough, "output", 2, "roughness"),
|
||||
(metal, "output", 3, "metallic"),
|
||||
(height, "output", 4, "height"),
|
||||
(ao, "output", 5, "ambientocclusion"),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
fn marble(b: &mut B) {
|
||||
let veins = b.n("marble", 0.0, 0.0, &[("scale", f(3.0)), ("turbulence", f(5.0)), ("sharpness", f(14.0)), ("direction", e(2))]);
|
||||
let fine = b.n("ridged_fractal", 0.0, 160.0, &[("scale", f(6.0)), ("octaves", i(6)), ("roughness", f(0.55)), ("sharpness", f(6.0))]);
|
||||
let flow = b.n("fractal_sum_base", 0.0, 320.0, &[("scale", f(3.0)), ("octaves", i(6))]);
|
||||
let fine_mask = b.n("levels", 180.0, 160.0, &[("in_low", f(0.55)), ("in_high", f(1.0)), ("out_high", f(0.45))]);
|
||||
b.c(fine, fine_mask, "input");
|
||||
let vein_mask = b.n("blend", 360.0, 80.0, &[("mode", e(5))]);
|
||||
b.c(fine_mask, vein_mask, "foreground");
|
||||
b.c(veins, vein_mask, "background");
|
||||
let normal = b.n("normal", 720.0, 0.0, &[("intensity", f(0.25))]);
|
||||
b.c(flow, normal, "input");
|
||||
let ao = b.n("ambient_occlusion", 720.0, 120.0, &[("spread", f(0.02)), ("intensity", f(0.2))]);
|
||||
b.c(flow, ao, "height");
|
||||
let stone = b.n("gradient_map", 540.0, 240.0, &[("gradient", grad(&[(0.0, [0.8, 0.78, 0.74]), (0.5, [0.52, 0.48, 0.42]), (1.0, [0.2, 0.17, 0.13])]))]);
|
||||
b.c(vein_mask, stone, "input");
|
||||
let cloudy = b.n("blend", 720.0, 240.0, &[("mode", e(3)), ("opacity", f(0.3))]);
|
||||
b.c(flow, cloudy, "foreground");
|
||||
b.c(stone, cloudy, "background");
|
||||
let rough = b.n("uniform", 720.0, 400.0, &[("mode", e(1)), ("color", col(0.12, 0.12, 0.12))]);
|
||||
let metal = b.n("uniform", 720.0, 520.0, &[("mode", e(1)), ("color", col(0.0, 0.0, 0.0))]);
|
||||
b.outputs(
|
||||
940.0,
|
||||
&[
|
||||
(cloudy, "output", 0, "basecolor"),
|
||||
(normal, "output", 1, "normal"),
|
||||
(rough, "output", 2, "roughness"),
|
||||
(metal, "output", 3, "metallic"),
|
||||
(flow, "output", 4, "height"),
|
||||
(ao, "output", 5, "ambientocclusion"),
|
||||
],
|
||||
);
|
||||
@@ -307,46 +572,6 @@ fn fabric(b: &mut B) {
|
||||
);
|
||||
}
|
||||
|
||||
fn ground(b: &mut B) {
|
||||
let stones = b.n("stones", 0.0, 0.0, &[("scale", f(5.0)), ("gap", f(0.12)), ("height_random", f(0.5))]);
|
||||
let dirt = b.n("dirt", 0.0, 180.0, &[("scale", f(5.0))]);
|
||||
let clouds = b.n("clouds_2", 0.0, 360.0, &[("scale", f(10.0))]);
|
||||
let h = b.n("height_blend", 220.0, 90.0, &[("offset", f(0.3)), ("contrast", f(0.85))]);
|
||||
b.c(stones, h, "top");
|
||||
b.c(dirt, h, "bottom");
|
||||
let normal = b.n("normal", 440.0, 0.0, &[("intensity", f(1.6))]);
|
||||
b.cp(h, "height", normal, "input");
|
||||
let ao = b.n("ambient_occlusion", 440.0, 120.0, &[("spread", f(0.08))]);
|
||||
b.cp(h, "height", ao, "height");
|
||||
// Stones: grey with cloudy variation; dirt: brown, joined by the blend's mask.
|
||||
let stone_h = b.n("blend", 220.0, 300.0, &[("mode", e(3)), ("opacity", f(0.5))]);
|
||||
b.c(clouds, stone_h, "foreground");
|
||||
b.c(stones, stone_h, "background");
|
||||
let stone_col =
|
||||
b.n("gradient_map", 440.0, 240.0, &[("gradient", grad(&[(0.0, [0.06, 0.055, 0.05]), (0.6, [0.17, 0.16, 0.14]), (1.0, [0.30, 0.28, 0.25])]))]);
|
||||
b.c(stone_h, stone_col, "input");
|
||||
let dirt_col = b.n("gradient_map", 440.0, 360.0, &[("gradient", grad(&[(0.0, [0.03, 0.02, 0.012]), (1.0, [0.12, 0.08, 0.05])]))]);
|
||||
b.c(dirt, dirt_col, "input");
|
||||
let base = b.n("blend", 660.0, 300.0, &[]);
|
||||
b.c(dirt_col, base, "foreground");
|
||||
b.c(stone_col, base, "background");
|
||||
b.cp(h, "blend_mask", base, "mask");
|
||||
let rough = b.n("levels", 660.0, 440.0, &[("out_low", f(0.7)), ("out_high", f(0.95))]);
|
||||
b.c(clouds, rough, "input");
|
||||
let metal = b.n("uniform", 660.0, 560.0, &[("mode", e(1)), ("color", col(0.0, 0.0, 0.0))]);
|
||||
b.outputs(
|
||||
880.0,
|
||||
&[
|
||||
(base, "output", 0, "basecolor"),
|
||||
(normal, "output", 1, "normal"),
|
||||
(rough, "output", 2, "roughness"),
|
||||
(metal, "output", 3, "metallic"),
|
||||
(h, "height", 4, "height"),
|
||||
(ao, "output", 5, "ambientocclusion"),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// The package the app opens with: the brick wall sample.
|
||||
pub fn sample_package() -> Package {
|
||||
let mut p = Package::new("Untitled package");
|
||||
|
||||
@@ -280,6 +280,48 @@ impl Mesh {
|
||||
}));
|
||||
}
|
||||
|
||||
/// Each triangle split into four at its edge midpoints (shared edges share their midpoint);
|
||||
/// attributes are interpolated and submesh ranges keep their triangles.
|
||||
pub fn subdivided(&self) -> Mesh {
|
||||
let mut m = Mesh { indices: Vec::with_capacity(self.indices.len() * 4), ..self.clone() };
|
||||
let has = |len: usize| len == self.positions.len();
|
||||
let (has_n, has_t, has_uv, has_c) = (has(self.normals.len()), has(self.tangents.len()), has(self.uvs.len()), has(self.colors.len()));
|
||||
let mut mids = std::collections::HashMap::new();
|
||||
let mut mid = |m: &mut Mesh, a: u32, b: u32| -> u32 {
|
||||
*mids.entry((a.min(b), a.max(b))).or_insert_with(|| {
|
||||
let (i, j) = (a as usize, b as usize);
|
||||
m.positions.push((self.positions[i] + self.positions[j]) * 0.5);
|
||||
if has_n {
|
||||
m.normals.push((self.normals[i] + self.normals[j]).normalize_or_zero());
|
||||
}
|
||||
if has_t {
|
||||
let (ti, tj) = (self.tangents[i], self.tangents[j]);
|
||||
m.tangents.push((ti.truncate() + tj.truncate()).normalize_or_zero().extend(ti.w));
|
||||
}
|
||||
if has_uv {
|
||||
m.uvs.push((self.uvs[i] + self.uvs[j]) * 0.5);
|
||||
}
|
||||
if has_c {
|
||||
m.colors.push((self.colors[i] + self.colors[j]) * 0.5);
|
||||
}
|
||||
(m.positions.len() - 1) as u32
|
||||
})
|
||||
};
|
||||
for t in self.indices.chunks_exact(3) {
|
||||
if t.iter().any(|&i| i as usize >= self.positions.len()) {
|
||||
continue;
|
||||
}
|
||||
let (a, b, c) = (t[0], t[1], t[2]);
|
||||
let (ab, bc, ca) = (mid(&mut m, a, b), mid(&mut m, b, c), mid(&mut m, c, a));
|
||||
m.indices.extend_from_slice(&[a, ab, ca, ab, b, bc, ca, bc, c, ab, bc, ca]);
|
||||
}
|
||||
for s in &mut m.submeshes {
|
||||
s.start *= 4;
|
||||
s.count *= 4;
|
||||
}
|
||||
m
|
||||
}
|
||||
|
||||
/// Uniformly scale and translate so the mesh is centered with the given bounding radius.
|
||||
pub fn normalize_to(&mut self, radius: f32) {
|
||||
let (lo, hi) = self.bounds();
|
||||
@@ -377,6 +419,16 @@ mod tests {
|
||||
assert_eq!(m.triangles_of(0).collect::<Vec<_>>(), vec![0, 1]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn subdivision_shares_edge_midpoints() {
|
||||
let m = quad().subdivided();
|
||||
// 4 corners + 5 edge midpoints (the diagonal is shared), 8 triangles.
|
||||
assert_eq!((m.positions.len(), m.triangle_count()), (9, 8));
|
||||
assert_eq!(m.uvs.len(), 9);
|
||||
assert_eq!((m.submeshes[0].start, m.submeshes[0].count), (0, 24));
|
||||
m.validate().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validate_catches_bad_indices() {
|
||||
let mut m = quad();
|
||||
|
||||
@@ -158,7 +158,7 @@ impl EnvImage {
|
||||
}
|
||||
}
|
||||
|
||||
fn hammersley(i: u32, n: u32) -> Vec2 {
|
||||
pub(crate) fn hammersley(i: u32, n: u32) -> Vec2 {
|
||||
Vec2::new(i as f32 / n as f32, i.reverse_bits() as f32 * 2.328_306_4e-10)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,4 +9,4 @@
|
||||
pub mod ibl;
|
||||
pub mod preview;
|
||||
|
||||
pub use preview::{Lighting, Maps, Scene, Settings, render};
|
||||
pub use preview::{Lighting, Maps, Scene, Settings, builtin_mesh, render};
|
||||
@@ -3,6 +3,7 @@
|
||||
//! height output, then metallic/roughness GGX shading under image-based light (SH diffuse,
|
||||
//! prefiltered specular, an analytic environment BRDF), exposure and ACES tone mapping.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use materialcraft_geom::glam::{Vec2, Vec3};
|
||||
@@ -75,11 +76,50 @@ impl Scene {
|
||||
|
||||
/// A built-in scene (`rounded_cube`, `sphere`, …); unknown ids give the rounded cube.
|
||||
pub fn builtin(id: &str) -> Scene {
|
||||
let mesh = materialcraft_geom::primitives::builtin(id).unwrap_or_else(|| materialcraft_geom::primitives::rounded_box(Vec3::ONE, 0.15));
|
||||
Scene::new(builtin_mesh(id))
|
||||
}
|
||||
|
||||
/// `base` subdivided to at most `max_tris` triangles and pushed along its normals by
|
||||
/// `depth × (height − 0.5)` (the height map repeated `tiling` times): real silhouettes and
|
||||
/// self-occlusion for offline renders. Coincident vertices (UV seams, hard edges) move
|
||||
/// together, so the surface stays closed.
|
||||
pub fn displaced(base: &Mesh, height: &Image, tiling: f32, depth: f32, max_tris: usize) -> Scene {
|
||||
let mut mesh = base.clone();
|
||||
if mesh.normals.len() != mesh.positions.len() {
|
||||
mesh.compute_normals();
|
||||
}
|
||||
while mesh.triangle_count() > 0 && mesh.triangle_count() * 4 <= max_tris {
|
||||
mesh = mesh.subdivided();
|
||||
}
|
||||
// Pre-filtered so fine detail (left to the normal map) does not spike the silhouette.
|
||||
let height = height.resize(height.w.min(512), height.h.min(512), true);
|
||||
let key = |p: Vec3| (p * 1e4).round().as_ivec3().to_array();
|
||||
let mut welded: HashMap<[i32; 3], (Vec3, f32, f32)> = HashMap::new();
|
||||
for ((p, n), uv) in mesh.positions.iter().zip(&mesh.normals).zip(&mesh.uvs) {
|
||||
let e = welded.entry(key(*p)).or_default();
|
||||
e.0 += *n;
|
||||
e.1 += height.sample_gray(uv.x * tiling, uv.y * tiling, true);
|
||||
e.2 += 1.0;
|
||||
}
|
||||
for p in &mut mesh.positions {
|
||||
if let Some((n, h, count)) = welded.get(&key(*p)) {
|
||||
*p += n.normalize_or_zero() * depth * (h / count - 0.5);
|
||||
}
|
||||
}
|
||||
Scene::new(mesh)
|
||||
}
|
||||
}
|
||||
|
||||
/// A built-in mesh by id; unknown ids give the rounded cube.
|
||||
pub fn builtin_mesh(id: &str) -> Mesh {
|
||||
let mut m = materialcraft_geom::primitives::builtin(id).unwrap_or_else(|| materialcraft_geom::primitives::rounded_box(Vec3::ONE, 0.15));
|
||||
if id == "sphere" {
|
||||
// The texture wraps twice around, so texels are square at the equator.
|
||||
m.uvs.iter_mut().for_each(|uv| uv.x *= 2.0);
|
||||
}
|
||||
m
|
||||
}
|
||||
|
||||
/// Prefiltered environment lighting.
|
||||
pub struct Lighting {
|
||||
pub name: String,
|
||||
@@ -134,11 +174,28 @@ pub struct Settings {
|
||||
pub show_env: bool,
|
||||
/// 1 = one ray per pixel, 2 = 2×2 supersampling.
|
||||
pub supersample: u32,
|
||||
/// Ray-traced ambient occlusion rays per sample (0 = off): darkens the crevices of a
|
||||
/// displaced scene.
|
||||
pub ao_rays: u32,
|
||||
/// Strength of a shadow-casting key light from the camera's upper left (0 = off).
|
||||
pub key_light: f32,
|
||||
}
|
||||
|
||||
impl Default for Settings {
|
||||
fn default() -> Self {
|
||||
Settings { yaw: 35.0, pitch: 25.0, distance: 3.2, tiling: 1.0, exposure: 0.0, env_rotation: 0.0, height_scale: 0.03, show_env: false, supersample: 1 }
|
||||
Settings {
|
||||
yaw: 35.0,
|
||||
pitch: 25.0,
|
||||
distance: 3.2,
|
||||
tiling: 1.0,
|
||||
exposure: 0.0,
|
||||
env_rotation: 0.0,
|
||||
height_scale: 0.03,
|
||||
show_env: false,
|
||||
supersample: 1,
|
||||
ao_rays: 0,
|
||||
key_light: 0.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,8 +243,52 @@ fn rotate_y(v: Vec3, deg: f32) -> Vec3 {
|
||||
Vec3::new(v.x * c + v.z * s, v.y, -v.x * s + v.z * c)
|
||||
}
|
||||
|
||||
/// Per-pixel inputs of [`shade`] beyond the camera ray.
|
||||
struct Px {
|
||||
/// Backdrop color (seen through transparent areas).
|
||||
bg: Vec3,
|
||||
/// Direction toward the key light.
|
||||
key: Vec3,
|
||||
/// Random rotation of the ambient occlusion ray pattern.
|
||||
jitter: Vec2,
|
||||
}
|
||||
|
||||
/// The fraction of `n`'s hemisphere at `p` that is open within `reach` (cosine-weighted).
|
||||
fn ambient_occlusion(scene: &Scene, p: Vec3, n: Vec3, rays: u32, jitter: Vec2) -> f32 {
|
||||
let (t, b) = n.any_orthonormal_pair();
|
||||
let reach = scene.radius * 0.3;
|
||||
let open = (0..rays)
|
||||
.filter(|&i| {
|
||||
let u = (ibl::hammersley(i, rays) + jitter).fract();
|
||||
let (r, phi) = (u.x.sqrt(), u.y * std::f32::consts::TAU);
|
||||
let d = t * (r * phi.cos()) + b * (r * phi.sin()) + n * (1.0 - u.x).max(0.0).sqrt();
|
||||
!scene.bvh.occluded(p, d, reach)
|
||||
})
|
||||
.count();
|
||||
open as f32 / rays as f32
|
||||
}
|
||||
|
||||
/// GGX specular plus Lambert diffuse from a white directional light along `l`.
|
||||
fn direct(n: Vec3, v: Vec3, l: Vec3, base: Vec3, f0: Vec3, metal: f32, rough: f32) -> Vec3 {
|
||||
let ndl = n.dot(l);
|
||||
if ndl <= 0.0 {
|
||||
return Vec3::ZERO;
|
||||
}
|
||||
let ndv = n.dot(v).max(1e-4);
|
||||
let h = (v + l).normalize_or_zero();
|
||||
let (ndh, vdh) = (n.dot(h).max(0.0), v.dot(h).max(0.0));
|
||||
let a2 = (rough * rough).powi(2).max(1e-4);
|
||||
let d = a2 / (std::f32::consts::PI * (ndh * ndh * (a2 - 1.0) + 1.0).powi(2));
|
||||
let k = (rough + 1.0).powi(2) / 8.0;
|
||||
let g = ndl / (ndl * (1.0 - k) + k) * ndv / (ndv * (1.0 - k) + k);
|
||||
let f = f0 + (Vec3::ONE - f0) * (1.0 - vdh).powi(5);
|
||||
let spec = f * (d * g / (4.0 * ndv * ndl));
|
||||
let diff = (Vec3::ONE - f) * base * (1.0 - metal) / std::f32::consts::PI;
|
||||
(diff + spec) * ndl
|
||||
}
|
||||
|
||||
/// Shade one camera ray; `None` = missed the mesh.
|
||||
fn shade(scene: &Scene, maps: &Maps, light: &Lighting, s: &Settings, origin: Vec3, dir: Vec3) -> Option<Vec3> {
|
||||
fn shade(scene: &Scene, maps: &Maps, light: &Lighting, s: &Settings, origin: Vec3, dir: Vec3, px: &Px) -> Option<Vec3> {
|
||||
let hit = scene.bvh.closest(origin, dir, f32::MAX)?;
|
||||
let m = &scene.mesh;
|
||||
let [i0, i1, i2] = m.tri(hit.tri as usize)?;
|
||||
@@ -254,20 +355,42 @@ fn shade(scene: &Scene, maps: &Maps, light: &Lighting, s: &Settings, origin: Vec
|
||||
let spec = light.specular(rot(r), rough) * (f0 * sa + Vec3::splat(sb));
|
||||
let diff = light.diffuse(rot(n)) * diffuse_col;
|
||||
let mut c = (diff + spec) * ao;
|
||||
if s.ao_rays > 0 || s.key_light > 0.0 {
|
||||
// The true surface (a displaced scene's facets), offset to avoid self-hits.
|
||||
let (p0, p1, p2) = (*m.positions.get(i0)?, *m.positions.get(i1)?, *m.positions.get(i2)?);
|
||||
let face = (p1 - p0).cross(p2 - p0).normalize_or_zero();
|
||||
let face = if face.dot(nrm) < 0.0 { -face } else { face };
|
||||
let p = origin + dir * hit.t + face * scene.radius * 2e-4;
|
||||
if s.ao_rays > 0 {
|
||||
c *= ambient_occlusion(scene, p, face, s.ao_rays, px.jitter);
|
||||
}
|
||||
if s.key_light > 0.0 && face.dot(px.key) > 0.0 && !scene.bvh.occluded(p, px.key, f32::MAX) {
|
||||
c += direct(n, v, px.key, base, f0, metal, rough) * s.key_light * ao;
|
||||
}
|
||||
}
|
||||
if let Some(e) = tex(&maps.emissive, uv) {
|
||||
c += Vec3::new(e[0], e[1], e[2]);
|
||||
}
|
||||
if let Some(o) = &maps.opacity {
|
||||
let a = o.sample_gray(uv.x, uv.y, true).clamp(0.0, 1.0);
|
||||
c = c * a + backdrop(dir) * (1.0 - a);
|
||||
c = c * a + px.bg * (1.0 - a);
|
||||
}
|
||||
Some(c)
|
||||
}
|
||||
|
||||
/// The flat studio backdrop: a soft vertical gradient (linear).
|
||||
fn backdrop(dir: Vec3) -> Vec3 {
|
||||
let t = (dir.y * 0.5 + 0.5).clamp(0.0, 1.0);
|
||||
Vec3::splat(0.012).lerp(Vec3::splat(0.03), t)
|
||||
/// The studio backdrop at screen position `p` (−1..1): a soft vignette (linear).
|
||||
fn backdrop(p: Vec2) -> Vec3 {
|
||||
let t = (p.length() * 0.75).clamp(0.0, 1.0);
|
||||
Vec3::splat(0.04).lerp(Vec3::splat(0.012), t * t * (3.0 - 2.0 * t))
|
||||
}
|
||||
|
||||
/// A cheap integer hash to 0..1 pairs (the per-sample AO pattern rotation).
|
||||
fn jitter(x: u32, y: u32) -> Vec2 {
|
||||
let mut h = x.wrapping_mul(0x9E37_79B1) ^ y.wrapping_mul(0x85EB_CA77);
|
||||
h ^= h >> 15;
|
||||
h = h.wrapping_mul(0x2C1B_3C6D);
|
||||
h ^= h >> 12;
|
||||
Vec2::new((h & 0xFFFF) as f32 / 65536.0, (h >> 16) as f32 / 65536.0)
|
||||
}
|
||||
|
||||
/// Render `w × h` pixels to sRGB RGBA8.
|
||||
@@ -278,31 +401,30 @@ pub fn render(scene: &Scene, maps: &Maps, light: &Lighting, s: &Settings, w: u32
|
||||
let ss = s.supersample.clamp(1, 4);
|
||||
let k = 2f32.powf(s.exposure);
|
||||
let bg_env = light.specular.get(3).or(light.specular.last());
|
||||
// Key light from the camera's upper left, a little in front of the subject.
|
||||
let fwd = cam.ray(Vec2::ZERO, aspect).dir;
|
||||
let right = fwd.cross(Vec3::Y).normalize_or(Vec3::X);
|
||||
let key = (right * -0.6 + right.cross(fwd) * 0.75 - fwd * 0.5).normalize_or_zero();
|
||||
let mut out = vec![0u8; (w * h * 4) as usize];
|
||||
out.par_chunks_mut(w as usize * 4).enumerate().for_each(|(y, row)| {
|
||||
for x in 0..w as usize {
|
||||
let mut acc = Vec3::ZERO;
|
||||
let mut cover = 0.0;
|
||||
for sy in 0..ss {
|
||||
for sx in 0..ss {
|
||||
let px = (x as f32 + (sx as f32 + 0.5) / ss as f32) / w as f32 * 2.0 - 1.0;
|
||||
let py = 1.0 - (y as f32 + (sy as f32 + 0.5) / ss as f32) / h as f32 * 2.0;
|
||||
let ray = cam.ray(Vec2::new(px, py), aspect);
|
||||
match shade(scene, maps, light, s, ray.origin, ray.dir) {
|
||||
Some(c) => {
|
||||
acc += c * k;
|
||||
cover += 1.0;
|
||||
}
|
||||
None => {
|
||||
acc += match (s.show_env, bg_env) {
|
||||
(true, Some(e)) => e.sample(rotate_y(ray.dir, -s.env_rotation)) * k,
|
||||
_ => backdrop(ray.dir),
|
||||
};
|
||||
}
|
||||
}
|
||||
let bg = backdrop(Vec2::new(px, py));
|
||||
let p = Px { bg, key, jitter: jitter(x as u32 * ss + sx, y as u32 * ss + sy) };
|
||||
acc += match shade(scene, maps, light, s, ray.origin, ray.dir, &p) {
|
||||
Some(c) => c * k,
|
||||
None => match (s.show_env, bg_env) {
|
||||
(true, Some(e)) => e.sample(rotate_y(ray.dir, -s.env_rotation)) * k,
|
||||
_ => bg,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
let _ = cover;
|
||||
let c = acc / (ss * ss) as f32;
|
||||
let q = |v: f32| (linear_to_srgb(aces(v)) * 255.0 + 0.5) as u8;
|
||||
if let Some(px) = row.get_mut(x * 4..x * 4 + 4) {
|
||||
|
||||
@@ -230,6 +230,7 @@ fn render(app: &mut MaterialCraftApp, ctx: &egui::Context, rect: Rect, moving: b
|
||||
height_scale: v.height_scale,
|
||||
show_env: app.view3d.show_env,
|
||||
supersample: if full { 2 } else { 1 },
|
||||
..Settings::default()
|
||||
};
|
||||
let maps = Maps::from_usages(app.session.material_maps());
|
||||
let (Some((_, scene)), Some(light)) = (&app.view3d.scene, &app.view3d.light) else { return };
|
||||
|
||||
@@ -112,13 +112,14 @@ fn modal(ctx: &egui::Context, id: &str, title: &str, open: &mut bool, size: egui
|
||||
fn new_graph(app: &mut MaterialCraftApp, ctx: &egui::Context) {
|
||||
let mut open = true;
|
||||
let mut create = false;
|
||||
modal(ctx, "new-graph", tr("New graph"), &mut open, vec2(640.0, 420.0), |ui| {
|
||||
modal(ctx, "new-graph", tr("New graph"), &mut open, vec2(640.0, 490.0), |ui| {
|
||||
let tk = Tokens::get(ui.ctx());
|
||||
ui.horizontal_top(|ui| {
|
||||
ui.vertical(|ui| {
|
||||
ui.set_width(400.0);
|
||||
ui.label(RichText::new(tr("Templates")).strong());
|
||||
egui::ScrollArea::vertical().max_height(330.0).show(ui, |ui| {
|
||||
// Three rows of templates without scrolling.
|
||||
egui::ScrollArea::vertical().max_height(400.0).show(ui, |ui| {
|
||||
for row in materialcraft_engine::samples::TEMPLATES.chunks(4) {
|
||||
ui.horizontal(|ui| {
|
||||
for (id, label) in row {
|
||||
|
||||
@@ -47,10 +47,12 @@ fn snapshots() {
|
||||
// Select a node so the properties panel shows parameters.
|
||||
let id = h.state().session.graph().unwrap().nodes[0].id;
|
||||
h.state_mut().run("graph.select", json!({"ids": [id.0]}));
|
||||
h.state_mut().run("view.2d", json!({"node": 17, "histogram": true}));
|
||||
h.state_mut().run("view.2d", json!({"node": 16, "histogram": true}));
|
||||
settle(&mut h, 30);
|
||||
save(&mut h, &dir, "workspace");
|
||||
for (tpl, name) in [("wood", "wood"), ("rusty_metal", "rusty-metal"), ("stone_tiles", "stone-tiles"), ("fabric", "fabric"), ("ground", "ground")] {
|
||||
for (tpl, name) in
|
||||
[("wood", "wood"), ("rusty_metal", "rusty-metal"), ("stone_tiles", "stone-tiles"), ("fabric", "fabric"), ("ground", "ground"), ("lava", "lava")]
|
||||
{
|
||||
h.state_mut().run("file.new", json!({"template": tpl, "size": 1024}));
|
||||
h.state_mut().ui.frame_all = true;
|
||||
settle(&mut h, 40);
|
||||
|
||||
@@ -26,7 +26,7 @@ Agents drive MaterialCraft three ways, all dispatching the same engine commands:
|
||||
| `package.open {path}` / `package.save {path?}` | headless | workspace-scoped package I/O |
|
||||
| `bitmap.import {path, name?}` | headless | embed an image as a resource |
|
||||
| `outputs.export {dir, format?, pattern?, depth?, graph?}` | headless | cook at full size and write every output |
|
||||
| `render {view?, width?, height?, yaw?, pitch?, scene?, node?, port?, full?}` | headless | PNG (base64) of the 3D view or of one node |
|
||||
| `render {view?, width?, height?, yaw?, pitch?, scene?, node?, port?, full?, tiling?, hq?, displacement?}` | headless | PNG (base64) of the 3D view or of one node; `hq` is the beauty render (displaced mesh, ray-traced AO, shadowed key light, 3×3 supersampling), `displacement` its depth in scene radii |
|
||||
| `ui.inspect` | app | UI state, the graph view rectangle, every node's screen rectangle, every port's screen position, fps, toasts |
|
||||
| `ui.menu.list` / `ui.menu.invoke {id}` | app | the menu catalog; behave like a click |
|
||||
| `ui.set {...}` | app | merge fields into the UI state |
|
||||
|
||||
|
Before Width: | Height: | Size: 624 KiB |
|
After Width: | Height: | Size: 636 KiB |
|
After Width: | Height: | Size: 621 KiB |
|
Before Width: | Height: | Size: 980 KiB After Width: | Height: | Size: 1.4 MiB |
|
Before Width: | Height: | Size: 504 KiB After Width: | Height: | Size: 620 KiB |
|
Before Width: | Height: | Size: 517 KiB After Width: | Height: | Size: 540 KiB |
|
Before Width: | Height: | Size: 573 KiB After Width: | Height: | Size: 624 KiB |