{
 "id": "hex-tiling",
 "title": "Hex-tiling",
 "aliases": [],
 "domain": "materials",
 "subdomain": "texture synthesis",
 "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",
 "summary": "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.",
 "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": "Choose it when you want a drop-in anti-tiling operator for terrain, floors and walls with stochastic textures. Prefer `histogram-preserving-blending` when contrast must be exactly preserved. Prefer `image-quilting` or authored variation for structured patterns where blending would ghost. Use with `triplanar-mapping` for rocks.",
 "cost": {
  "class": "cheap",
  "notes": "Three fetches per texture plus a hash and weight computation."
 },
 "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"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://jcgt.org/published/0011/03/05",
   "type": "web",
   "title": "Practical Real-Time Hex-Tiling",
   "authors": [
    "Morten S. Mikkelsen"
   ],
   "year": null,
   "venue": "JCGT 2022",
   "url": "https://jcgt.org/published/0011/03/05",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261128090215/https://jcgt.org/published/0011/03/05/",
     "timestamp": "20261128090215"
    },
    "page_title": null,
    "host": "jcgt.org",
    "title_confirmed_by_page": false,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://jcgt.org/published/0011/03/05 → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "mikkelsenpractical"
  },
  {
   "role": "implementation",
   "key": "gh:mmikk/hextile-demo",
   "type": "code",
   "title": "mmikk/hextile-demo",
   "description": "demonstrates hex-tiling",
   "authors": [
    "mmikk"
   ],
   "year": 2022,
   "venue": "GitHub",
   "url": "https://github.com/mmikk/hextile-demo",
   "ids": {
    "repo": "mmikk/hextile-demo"
   },
   "license": "MIT",
   "extra": {
    "stars": 1038,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2022-08-25T21:11:53Z",
    "language": "C++",
    "homepage": null,
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmikk/hextile-demo",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmikk/hextile-demo",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmikk/hextile-demo",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmikk/hextile-demo",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmikk/hextile-demo",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmikk/hextile-demo",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "mmikk2022mmikk"
  }
 ],
 "presets": [
  {
   "id": "hex-tiling-specimen",
   "title": "Repeating tiles (left) vs stochastic hex-grid tiling (right)",
   "runtime": "glsl-fragment",
   "params": {
    "TILES": 6,
    "BLEND_POW": 7
   },
   "code": "// Stochastic hex-grid tiling: a triangle grid picks 3 random offsets per fragment and blends them\n// with contrast-sharpened barycentric weights. Left: ordinary repeating tiles. Right: hex tiling.\nconst float TILES = 6.0;\nconst float BLEND_POW = 7.0;\n\nvec3 tex(vec2 uv) {\n  vec2 f = fract(uv);\n  vec3 c = vec3(0.5 + 0.18 * sin(6.2832 * f.x + 1.0) * sin(12.566 * f.y));\n  c *= vec3(0.9, 0.8, 0.65);\n  c = mix(c, vec3(0.08, 0.06, 0.05), smoothstep(0.17, 0.1, length(f - vec2(0.3, 0.65))));\n  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)));\n  c = mix(c, vec3(0.7, 0.2, 0.15), smoothstep(0.025, 0.0, abs(f.x - f.y * 0.5 - 0.4)));\n  return c;\n}\nvec2 h2(vec2 p) { return fract(sin(vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)))) * 43758.5453); }\nvec3 hexTex(vec2 uv) {\n  vec2 sk = mat2(1.0, -0.57735027, 0.0, 1.15470054) * (uv * 3.4641016);\n  vec2 base = floor(sk); vec2 tt = fract(sk);\n  vec3 bary = vec3(tt, 1.0 - tt.x - tt.y);\n  vec2 v1, v2, v3; vec3 w;\n  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); }\n  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); }\n  w = pow(w, vec3(BLEND_POW)); w /= (w.x + w.y + w.z);\n  return tex(uv + h2(v1)) * w.x + tex(uv + h2(v2)) * w.y + tex(uv + h2(v3)) * w.z;\n}\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = fragCoord / iResolution.xy * TILES;\n  vec3 col = fragCoord.x < 0.5 * iResolution.x ? tex(uv) : hexTex(uv);\n  if (abs(fragCoord.x - 0.5 * iResolution.x) < 1.0) col = vec3(1.0);\n  fragColor = vec4(pow(col, vec3(1.0 / 2.2)), 1.0);\n}\n",
   "basis": "original",
   "license_note": "written for this index",
   "execution_fidelity": "faithful-pass",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-29",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "hex-tiling",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-29T15:51:50.471Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.6452,
      "std": 0.0963,
      "unique_colors": 122
     },
     "image": "/specimens/hex-tiling-specimen.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "histogram-preserving-blending",
  "triplanar-mapping",
  "surface-gradient-bump-mapping",
  "image-quilting"
 ],
 "extends": [
  "histogram-preserving-blending"
 ],
 "supersedes": [],
 "combines_with": [
  {
   "id": "surface-gradient-bump-mapping",
   "why": "Blends the three hex-cell normals as surface gradients so shading stays consistent."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/materials/hex-tiling.json"
 },
 "solves": [
  "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"
 ],
 "authority": "Mikkelsen",
 "url": "https://texelatlas.vercel.app/t/hex-tiling/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 3.88,
  "tier": "light",
  "p50_ms": 0.1276,
  "p95_ms": 0.1349,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "hex-tiling-specimen",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 3.28,
   "tier": "light",
   "p50_ms": 0.0522,
   "p95_ms": 0.0526,
   "speedup_x": 2.44,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 2.4,
   "tier": "light",
   "p50_ms": 0.0692,
   "p95_ms": 0.0693,
   "speedup_x": 1.84,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}