Skip to content

Pattern looks: every starter pattern drawn to tile, with its own controls - #946

Draft
Rebornim wants to merge 76 commits into
storytold:mainfrom
Rebornim:feat/textures-2
Draft

Rebornim wants to merge 76 commits into
storytold:mainfrom
Rebornim:feat/textures-2

Conversation

@Rebornim

@Rebornim Rebornim commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Draft. The pattern looks are done and reviewed: every look below was approved in review except Skin pores, whose redrawn pores are still in review. It stays a draft until the measuring question on storytold/craft-contrib#85 is settled. Done: rebased onto main (after #897); the GPU viewport's opcode range and side-table record for patterns drawn with a look; #930's Clouds, Fine noise, Cells, Crumpled foil and weave looks drawn on the GPU; new or reworked looks for Perlin noise, Voronoi, Smooth fur, Ridged noise, Hammered, Brushed lines, Moss, Pores (skin), Tiles, Bricks, Hexagon tiles, Random tiles, Tread plate, Checker, Stripes, Halftone dots, Wave scales, Gradient, Round gradient, Strip flooring, Herringbone planks, Goose-eye twill, Diamond brocade, Houndstooth, Chevron, Knit, Camouflage and Digital camo, each drawn on the CPU and on the GPU.

Closes #927, closes #943. Carries the commits of closed #930 (pattern looks), rebased onto main.

Not in this PR

  • Grunge, Scratches, Smudges, Streaks and Chips move to an image-based pass, tracked separately.
  • Vertical streaks, fibres and strands, hand-made marks, crystal shards, circular brushing, rusty runs, dried stain runs, caked mud, rust mottling, rock grain, fine wrinkles, wipes, scraped paint, scattered spots, ring stains, fine speckled wear, concrete, plaster, dirt grain, dust patches, gravel grain, cracks, marble veins, leather grain, reptile scales, galvanized spangle, wood grain, knotty wood and bark are not drawn in code in this pass either (judged in review to be out of reach procedurally or better served by scans); they are left to the image-based work.
  • Brush alphas (shapes, stamps, height profiles) are a separate PR.
  • A look drawn at a reduced resolution still draws four samples per texel; making that cheaper changes the drawing, so it is left for a later change.
  • Dropdowns announce their value rather than their label to screen readers (an older widget, not this PR).

What changes

  • Patterns can carry a look (Starter textures: pattern looks and parity for the starter procedurals #930's model): an optional set of controls per kind. A pattern saved before its kind had a look draws exactly as before; kinds added with their look always have one.
  • Perlin noise, Voronoi and Smooth fur gain looks: Smooth noise (Detail, Stretch), Domed cells (Detail, Roundness, Variation) and Fur (Flow: straight, flowing, parted; Waviness). Their hidden drawing values were tuned by comparing exported images (tone distribution, frequency spectrum, strand lengths) with the reference app's exports at matching settings, captured by a person in a separate session; no reference code or files were used. Projects saved before keep the earlier drawings.
  • A new pattern, Ridged noise: thin dark creases between brighter bulges (Detail, Sharpness). Hammered is redrawn as shallow round dents meeting in low ridges (Depth, Roundness, Variation; 55 dents per repeat) and Brushed lines as rows with hard edges, each a smooth streak along the brushing through random tones (Streak length down to 1/512 of the repeat, Rows, Vertical). These two looks only existed on this branch, so no saved project changes; patterns saved without a look keep their earlier drawings. All three draw on the GPU in the existing family opcodes (85 noise, 86 cell fields, 87 strands).
  • A new pattern, Moss: domed clumps at three sizes lit from above, with torn edges, gathered into masses (Coverage, Clump size, Grain). Pores gains a skin look: grainy, mottled skin crossed by three bent networks of fine broken creases, with small, evenly sized pores along the middle network's creases (Pores, Pore size, Creases). Both draw on the GPU in a new moss family (opcode 88).
  • Tiles, Bricks and Hexagon tiles gain looks: square tiles with a soft or sharp edge (Size, Softness, Variation), running or stacked bricks (Mortar, Offset, Bevel, Variation) and hexagon outlines with gaps at the corners over a fill bright in the middle (Outline, Corner gap, Fill, Variation). Two new patterns: Random tiles, rectangles of many sizes whose joints meet in T shapes and never run on past two tiles, some split again (Splits, Gap, Bevel, Variation), and Tread plate, raised rounded bars along each cell's diagonal, turning cell to cell (Bars, Bar length, Bar width, Plate height, Mottling). All five draw on the GPU in a new tile family (opcode 89); patterns saved without a look keep their earlier drawing.
  • Checker, Stripes, Halftone dots, Wave scales and Gradient gain looks: a checker two squares each way per repeat (Variation, Dark squares), stripes slanted whole steps so they tile (Width, Softness, Slant), hard dots on a square grid sized by a ramp, a mirrored ramp or a cloudy tone (Dots, Dot size, Tone), flat scales drawn as concentric lines (Rings, Line width, Outline, Shade) and a ramp in one of four directions (Direction, Mirror, Curve). New pattern: Round gradient, around a centre or outward from it (Around the centre, Centre across, Centre down, Angle, Radius). All six draw on the GPU in the tile family; patterns saved without a look keep their earlier drawing.
  • Strip flooring and Herringbone planks gain looks over one shared wood grain (growth rings bent by a slow wave, fibres and pore dashes along the grain, weathered patches, grit): rows of boards whose end joints wander so they never line up (Rows, Boards, Gap, Variation), and planks meeting at right angles in zig-zags (Zig-zags, Plank length, Gap, Variation). Each board shows the grain from a place of its own, with its own tone. Both draw on the GPU in a new board family; patterns saved without a look keep their earlier drawing.
  • GPU viewport: main composites fill layers on the GPU, so each look family gets its own opcode (81..127) and WGSL, reading a side-table record (period, the kind's hidden values from compose's own tables, the look's controls). A look whose family has no WGSL yet composites on the CPU, never with its kind's earlier drawing.
  • Goose-eye twill and Diamond brocade gain looks, and two new patterns join them, drawn crisp in two tones, one motif per repeat (three by default): nested chevrons folded into diamonds (Bands, Band width); two crossing split bars with diamonds at the corners and edges (Arm width, Arm length, Split); Houndstooth, a dark and a light quarter joined by diagonal teeth (Teeth); Chevron, dashes stepping down and back up into V shapes (Columns, Dash length). Thread shading lays woven threads over any of them. All four draw on the GPU in a new print family; patterns saved without a look keep their earlier drawing.
  • Knit gets a look: columns of V-shaped stitches whose rounded, twisted yarn legs interlock half a row, each stitch with its own tone, under a haze of fine wool fibres (Fuzz, from smooth jersey to wool; Slant, how steeply the legs dive). The scale counts stitch columns per repeat (64 by default). It draws on the GPU in a new knit family; patterns saved without a look keep their earlier drawing.
  • Knit's columns sway, pinch and lean off straight like the jersey references: a new Wander control (0 to 1, 0.5 by default) bends the stitch lattice with smooth noise that repeats with the stitches and varies each stitch's thickness and tone; 0 draws straight columns.
  • Camouflage gains a look: three fields of warped tiling noise cut hard into dark, mid and light blobs over a base, eight blob fields per UV tile so they sit at a woodland pattern's size (Coverage, Wobble); Camouflage saved without a look keeps its earlier drawing. It draws on the GPU in a camouflage family of its own (opcode 93).
  • A new pattern, Digital camo: square blocks in three flat tones, painted by layers of block rectangles so same-tone rectangles merge into stepped shapes (Blocks, Shape size, Dark, Light, Layers); whole-number maths, drawn on the GPU in the tile family.
  • A pattern with a look drawn at a reduced resolution lays out its sample grid inside its first UV tile, on the CPU and in the GPU viewport alike, so on later UV tiles it meets itself exactly at the tile edge (the first UV tile draws as before).

Tests

  • gpu_composite::looks::tests::*_matches_the_cpu: each family on the GPU against the CPU oracle at a UV fill and a triplanar mask (128²), run on Lavapipe.
  • a_pattern_with_a_look_never_composites_as_its_kinds_earlier_drawing.
  • Ran on Lavapipe (llvmpipe, Vulkan; GitHub ubuntu-24.04): cloud_stacks_match_the_cpu, cells_match_the_cpu, crumpled_foil_matches_the_cpu, weaves_match_the_cpu, smooth_noise_matches_the_cpu, domed_cells_match_the_cpu, fur_matches_the_cpu, a_pattern_with_a_look_never_composites_as_its_kinds_earlier_drawing, material_patterns_match_cpu_as_fills_and_masks (unchanged, every kind), package_shaders_validate_and_write_glsl_without_an_adapter: all pass.
  • After the rebase onto main with Keep resized paint sharp and accelerate mask generators and live painting #897 (head 3213b91): cargo test -p texturecraft-compose --lib, cargo test -p texturecraft-core --lib and the Lavapipe list above: pass. Keep resized paint sharp and accelerate mask generators and live painting #897's generator opcode 47 and these look opcodes (81..127) are separate ranges.
  • Before the rebase: cargo test -p texturecraft-core -p texturecraft-texel --lib and cargo test -p texturecraft-engine --test it pattern_looks: pass. xtask layers and xtask wasm: pass. Clippy (-D warnings, Rust 1.95.0) on texel, core, compose, engine: pass; on render and ui-egui it stops at one existing line not touched here (gpu_composite_projection.rs:403, nonminimal_bool), so those two are not fully linted by this run.
  • cargo test -p texturecraft-compose --lib: pass (Fine noise is now a one-octave preset of the cloud stack; same values).
  • Pores (skin pores) and Moss (head c172890): spots_match_the_cpu and the whole Lavapipe look list above, cargo test -p texturecraft-compose --lib, cargo test -p texturecraft-engine --test it pattern_looks, --test session panic_hunt and xtask layers: pass. Clippy (Rust 1.95.0) stops at one existing line not touched here (crates/geom/src/bvh.rs:451, nonminimal_bool), so this change is not linted by that run; xtask wasm not run.
  • Tile, line/dot/ramp and board looks (commits 309aa06, fafc8f8, 1f73f62): on GitHub ubuntu-24.04: the Lavapipe look list (now with tiles_match_the_cpu, lines_dots_and_ramps_match_the_cpu, boards_match_the_cpu), cargo test -p texturecraft-compose -p texturecraft-core --lib, xtask layers, cargo test -p texturecraft-engine --test it pattern_looks and --test session panic_hunt: pass. Clippy (--no-deps -D warnings, Rust 1.95.0): texel, core, compose and render pass; it stops at two existing lines not touched here (gpu_composite_projection.rs:403 nonminimal_bool, layer_pick_list.rs:126 collapsible_match), so ui-egui and engine are not fully linted. These runs caught test gaps in the tile and line commits, fixed in them: looks with no random part at their defaults are no longer asked to change with the seed, the control sweep samples an odd grid so thin mortar and bars aren't missed, and two drawing functions take fewer arguments. xtask wasm not run.
  • Print looks (commit c369032): on GitHub ubuntu-24.04: the Lavapipe look list with prints_match_the_cpu: pass (on 2eb5259, same drawing code). cargo test -p texturecraft-compose -p texturecraft-core --lib: pass. The first compose run caught Diamond brocade's diagonal edges falling exactly on the seam test's sample points (rounding then picked a different side one tile over); every print's motif now sits a fraction of a texel off those points. Engine, ui-egui and clippy: upstream's gate on this PR.
  • Knit stitches (commit ebceca8): on GitHub ubuntu-24.04: the Lavapipe look list with knit_matches_the_cpu: pass; cargo test -p texturecraft-compose -p texturecraft-core --lib: pass (on 58dc5af; the amend only renamed a shader parameter from, a reserved WGSL word, which the first Lavapipe run caught), and the knit unit tests on ebceca8: pass. Engine, ui-egui and clippy: upstream's gate on this PR.
  • Knit Wander, Digital camo, Camouflage and the reduced-resolution fix (head eeb6504, the weathering patterns and Fine wrinkles taken out): on GitHub ubuntu-24.04: the Lavapipe look list with digital_camo_matches_the_cpu, camouflage_matches_the_cpu and knit_matches_the_cpu (47100380025), cargo test -p texturecraft-compose -p texturecraft-core --lib (47100386391), cargo test -p texturecraft-engine --test it -- layers pattern_looks (47100394256): pass. Clippy on the fork runner did not get to our crates: it stops at a nonminimal_bool lint in crates/geom/src/bvh.rs, unchanged from main; clippy for this PR is upstream's gate, which passed on ubuntu-24.04 at eeb6504 (run 47100393657; its Windows leg still running when this was written). Before the removal, on 7bcbf51: cargo test -p texturecraft-compose -p texturecraft-core --lib (47099040402) and cargo test -p texturecraft-engine --test it -- layers pattern_looks (47099124708): pass; on 6c4405d the Lavapipe look list with digital_camo_matches_the_cpu and camouflage_matches_the_cpu: pass (47093246975). Knit's CPU port checked against the prototype: p99 0.5/255. CPU export cost at 4096 against Clouds: Camouflage 1.7x, Digital camo 2.1x. Upstream's gate on 7bcbf51 failed at cargo fmt --check (three files formatted without the repository's rustfmt.toml); fixed in the Knit Wander commit.
  • Random tiles redrawn and the skin pores look taken out (2a3de80), Brushed lines redrawn as rows of streaks (head 23fe219, brushed_matches_the_cpu now allows 0.5 % of texels to round into the next row at a hard row edge): cargo test --release -p texturecraft-compose -p texturecraft-core --lib passed on 2a3de80 (47106741708). On 23fe219: compose + core lib (47108323934), xtask layers, --test it pattern_looks and --test session panic_hunt (47108337233): pass; the Lavapipe look list failed there because the brushed shader named a variable from (a reserved WGSL word), renamed in the same commit (now c3e2f6b), where the Lavapipe look list passes (47110370714). Brushed's export checked against the reference by its statistics (tone spread, streak and row correlation), not pixel for pixel.
  • Review fixes (critic rounds 1-3, commits 1e724f8..01fbcf3): Stripes' negative Slant can be set again through layer.fill.set (a_signed_whole_number_control_crosses_zero_both_ways, fails without the fix); Tread plate's outer bars with no room in their cell are left out instead of drawn as corner slivers (tread_plate_outer_bars_with_no_room_leave_the_corners_bare, fails without it); the GPU viewport lays a reduced-resolution look's grid inside its first UV tile as the CPU does (a_reduced_look_a_whole_uv_tile_over_matches_the_cpu checks the two agree a whole UV tile over; it also passed with the shader change reverted, so it guards the parity and does not show the rounding case); the rest is naming, named constants on both sides, files split one type each, and docs. On e27efe5: the Lavapipe look list (47113388661) and cargo test --release -p texturecraft-compose -p texturecraft-core --lib (47113393563): pass. On 01fbcf3: the Lavapipe look list (47117733252), compose + core lib (47117740225), --test it -- layers pattern_looks and --test session panic_hunt (47117746421) and the fork's full CI (fmt, layers, clippy -D warnings, tests, wasm; ubuntu and Windows, 47117752620): pass.
  • Final review pass (4abe70b..478f77a): the look options Flow, Tone and Direction go in the translation key list; the ToneAndGrain test helper moves to its own file; docs/features.md names the new patterns; a new crash-input sweep, panic_hunt_pattern_looks, sends hostile values to every look control of every pattern. Fork's full CI on 478f77a (ubuntu and Windows, 47122384046): pass. Known and not changed here: dropdowns announce their value rather than their label to screen readers (an older widget, not this PR).
  • Speed changes (f800ba4, 5a272a3, b1012cb; b87ee7b reverted by e1c7337): the output is unchanged; the probe hashed every output value before and after, for every look on both projections. cargo test --release -p texturecraft-compose on e1c7337 (47137664856) and the ui-egui fill_material_rows tests on b1012cb (47133132026): pass. On the final head e1c7337: the Lavapipe look list (47141343927), the fork's full CI (fmt, layers, clippy -D warnings, tests, wasm; ubuntu and Windows, 47141351781) and upstream's gate and parity checks on this PR (ubuntu-24.04 and windows-latest): pass.
  • Skin pores brought back with its pores along the creases (head 3687b9c): on GitHub ubuntu-24.04, the Lavapipe look list with moss_matches_the_cpu now also checking three Skin pores settings, plus shader validation (47152742253), and cargo test --release -p texturecraft-compose --lib with the two new skin pores tests (47152749319): pass. On the same code before two comment and test-only edits (aa7abc7): cargo test --release -p texturecraft-compose -p texturecraft-core --lib (47151060397), xtask layers and --test session panic_hunt (47151068039): pass. The ui-egui filter in that run matched no tests, so the panel rows were not tested. On the final head 3687b9c: the fork's full CI (fmt, layers, clippy -D warnings, the whole workspace's tests, wasm; ubuntu and Windows, 47156510421), upstream's gate and parity checks on this PR (ubuntu-24.04 and windows-latest) and the ui-egui pattern_look_snapshots set with the dark and light themes on a software GPU (47156516967): pass. The Memory section was measured before Skin pores came back.

Optimization

Each row compares the PR code right before the optimization commits (478f77a) with the PR head (e1c7337) on the same workload; release build, GitHub ubuntu-24.04, 4 cores, median of 3 interleaved runs (GitHub run 47137658347). The panel row compares b87ee7b with the same code plus b1012cb (run 47133237775).

Workload and metric Before After Reduction
Smooth fur, 4096² UV-tile fill on 4 threads, wall time 4,880 ms 3,581 ms 26.62%
Smooth fur, 256² UV tile, time per texel 740.4 ns 556.6 ns 24.82%
Smooth fur, 256² triplanar, time per texel 1,704.4 ns 1,602.9 ns 5.96%
Voronoi (Domed cells), 4096² UV-tile fill, wall time 863 ms 650 ms 24.68%
Voronoi, 256² UV tile, time per texel 130.0 ns 111.7 ns 14.08%
Voronoi, 256² triplanar, time per texel 287.2 ns 272.6 ns 5.08%
Hammered, 4096² UV-tile fill, wall time 1,267 ms 1,062 ms 16.18%
Hammered, 256² UV tile, time per texel 188.9 ns 156.8 ns 16.99%
Hammered, 256² triplanar, time per texel 456.7 ns 411.5 ns 9.90%
Moss, 4096² UV-tile fill, wall time 7,413 ms 6,792 ms 8.38%
Moss, 256² UV tile, time per texel 1,301.6 ns 1,166.8 ns 10.36%
Moss, 256² triplanar, time per texel 2,995.8 ns 3,086.1 ns 3.01% more
Smooth fur's Material panel, 300 warm frames, allocations per frame 25,359 calls 25,358 calls 1 fewer

Output: the FNV hash of every output float matched before and after, for every look on both projections and for the four 4096² fills. Every run lies within 1.51% of its median. Tradeoff: Moss on triplanar is 3.01% slower. Triplanar has no period, so nothing is saved there and the change only alters codegen. It stays for the 10.36% on the tiling projections that fills use by default. The other looks, whose code is unchanged, moved within ±1.25%. The panel row is one Vec per frame (24 B) and negligible against egui's ~25,000 allocations per frame. That change stays because the code is one line shorter.
Rejected: wrapping Crumpled foil's 25 crease cells once per row and column (1% faster on a UV tile, 66% slower on triplanar; reverted in e1c7337). Rejected: reading a pattern's look and repeats from one lookup per texel (the flat looks went from 27-35 ns to 34-50 ns per texel).
Not measured: the GPU (the WGSL mirrors are unchanged), Windows and the browser. The 4096² fills call pattern::procedural for every texel (rayon over rows), not the whole layer compositor.

Memory

Drawing a look allocates nothing: 0 allocation calls over 5 × 65,536 texels for every look on both projections, in both versions. Across 300 warm frames the live heap grew by the same 8,960 B in every panel case (uniform source, a look without rows, Moss's three sliders, Smooth fur's choice row). The look rows keep nothing per frame. The GPU lowering appends a few words per look to the program's side table, which is rebuilt with the program. No leak was found, and nothing changed here.

@coderabbitai

coderabbitai Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@autocraft-bot autocraft-bot Bot added missing feature The reference application has it and we do not, or only part of it needs decision Needs a product or scope decision by a maintainer labels Dec 2, 2026
@Rebornim
Rebornim force-pushed the feat/textures-2 branch 15 times, most recently from e9fe15b to def8607 Compare December 3, 2026 10:52
A pattern can now carry a look: its kind's own controls, drawn so it repeats
seamlessly at whole-number scales. Clouds gets a new look, and Soft clouds and
Dark clouds are added. Picking a kind gives it its look; patterns saved before
and every built-in (smart masks, materials, finish filters) keep drawing as
they did, and lookDefaults switches a saved pattern over.

Refs storytold#927
…ushed's seam test allows rounding on its hard row edges
A new pattern of square blocks in three flat tones, painted by layers
of block rectangles so same-tone rectangles merge into stepped blobs
and bars rather than random salt (Blocks, Shape size, Dark, Light,
Layers). Drawn in the tile look family on the GPU, the same as the CPU.
Camouflage gets a look: three fields of warped noise, each cut hard into
dark, mid and light blobs over a base, eight blob fields per UV tile by
default so the blobs sit at the size a woodland pattern has. Coverage
sets how much of the base the blobs cover; Wobble how much their edges
wander. It draws on the GPU as a look family of its own (opcode 93).
Patterns saved without a look keep their earlier drawing.
Knit's stitch columns ran dead straight. The jersey references' columns
drift sideways in long S-curves over a few stitch rows, neighbours
pinching and widening, with each stitch's leg a little thicker or
thinner. A new Wander control (0 to 1, 0.5 by default) bends the
stitch lattice with smooth noise that repeats with the stitches and
varies each stitch's thickness and tone; 0 draws the straight columns
as before. CPU and GPU draw it the same way (knit_matches_the_cpu).
The skin pores look did not reach its reference and moves to the
image-based pass. Pores draws as it did before this pass; Moss stays in
the spots family, which now carries its three controls without a style
word.
Rows of square cells left joints running straight across the whole
repeat. Now every grid corner is a T, the joint running through it
taking turns between across and down, and every joint is two cells long
and moved off its line at random, so tiles come in many widths and
heights. Tiles longer than a cell may be split again (Splits, default
1). Two cells per repeat, so the weave always meets itself; default
scale 5.
…ference measures

Each row (hard edges, centred on whole steps) runs one smooth curve
along the brushing through random tones at evenly spaced knots, shifted
by the row's own random share of a knot. Streak length now reaches
1/512 of the repeat (fine grain) and starts at 0.25 (four knots).
…d for translators

The options reach tr() through their enums' labels, not as literals, so the
translation coverage report never listed Straight, Flowing, Parted, Ramp,
Mirrored, Cloudy, Up, Right, Down or Left; they join the other enum labels
in catalog_keys.
The tone-and-grain measure the look tests share was a struct inside
pattern.rs's tests module; it now lives in pattern/tone_and_grain.rs
(test builds only) as ToneAndGrain::of, one type per file.
docs/features.md counted 58 procedurals but listed none of the kinds this
branch adds and never mentioned looks: whole-number scales that tile, the
kind's own controls, and the earlier drawing kept for saved patterns.
…values

panic_hunt_pattern_looks sends 1e30, -1e30, 0, null, a string, an array,
an object and true to each control of every pattern with a look (and to
an unknown control, to look itself and to lookDefaults) through
layer.fill.set and effect.set, renders after each, and checks that a
refused edit leaves the project and the undo history as they were.
… cells into the period once per row and column
… lean is read only when it reaches the point
Wrapping the 25 cells once per row and column measured no faster on a UV tile and two thirds slower on triplanar (codegen), so the fold loop reads each cell as it did
Pores draws grainy, mottled skin again, crossed by three bent networks of
fine broken creases. Its pores are now small, evenly sized and placed
only along the middle network's creases, instead of scattered over the
skin at random. Pores is now the share of places along those creases
that hold one (0.85 by default). The look rejoins Moss in its family,
which carries a style word again.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

missing feature The reference application has it and we do not, or only part of it needs decision Needs a product or scope decision by a maintainer

Projects

None yet

1 participant