Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1d792a7
Brush alphas: retired alphas leave the shelf but still load
Rebornim Dec 3, 2026
0213fe6
Brush alphas: pointed and faceted stars with a Points control replace…
Rebornim Dec 3, 2026
bd25fbd
Brush alphas: circle, square, triangle and cross outlines that thicke…
Rebornim Dec 3, 2026
428d5b2
Brush alphas: flat, rounded, double, bent and chevron arrows pointing up
Rebornim Dec 3, 2026
030d503
Brush alphas: bell, cone, pyramid and dome height profiles
Rebornim Dec 3, 2026
b08e704
Brush alphas: round and hex screw heads with five drives replace Rive…
Rebornim Dec 3, 2026
bc74c17
Brush alphas: vent dots, vent holes and a slotted vent plate replace …
Rebornim Dec 3, 2026
46dce99
Brush alphas: bevelled hexagon, square, circle and long hexagon solids
Rebornim Dec 3, 2026
47b78bc
Brush alphas: the shape labels' naming note and the alpha count
Rebornim Dec 3, 2026
2ef3910
Brush alphas: paint chips, dirt blots and a fur tuft replace Chips, G…
Rebornim Dec 4, 2026
ce3e60b
Brush alphas: scratch, crack, splash and seam stamps, one per job, re…
Rebornim Dec 4, 2026
9173a24
Brush alphas: Hairline crack web is one even web of thin cracks with …
Rebornim Dec 4, 2026
7a7f966
Brush alphas: Hairline crack web has faint cracks and strong ones tha…
Rebornim Dec 4, 2026
441421d
Brush alphas: Hairline crack web is mostly faint fine cracks with a f…
Rebornim Dec 4, 2026
6d55487
Brush alphas: Hairline crack web keeps its cracks near one quiet tone…
Rebornim Dec 4, 2026
66915b8
Brush alphas: Hairline crack web is a web of straight hairlines, stro…
Rebornim Dec 4, 2026
9670b09
Brush alphas: each stamp type in its own file under a singular stamp …
Rebornim Dec 4, 2026
751aa78
Brush alphas: stamp constants named, clearer names and comments, reti…
Rebornim Dec 4, 2026
4bef415
Brush alphas: every look constant named or commented, seed offsets na…
Rebornim Dec 4, 2026
257d560
Brush alphas: a blank line after the guard that stops shortening a ha…
Rebornim Dec 4, 2026
19a85d0
Brush alphas: the hex head's face radius and the strand point count e…
Rebornim Dec 4, 2026
f014c20
Brush alphas: the shelf keeps each category's alphas together, so a p…
Rebornim Dec 4, 2026
4997bc5
Brush alphas: a scratch returns nothing at once for a pixel wider off…
Rebornim Dec 4, 2026
215a287
Brush alphas: the hairline crack web has larger cells and fewer split…
Rebornim Dec 4, 2026
7ef91f1
Brush alphas: scratches, splashes and stitches leave room in their bo…
Rebornim Dec 4, 2026
295429c
Brush alphas: a screw head's face sits below its rim crest, the round…
Rebornim Dec 4, 2026
3cd4157
Brush alphas: the bent arrow's shaft ends inside the stamp, and an od…
Rebornim Dec 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/engine/src/tool_cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ pub fn specs() -> Vec<CommandSpec> {
always,
brush
),
cmd!("alpha.list", "List brush alphas", [], None, "{} — procedural alphas and the built-in library", always, |_, _| Ok(json!({
cmd!("alpha.list", "List brush alphas", [], None, "{} — procedural alphas and the library (onShelf false: retired)", always, |_, _| Ok(json!({
"procedural": BrushAlpha::ALL.map(BrushAlpha::label),
"library": alphas::library().iter().map(|alpha| {
let parameters: Vec<_> = alpha.options().iter().map(|option| json!({
"name": option.control.key(), "label": option.label, "min": option.minimum, "max": option.maximum,
"default": option.default, "integer": option.control.whole_number(),
})).collect();
json!({"id": alpha.id, "label": alpha.label, "category": alpha.category, "parameters": parameters})
json!({"id": alpha.id, "label": alpha.label, "category": alpha.category, "onShelf": alpha.on_shelf(), "parameters": parameters})
}).collect::<Vec<_>>(),
}))),
cmd!(
Expand Down
30 changes: 30 additions & 0 deletions crates/engine/tests/it/fill_alpha_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,33 @@ fn an_import_and_a_legacy_resource_keep_their_own_pixels_when_picking_an_alpha()
assert_eq!(reopened.library_alpha(&name).unwrap().id, alpha.id);
}
}

/// A retired alpha is off the shelf but still listed (marked) and still accepted by id, so saved brushes, fills and scripts keep working
#[test]
fn a_retired_alpha_is_marked_in_the_list_and_still_works_by_id() {
let (mut session, layer) = fill();
let list = execute(&mut session, "alpha.list", &Value::Null).unwrap();
let on_shelf = |id: &str| list["library"].as_array().and_then(|all| all.iter().find(|alpha| alpha["id"] == id)).map(|alpha| alpha["onShelf"].clone());
assert_eq!(on_shelf("speckle"), Some(json!(false)), "{list}");
assert_eq!(on_shelf("scratch_field"), Some(json!(true)));

execute(&mut session, "tool.brush", &json!({"alpha": {"library": "speckle"}})).unwrap();
assert_eq!(session.tool.brush.alpha_library.as_deref(), Some("speckle"));
execute(&mut session, "layer.fill.set", &json!({"layer": layer.0, "channel": "roughness", "alpha": "Stencil A"})).unwrap();
let name = resource_name(alphas::find("letter_a").unwrap());
assert_eq!(source(&session, layer, Channel::Roughness), Source::image(name));
}

/// Retired alphas stay findable, so a saved picture of one reopens as that alpha; it fails if find or reopen skips retired alphas
#[test]
fn saved_pictures_of_retired_alphas_reopen_as_those_alphas() {
for id in ["star_5", "chips", "rivet", "bolt_head", "scratches"] {
let (mut session, layer) = fill();
execute(&mut session, "layer.fill.set", &json!({"layer": layer.0, "channel": "roughness", "alpha": id})).unwrap();
let Source::Image { name, .. } = source(&session, layer, Channel::Roughness) else { panic!("{id}: alpha image") };

let reopened = Session::from_project_file(session.project_file()).unwrap();

assert_eq!(reopened.library_alpha(&name).map(|alpha| alpha.id.as_str()), Some(id));
}
}
4 changes: 2 additions & 2 deletions crates/engine/tests/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ fn brush_presets_apply_save_and_load() {
assert!(list.as_array().unwrap().len() >= 12);
execute(&mut s, "tool.brush", &json!({"size": 30})).unwrap();
let b = execute(&mut s, "brush.preset.apply", &json!({"preset": "Scratches"})).unwrap();
assert_eq!((b["alpha"]["library"].as_str(), b["followPath"].as_bool()), (Some("scratches"), Some(true)));
assert_eq!((b["alpha"]["library"].as_str(), b["followPath"].as_bool()), (Some("scratch_field"), Some(true)));
assert!((b["size"].as_f64().unwrap() - 30.0).abs() < 1e-3, "presets keep the size");
assert!(execute(&mut s, "tool.stroke", &json!({"points": [[160, 200], [240, 200]]})).unwrap()["stamps"].as_u64().unwrap() > 0);
// Saved and loaded back onto another brush, the stroke returns and the size stays.
Expand All @@ -760,7 +760,7 @@ fn brush_presets_apply_save_and_load() {
execute(&mut s, "brush.preset.apply", &json!({"preset": "basic_soft"})).unwrap();
execute(&mut s, "tool.brush", &json!({"size": 10})).unwrap();
let b = execute(&mut s, "brush.preset.load", &json!({"path": path})).unwrap();
assert_eq!(b["alpha"]["library"], "scratches");
assert_eq!(b["alpha"]["library"], "scratch_field");
assert!((b["size"].as_f64().unwrap() - 10.0).abs() < 1e-3);
std::fs::write(path, b"{}").unwrap();
assert!(execute(&mut s, "brush.preset.load", &json!({"path": path})).is_err());
Expand Down
94 changes: 91 additions & 3 deletions crates/paint/src/alphas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ pub use crate::alpha_option::AlphaOption;

use crate::brush::smoothstep;

mod hard_surface;
mod shapes;
mod stamp;

/// Size in pixels of the finest mip level.
pub const BASE: usize = 512;
/// Size of the coarsest mip level.
Expand Down Expand Up @@ -61,6 +65,8 @@ pub struct LibraryAlpha {
maker: Maker,
options: &'static [AlphaOption],
image: OnceLock<Arc<AlphaImage>>,
/// Replaced or dropped: off the shelf and the pickers, still found by id and label so saved brushes and fills keep drawing
retired: bool,
}

/// Bound the pixel buffer and supersampling work for a single alpha render
Expand All @@ -72,6 +78,11 @@ impl LibraryAlpha {
self.options
}

/// Whether the shelf and the pickers offer this alpha (see [`shelf`])
pub fn on_shelf(&self) -> bool {
!self.retired
}

/// Keep only this alpha's valid non-default settings.
pub fn sanitized_parameters(&self, params: &LibraryAlphaParams) -> LibraryAlphaParams {
self.options
Expand Down Expand Up @@ -212,8 +223,16 @@ impl AlphaImage {
}

static LIBRARY: LazyLock<Vec<LibraryAlpha>> = LazyLock::new(|| {
let entry = |id: String, label: String, category, options, maker| LibraryAlpha { id, label, category, maker, options, image: OnceLock::new() };
let shapes = SHAPES.iter().map(|&(id, label, cat, options, make)| entry(id.into(), label.into(), cat, options, Maker::Shape(make)));
let entry = |id: String, label: String, category, options, maker| {
let retired = matches!(maker, Maker::Glyph(_)) || RETIRED.contains(&id.as_str());
LibraryAlpha { id, label, category, maker, options, image: OnceLock::new(), retired }
};
let shapes = SHAPES
.iter()
.chain(shapes::SHAPES)
.chain(hard_surface::SHAPES)
.chain(stamp::FAMILIES.iter().flat_map(|family| family.iter()))
.map(|&(id, label, cat, options, make)| entry(id.into(), label.into(), cat, options, Maker::Shape(make)));
let glyphs = GLYPHS
.iter()
.map(|&(c, strokes)| entry(format!("letter_{}", c.to_ascii_lowercase()), format!("Stencil {c}"), LETTERS, &[THICKNESS], Maker::Glyph(strokes)));
Expand All @@ -225,6 +244,45 @@ pub fn library() -> &'static [LibraryAlpha] {
&LIBRARY
}

/// The alphas the shelf and the pickers offer: [`library`] without the retired ones, grouped by category in first-appearance order
pub fn shelf() -> impl Iterator<Item = &'static LibraryAlpha> {
SHELF.iter().copied()
}

static SHELF: LazyLock<Vec<&'static LibraryAlpha>> = LazyLock::new(|| {
let mut categories: Vec<&str> = Vec::new();
for alpha in library() {
if !categories.contains(&alpha.category) {
categories.push(alpha.category);
}
}
let mut shelf: Vec<&LibraryAlpha> = library().iter().filter(|alpha| alpha.on_shelf()).collect();
shelf.sort_by_key(|alpha| categories.iter().position(|&category| category == alpha.category));
shelf
});

/// Alphas taken off the shelf, replaced by a newer look or dropped; every stencil letter is retired too. They still load by id and label
const RETIRED: [&str; 18] = [
"speckle",
"leaf",
"fabric",
"bricks",
"star_5",
"star_6",
"rivet",
"bolt_head",
"screw_slot",
"screw_cross",
"vent",
"chips",
"grunge_spots",
"fur",
"scratches",
"splatter",
"cracks",
"stitches",
];

/// A library alpha by id or label (case, spaces, `_` and `-` ignored).
pub fn find(name: &str) -> Option<&'static LibraryAlpha> {
if let Some(alpha) = library().iter().find(|alpha| alpha.id == name) {
Expand Down Expand Up @@ -770,6 +828,36 @@ mod tests {
assert!(find("STENCIL a").is_some() && find("letter_7").is_some() && find("nope").is_none());
}

#[test]
fn the_shelf_keeps_each_category_together() {
// A picker draws a caption where the category changes, so a category split in two runs shows its caption twice
let mut runs: Vec<&str> = Vec::new();
for alpha in shelf() {
if runs.last() != Some(&alpha.category) {
assert!(!runs.contains(&alpha.category), "{} comes back after {runs:?}", alpha.category);
runs.push(alpha.category);
}
}
assert!(runs.len() > 1);
}

#[test]
fn retired_alphas_leave_the_shelf_but_still_load() {
let on_shelf = |id: &str| shelf().any(|alpha| alpha.id == id);
for id in ["speckle", "letter_a", "letter_7"] {
assert!(!on_shelf(id), "{id} is retired");
let alpha = find(id).unwrap_or_else(|| panic!("{id} still loads"));
assert!(find(&alpha.label).is_some_and(|found| found.id == id), "{id} is still found by its label");
}
assert!(on_shelf("round_soft") && on_shelf("sponge"), "the kept alphas stay");
assert!(shelf().count() < library().len());

// A misspelt retired id would leave the alpha it meant on the shelf
for id in RETIRED {
assert!(find(id).is_some_and(|alpha| alpha.id == id && !on_shelf(id)), "{id} is a library alpha, taken off the shelf");
}
}

#[test]
fn levels_follow_the_stamp_size() {
let img = find("round_hard").map(LibraryAlpha::image).unwrap();
Expand All @@ -791,7 +879,7 @@ mod tests {
#[test]
#[ignore]
fn bench_library_sampling() {
let img = find("scratches").map(LibraryAlpha::image).unwrap();
let img = find("scratch_field").map(LibraryAlpha::image).unwrap();
let t = std::time::Instant::now();
let mut sum = 0.0;
for i in 0..4_000_000u32 {
Expand Down
Loading
Loading