---
id: "hex-tiling"
title: "Hex-tiling"
domain: "materials"
stage: "material"
realtime: "realtime"
platforms: [webgl2, webgpu, desktop-gpu, mobile-gpu, unity, unreal, godot, blender]
year_introduced: 2022
inputs: [texture]
outputs: [texture]
style: "photoreal"
dynamic: "both"
cost: "cheap"
authority: "Mikkelsen"
url: "https://texelatlas.vercel.app/t/hex-tiling/"
sources_verified_at: "2026-11-29"
---
# Hex-tiling (Mikkelsen)

> Mikkelsen's practical hexagonal tiling: break texture repetition by randomly rotating, offsetting and blending three overlapping hex cells per pixel. Simple, cheap and fits into existing shaders.

## Reach for it when

- repeating texture pattern is obvious across terrain
- tiling visible on large floors and walls
- need a cheap drop-in way to hide repetition
- textures look copy-pasted over big surfaces

## How it works

A hexagonal grid is overlaid on UV space. For each pixel the three nearest hex centres are found and each gets a pseudo-random offset (and optionally rotation or mirroring) hashed from its cell id. The texture is sampled once per cell and the three results are blended with weights that fall from 1 at the cell centre to 0 at the edge. To avoid contrast loss in the blend, the weights are sharpened with a power function and, for detail textures, the variance can be rescaled in a histogram-preserving way (as in Heitz-Neyret). For normal maps the three fetched normals should be combined carefully (for example as surface gradients) so lighting stays consistent. Mip level selection uses analytic gradients per cell to avoid seams.

## When to use it

Choose it when you want a drop-in anti-tiling operator for terrain, floors and walls with stochastic textures. Prefer [Histogram-preserving blending (stochastic texturing)](https://texelatlas.vercel.app/t/histogram-preserving-blending.md) when contrast must be exactly preserved. Prefer [Image quilting](https://texelatlas.vercel.app/t/image-quilting.md) or authored variation for structured patterns where blending would ghost. Use with [Triplanar mapping](https://texelatlas.vercel.app/t/triplanar-mapping.md) for rocks.

## Cost

cheap — Three fetches per texture plus a hash and weight computation.
Measured GPU Weight: 3.88× baseline (light) — 0.1276 ms median / 0.1349 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 3.28× baseline (light) — 0.0522 ms median (2.44× faster on L4).
Ampere A100 scaling: 2.4× baseline (light) — 0.0692 ms median (1.84× faster on A100).

## Failure modes

- Ghosting and loss of contrast in the blend regions, especially on high-frequency textures
- Visible hex structure if offsets are too small or the texture has strong directional features
- Mip seams if derivatives from the transformed coordinates are not used
- Rotation of an anisotropic or directional texture causes lighting direction mismatches on normal maps

## Engine support

- babylonjs: builtin — `pbrMaterial.textureRepetitionMode (hex tiling mode) + textureRepetitionHexTilingParams` (evidence: https://github.com/BabylonJS/Babylon.js/blob/9.38.0/packages/dev/core/src/Materials/PBR/pbrBaseMaterial.pure.ts, checked 2026-12-01) — WebGL2/WebGPU only.
- threejs: official — `MaterialXLoader hextile node (examples/jsm/loaders/materialx/MaterialXHextile.js)` (evidence: https://github.com/mrdoob/three.js/blob/r187/examples/jsm/loaders/materialx/MaterialXHextile.js, checked 2026-12-01) — Via MaterialX hextile; not a general material option.
- unity: official — `Shader Graph samples > Terrain Sample > Hex layer nodes (LayerHex)` (evidence: https://github.com/Unity-Technologies/Graphics/blob/557f6ac22b948284f57ffae6a789751fd1f63620/Packages/com.unity.shadergraph/Documentation~/Shader-Graph-Sample-Terrain-Shaders.md, checked 2026-12-01) — Shipped as a Shader Graph sample (Terrain Sample), not a core node.

## Dataflow

- Inputs: texture
- Outputs: texture
- Platforms: webgl2, webgpu, desktop-gpu, mobile-gpu, unity, unreal, godot, blender

## Presets

### Repeating tiles (left) vs stochastic hex-grid tiling (right) (glsl-fragment; rendered 2026-11-29)

```json
{
  "TILES": 6,
  "BLEND_POW": 7
}
```

```glsl
// Stochastic hex-grid tiling: a triangle grid picks 3 random offsets per fragment and blends them
// with contrast-sharpened barycentric weights. Left: ordinary repeating tiles. Right: hex tiling.
const float TILES = 6.0;
const float BLEND_POW = 7.0;

vec3 tex(vec2 uv) {
  vec2 f = fract(uv);
  vec3 c = vec3(0.5 + 0.18 * sin(6.2832 * f.x + 1.0) * sin(12.566 * f.y));
  c *= vec3(0.9, 0.8, 0.65);
  c = mix(c, vec3(0.08, 0.06, 0.05), smoothstep(0.17, 0.1, length(f - vec2(0.3, 0.65))));
  c = mix(c, vec3(0.9, 0.85, 0.7), smoothstep(0.02, 0.0, abs(length(f - vec2(0.72, 0.3)) - 0.12)));
  c = mix(c, vec3(0.7, 0.2, 0.15), smoothstep(0.025, 0.0, abs(f.x - f.y * 0.5 - 0.4)));
  return c;
}
vec2 h2(vec2 p) { return fract(sin(vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)))) * 43758.5453); }
vec3 hexTex(vec2 uv) {
  vec2 sk = mat2(1.0, -0.57735027, 0.0, 1.15470054) * (uv * 3.4641016);
  vec2 base = floor(sk); vec2 tt = fract(sk);
  vec3 bary = vec3(tt, 1.0 - tt.x - tt.y);
  vec2 v1, v2, v3; vec3 w;
  if (bary.z > 0.0) { v1 = base; v2 = base + vec2(0.0, 1.0); v3 = base + vec2(1.0, 0.0); w = vec3(bary.z, bary.y, bary.x); }
  else { v1 = base + vec2(1.0, 1.0); v2 = base + vec2(1.0, 0.0); v3 = base + vec2(0.0, 1.0); w = vec3(-bary.z, 1.0 - bary.y, 1.0 - bary.x); }
  w = pow(w, vec3(BLEND_POW)); w /= (w.x + w.y + w.z);
  return tex(uv + h2(v1)) * w.x + tex(uv + h2(v2)) * w.y + tex(uv + h2(v3)) * w.z;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 uv = fragCoord / iResolution.xy * TILES;
  vec3 col = fragCoord.x < 0.5 * iResolution.x ? tex(uv) : hexTex(uv);
  if (abs(fragCoord.x - 0.5 * iResolution.x) < 1.0) col = vec3(1.0);
  fragColor = vec4(pow(col, vec3(1.0 / 2.2)), 1.0);
}

```

Attribution: written for this index

## Lineage

- extends [Histogram-preserving blending (stochastic texturing)](https://texelatlas.vercel.app/t/histogram-preserving-blending.md)

## Combines with

- [Surface gradient based bump mapping framework](https://texelatlas.vercel.app/t/surface-gradient-bump-mapping.md): Blends the three hex-cell normals as surface gradients so shading stays consistent.

## Combination ideas

- [One phone photo, a whole floor](https://texelatlas.vercel.app/ideas/one-photo-endless-material/)

## Sources

1. [primary] Morten S. Mikkelsen Practical Real-Time Hex-Tiling. JCGT 2022. https://jcgt.org/published/0011/03/05 (verified via http on 2026-11-29)
2. [implementation] mmikk (2022) mmikk/hextile-demo. https://github.com/mmikk/hextile-demo License: MIT. (verified via github on 2026-11-29)

## Cite this entry

Texel. "Hex-tiling." https://texelatlas.vercel.app/t/hex-tiling/ (accessed 2026-12-01).
