Wang Tiles (Aperiodic Tile Synthesis)
A small set of square tiles with coloured edges is assembled so adjacent edge colours match, producing non-repeating textures or distributions from a compact atlas that can be looked up per pixel.
Also known as stochastic tiling with Wang tiles
In the family Procedural generation, tiling and texture
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | None found | |
| Babylon.js 9.38.0 | None found | |
| Godot 4.7 | None found | |
| Unity | None found | |
| Unreal 5.7 | None found | |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
Each tile carries a colour on each edge, and a tile set with all edge-colour combinations (for two colours per axis, 16 tiles; a reduced 8-tile set suffices for a scanline order) can tile the plane so every neighbouring pair of edges agrees. Tiles are generated from source patches so content crossing a shared edge colour is identical: for textures, patches are quilted together; for point sets, a stored Poisson disk set per tile makes a precomputed blue-noise distribution. At runtime a pseudo-random choice (or a hash of cell coordinates) picks, for each cell, a tile consistent with its left and top neighbours. This gives non-periodic coverage with a small atlas and constant-time per-pixel evaluation.
When to choose it
Reach for it when
- texture tiling visibly repeats across large surfaces
- non-periodic patterns from a small set of tiles
- tile floors and terrain without obvious seams
- cheap infinite texture without repetition
Choose it for large non-repeating ground textures, blue-noise scattering on the fly (e.g. foliage on a huge terrain) and sampling patterns. Prefer Poisson Disk Sampling (Bridson) for one-time point generation, Wave Function Collapse for richer adjacency rules and level layouts, and Worley (Cellular) Noise for a procedural cell pattern with no stored tiles.
Field marks
- Seams visible if edge colours are matched but the interior features differ in structure
- Few tile colours show repetition: the same motif recurs along rows or columns
- Tile-based blue noise has visible tile boundaries in the power spectrum
- Tile content must be authored per texture; oriented or anisotropic textures need extra care
Presets
Two-colour Wang tiles with automatically matching edges forming paths
{
"TILES": 6
}Show GLSL (24 lines)
// Wang tiles with 2 edge colours: each tile's edge colours come from a hash of the shared edge, so matching is automatic.
const float TILES = 6.0;
float eh(vec2 e, float k) { return step(0.5, fract(sin(dot(e, vec2(12.9898, 78.233)) + k * 31.7) * 43758.5453)); }
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = fragCoord / iResolution.xy * TILES;
vec2 id = floor(uv), f = fract(uv) - 0.5;
float N = eh(id + vec2(0, 1), 1.0), S = eh(id, 1.0), E = eh(id + vec2(1, 0), 2.0), W = eh(id, 2.0);
// quadrant triangles tinted by the edge colour on that side
float side;
if (abs(f.x) > abs(f.y)) side = f.x > 0.0 ? E : W; else side = f.y > 0.0 ? N : S;
vec3 c0 = vec3(0.16, 0.2, 0.35), c1 = vec3(0.95, 0.6, 0.25);
vec3 col = mix(c0, c1, side) * (0.7 + 0.3 * (1.0 - 2.0 * max(abs(f.x), abs(f.y))));
// coloured edges continue as paths through the tile centre, so matching edges form continuous lines
float d = 1e9;
if (N > 0.5) d = min(d, abs(f.x) + step(f.y, 0.0) * 9.0);
if (S > 0.5) d = min(d, abs(f.x) + step(0.0, f.y) * 9.0);
if (E > 0.5) d = min(d, abs(f.y) + step(f.x, 0.0) * 9.0);
if (W > 0.5) d = min(d, abs(f.y) + step(0.0, f.x) * 9.0);
col = mix(col, vec3(0.97, 0.93, 0.8), smoothstep(0.07, 0.055, d));
vec2 g = abs(f);
col = mix(col, vec3(0.03), smoothstep(0.012, 0.0, 0.5 - max(g.x, g.y)));
fragColor = vec4(pow(col, vec3(0.8)), 1.0);
}
Attribution: written for this index
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| wang-tiles-specimen | Tesla T4 1920x1080 | 2.45× baseline (light) · 0.081 ms / 0.083 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| wang-tiles-specimen | NVIDIA L4 1920x1080 | 1.94× baseline (feather) · 0.031 ms / 0.031 ms · 2.6× faster on L4 | opengl-timer-query · Cross-architecture validation |
| wang-tiles-specimen | NVIDIA A100-SXM4-40GB 1920x1080 | 1.57× baseline (feather) · 0.045 ms / 0.045 ms · 1.8× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): its primary source cites Plant Ecosystem Distribution Simulation, Image quilting, Progressive meshes, Weber and Penn parametric tree generation; cited by Histogram-preserving blending (stochastic texturing), Model Synthesis, XDoG edge and stylization filter.
Sources
- primaryMichael F. Cohen, Jonathan Shade, Stefan Hiller, Oliver Deussen (2003). Wang Tiles for image and texture generation. ACM Transactions on Graphics.Verified via crossref · 2026-11-29doi:10.1145/882262.882265