---
id: "wang-tiles"
title: "Wang Tiles (Aperiodic Tile Synthesis)"
aliases: [stochastic tiling with Wang tiles]
domain: "procgen"
stage: "procedural"
realtime: "realtime"
platforms: [cpu, webgl2, webgpu, desktop-gpu, unity, unreal, godot]
year_introduced: 2003
inputs: [texture]
outputs: [texture, layout]
style: "both"
dynamic: "static"
cost: "cheap"
authority: "Cohen et al., 2003"
url: "https://texelatlas.vercel.app/t/wang-tiles/"
sources_verified_at: "2026-11-29"
---
# Wang Tiles (Aperiodic Tile Synthesis) (Cohen et al., 2003)

> 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.

## 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

## 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 use it

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)](https://texelatlas.vercel.app/t/poisson-disk-sampling.md) for one-time point generation, [Wave Function Collapse](https://texelatlas.vercel.app/t/wave-function-collapse.md) for richer adjacency rules and level layouts, and [Worley (Cellular) Noise](https://texelatlas.vercel.app/t/worley-noise.md) for a procedural cell pattern with no stored tiles.

## Cost

cheap — One hash and an atlas lookup per cell; the cost is in precomputing tile content.
Measured GPU Weight: 2.45× baseline (light) — 0.0805 ms median / 0.0832 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 1.94× baseline (feather) — 0.0308 ms median (2.61× faster on L4).
Ampere A100 scaling: 1.57× baseline (feather) — 0.0452 ms median (1.78× faster on A100).

## Failure modes

- 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

## Dataflow

- Inputs: texture
- Outputs: texture, layout
- Platforms: cpu, webgl2, webgpu, desktop-gpu, unity, unreal, godot

## Presets

### Two-colour Wang tiles with automatically matching edges forming paths (glsl-fragment; rendered 2026-11-29)

```json
{
  "TILES": 6
}
```

```glsl
// 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

## Sources

1. [primary] Michael F. Cohen, Jonathan Shade, Stefan Hiller, Oliver Deussen (2003) Wang Tiles for image and texture generation. ACM Transactions on Graphics. https://doi.org/10.1145/882262.882265 (verified via crossref on 2026-11-29)

## Cite this entry

Texel. "Wang Tiles (Aperiodic Tile Synthesis)." https://texelatlas.vercel.app/t/wang-tiles/ (accessed 2026-12-01).
