bevy_symbios_texture
Procedural, tileable texture generation for Bevy.
Generates albedo, normal, and roughness (ORM) maps entirely on the CPU — no asset files required. All surface textures are seamlessly tileable by construction via toroidal 4-D noise mapping. Alpha-masked card textures (leaf, twig, window, stained glass, iron grille) produce per-pixel transparency and do not tile.
Bevy compatibility
| bevy_symbios_texture | Bevy |
|---|---|
| 0.3 | 0.18 |
Installation
[]
= "0.3"
# Optional: egui editor panel (required for the texture_viewer example)
= { = "0.3", = ["egui"] }
Quick start
Synchronous (blocking)
Suitable for startup systems or contexts where a small generation time is acceptable.
use *;
use ;
Asynchronous (non-blocking, recommended)
Offloads pixel math to a private, bounded rayon thread pool (capped at 4
concurrent tasks) so the main thread is never stalled. On WASM, falls back to
Bevy's AsyncComputeTaskPool.
use *;
use ;
Dropping a PendingTexture entity before generation completes sets a
cancellation flag; tasks that have not yet started exit without doing any work.
Generators
Surface textures (tileable)
All tileable generators produce three seamlessly-repeating maps:
| Map | Format | Contents |
|---|---|---|
albedo |
Rgba8UnormSrgb |
Base colour |
normal |
Rgba8Unorm |
Tangent-space normal (R=X, G=Y, B=Z) |
roughness |
Rgba8Unorm |
ORM: R=Occlusion, G=Roughness, B=Metallic |
Upload with [map_to_images] to get repeat-wrapping samplers.
Bark
Domain-warped FBM noise with an anisotropic Worley plate layer for rhytidome furrows, producing fibrous, streaked bark grain.
use BarkConfig;
let config = BarkConfig ;
Rock
Ridged multifractal noise for cracked, faceted stone.
use RockConfig;
let config = RockConfig ;
Ground
Blended dual-scale FBM for organic soil / dirt surfaces.
use GroundConfig;
let config = GroundConfig ;
Brick
Grid-based SDF with per-cell colour hashing and configurable mortar/bonding pattern.
use BrickConfig;
let config = BrickConfig ;
Plank
Anisotropic grain FBM with domain warp, Worley knots, and horizontal joint gaps. Each plank row has an independent de-correlated grain phase.
use PlankConfig;
let config = PlankConfig ;
Concrete
Smooth FBM surface relief with optional horizontal formwork-panel seams and scattered air-pocket pits.
use ConcreteConfig;
let config = ConcreteConfig ;
Metal
Brushed-metal (anisotropic FBM scratches) or standing-seam roof panels, with optional rust-patch weathering.
use ;
let config = MetalConfig ;
Shingle
Overlapping roof shingles or tiles with configurable profile shape, moss growth, and staggered bonding.
use ShingleConfig;
let config = ShingleConfig ;
Pavers
Square or flat-top hexagonal paving stones with grout joints, per-stone colour variance, and a rounded-box SDF bevel.
use ;
let config = PaversConfig ;
Stucco
High-frequency FBM bumps over a flat matte base — typical of sand-float or pebble-dash exterior render. Entirely matte with zero metallic response.
use StuccoConfig;
let config = StuccoConfig ;
Ashlar
Irregular cut-stone masonry with per-block colour variance, chisel-edge darkening, and configurable mortar joints.
use AshlarConfig;
let config = AshlarConfig ;
Cobblestone
Voronoi cell decomposition producing domed, irregularly shaped stones separated by mud/dirt gaps.
use CobblestoneConfig;
let config = CobblestoneConfig ;
Marble
Domain-warped FBM noise passed through a sinusoidal vein function for polished marble or granite with thin dark veins on a light background.
use MarbleConfig;
let config = MarbleConfig ;
Thatch
Dense fibrous roofing material with anisotropic straw fibres, lateral domain-warp wiggle, and layered bundle overlap shadows.
use ThatchConfig;
let config = ThatchConfig ;
Corrugated
Corrugated metal sheets with sine-wave ridges and valley-concentrated rust weathering.
use CorrugatedConfig;
let config = CorrugatedConfig ;
Asphalt
Three-band toroidal FBM (macro staining, micro roughness, aggregate flecks) for tarmac / asphalt with exposed stone chips.
use AsphaltConfig;
let config = AsphaltConfig ;
Wainscoting
Wood-panel wainscoting with recessed panel faces, rail/stile framing, and anisotropic grain FBM with domain warp.
use WainscotingConfig;
let config = WainscotingConfig ;
Encaustic
Decorative ceramic tiles with glazed surfaces in configurable geometric patterns (checkerboard, octagon, diamond).
use ;
let config = EncausticConfig ;
Alpha-masked cards
Card generators produce an RGBA8 texture where albedo.alpha encodes the
silhouette (0 = fully transparent, 255 = fully opaque). Upload with
[map_to_images_card] so the sampler does not tile and the alpha silhouette
does not bleed at edges.
Leaf
A discrete leaf silhouette with procedural venation: midrib, secondary veins, a Perlin venule (tertiary vein) network, Worley capillaries, and optional lobed margins.
use LeafConfig;
let config = LeafConfig ;
LeafSampler can also be used directly for per-pixel evaluation without
going through the full generator (e.g., inside a twig compositor):
use ;
let sampler = new;
if let Some = sampler.sample
Twig
A composite foliage card: a tapered, organically curved stem carrying multiple leaf cards. Supports two phyllotaxis modes:
- Monopodial (
sympodial: false) — opposite leaf pairs on a straight axis with a terminal leaf at the apex. - Sympodial (
sympodial: true) — alternate leaves on a zigzag axis, with a terminal leaf at the apex.
use FRAC_PI_2;
use TwigConfig;
use LeafConfig;
let config = TwigConfig ;
Window
An SDF-based window card with configurable frame, mullions/muntins, and per-pane glass. The alpha channel is transparent outside the frame and semi-transparent over glass panes.
use WindowConfig;
let config = WindowConfig ;
Stained Glass
Voronoi-based stained-glass panel with lead came borders and semi-transparent coloured glass panes. Glass alpha is 180 (semi-transparent); lead is 255 (fully opaque).
use StainedGlassConfig;
let config = StainedGlassConfig ;
Iron Grille
Rectangular or round-bar iron grille / portcullis with configurable bar count and joint-concentrated rust weathering.
use IronGrilleConfig;
let config = IronGrilleConfig ;
Evolutionary parameter search (genetics)
All config types implement symbios_genetics::Genotype, making them
compatible with the evolutionary algorithms in the symbios-genetics crate
(SimpleGA, Nsga2, MapElites).
Each field is independently perturbed during mutation and drawn uniformly from one of two parents during crossover:
use Genotype;
use BarkConfig;
use SeedableRng;
let mut config = default;
let mut rng = seed_from_u64;
config.mutate; // perturb each field with 30 % probability
let parent_b = BarkConfig ;
let child = config.crossover;
The texture_viewer example uses this to mutate any displayed material when
you click Mutate.
The Genotype implementations and the egui editor widgets are generated by
declarative macros (impl_genotype! / impl_config_editor!) rather than
hand-written per-config boilerplate. Each macro invocation declares the
config struct, field kinds (seed, f64, colour, enum, etc.), and optional
post-hooks for tiling-invariant fixups. This keeps the genetics and UI
modules concise (~400 and ~550 lines respectively) while covering all 23
config types.
Architecture
TextureGenerator (trait)
│
│ Tileable surface textures
├── BarkGenerator ─── ToroidalNoise (domain-warped FBM + Worley plates)
├── RockGenerator ─── ToroidalNoise (RidgedMulti)
├── GroundGenerator ─── ToroidalNoise × 2 (dual-scale FBM)
├── BrickGenerator ─── ToroidalNoise FBM + rounded-box SDF grid
├── PlankGenerator ─── ToroidalNoise FBM + Worley knots (anisotropic)
├── ConcreteGenerator ─── ToroidalNoise FBM + cosine formwork + pit FBM
├── MetalGenerator ─── ToroidalNoise FBM (brushed/standing-seam) + rust FBM
├── ShingleGenerator ─── ToroidalNoise FBM + sawtooth overlap ramp
├── PaversGenerator ─── ToroidalNoise FBM + square/hex SDF grid
├── StuccoGenerator ─── ToroidalNoise FBM (high-frequency, matte)
├── AshlarGenerator ─── ToroidalNoise FBM + irregular SDF grid + chisel edge
├── CobblestoneGenerator─── toroidal Voronoi (domed F1, mud gap at F2−F1)
├── MarbleGenerator ─── ToroidalNoise FBM (domain-warped sinusoidal veins)
├── ThatchGenerator ─── ToroidalNoise FBM (anisotropic fibre + sawtooth layers)
├── CorrugatedGenerator ─── sine-wave ridge profile + rust FBM
├── AsphaltGenerator ─── ToroidalNoise FBM × 3 (macro/micro/aggregate)
├── WainscotingGenerator─── ToroidalNoise grain FBM + panel margin SDF
├── EncausticGenerator ─── ToroidalNoise glaze FBM + geometric pattern SDF
│
│ Alpha-masked cards
├── LeafGenerator ─── LeafSampler (silhouette + venation)
├── TwigGenerator ─── LeafSampler × N (composite stem + leaves)
├── WindowGenerator ─── rounded-box SDF frame/mullions + FBM grime
├── StainedGlassGenerator── toroidal Voronoi + lead came SDF + grime FBM
└── IronGrilleGenerator ─── bar SDF grid + joint rust FBM
│
height_to_normal() → normal map
linear_to_srgb() → albedo encoding
│
TextureMap { albedo, normal, roughness }
│
map_to_images() → GeneratedHandles (repeat sampler)
map_to_images_card() → GeneratedHandles (clamp sampler)
│
full mipmap chain (type-correct averaging)
Noise-in-constructor — all generators build their noise objects
(Fbm<Perlin>, RidgedMulti<Perlin>, ToroidalNoise<…>) once in new()
and store them as struct fields. Calling generate() multiple times (e.g.
to produce size variants of the same material) skips the initialisation cost.
The only exception is Worley, which contains an Rc and is therefore
!Send; generators that use Worley noise (BarkGenerator, PlankGenerator)
construct it inside generate() so the struct remains Send for async tasks.
Workspace buffer pooling — generators that allocate large intermediate
grids (e.g. BarkGenerator, ThatchGenerator) accept an optional
[Workspace] via generate_with_workspace(). The workspace maintains a
pool of Vec<f64> buffers that are borrowed and returned across calls,
eliminating repeated 128 MB+ allocations at 4096×4096 resolution.
Seamless tiling is provided by [ToroidalNoise], which maps 2-D UV
coordinates onto a 4-D torus so that noise wraps perfectly at every edge:
nx = cos(2π·u) · frequency
ny = sin(2π·u) · frequency
nz = cos(2π·v) · frequency
nw = sin(2π·v) · frequency
Because cos(0) = cos(2π) and sin(0) = sin(2π), u=0 and u=1 always
resolve to the same 4-D point, guaranteeing zero-seam tiling.
Normal maps are derived from the height field via central-difference gradients. For the tileable surface textures the neighbours wrap toroidally, so the normals are also seamless. For card textures (Leaf, Twig, Window, Stained Glass, Iron Grille) the boundary uses clamp-to-edge so normals do not bleed across the transparent silhouette border.
Colour encoding uses a 4096-entry sRGB lookup table (built once via
OnceLock) to avoid repeated f32::powf calls during rasterisation.
A 256-entry table would be insufficient because the sRGB curve is steep
near zero; 4096 bins keep the maximum quantisation error well below one
count in u8.
Mipmap generation is performed by map_to_images / map_to_images_card
using a 2×2 box filter with type-correct averaging: sRGB values are decoded to
linear light before averaging and re-encoded afterward (avoiding dark mipmaps),
normal-map XYZ vectors are averaged and renormalized (avoiding zero-length
normals in PBR shaders), and ORM values are averaged directly in linear space.
16× anisotropic filtering is enabled on all samplers.
Running the viewer example
Displays an interactive material viewer with three columns: albedo (left), normal map (centre), and a spinning 3-D PBR cube (right) with the generated material applied. An egui panel on the left lets you cycle through all 23 generators with < Prev / Next >, trigger a random Mutate (rate = 0.3), and edit every parameter live.
License
MIT — see LICENSE.