{
 "id": "basis-universal-ktx2",
 "title": "Basis Universal / KTX2 supercompression",
 "aliases": [
  "Basis Universal",
  "KTX2",
  "UASTC"
 ],
 "domain": "performance",
 "subdomain": "texture compression",
 "stage": "performance",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu"
 ],
 "year_introduced": 2019,
 "inputs": [
  "texture"
 ],
 "outputs": [
  "texture"
 ],
 "style": "both",
 "dynamic": "both",
 "summary": "A supercompressed texture format stored in KTX2 that transcodes at load time into whichever GPU format the device supports, such as BC7, ASTC or ETC2.",
 "how_it_works": "The encoder writes an intermediate format, either ETC1S for small files or UASTC for high quality, then compresses it further with Zstandard in a KTX2 container. At load, a small WebAssembly or native transcoder converts blocks directly into the target GPU block format with little work per block, and the result uploads without decoding to RGBA.\n\nOne asset therefore ships to browsers and devices with different texture support, giving small download sizes and small video memory use at once.",
 "when_to_use": "Choose it for web and cross-platform delivery where the target format is unknown, for example glTF with KHR_texture_basisu. Prefer `block-texture-compression` pre-encoded per platform when you control the device set and want the best quality. Prefer PNG or JPEG for size-insensitive small textures.",
 "cost": {
  "class": "cheap",
  "notes": "Runtime cost is transcoding at load; GPU cost equals that of the chosen block format."
 },
 "failure_modes": [
  "ETC1S shows blocky colour and loses fine detail, especially on normals",
  "Transcoding adds load-time latency without a worker",
  "Quality at a given size is below a dedicated encoder per format",
  "Alpha and HDR need extra care"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "gh:binomialllc/basis_universal",
   "type": "code",
   "title": "BinomialLLC/basis_universal",
   "description": "Basis Universal GPU Texture Codec",
   "authors": [
    "BinomialLLC"
   ],
   "year": 2019,
   "venue": "GitHub",
   "url": "https://github.com/BinomialLLC/basis_universal",
   "ids": {
    "repo": "BinomialLLC/basis_universal"
   },
   "license": "Apache-2.0",
   "extra": {
    "stars": 3158,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-10-30T18:07:49Z",
    "language": "C++",
    "homepage": null,
    "license_name": "Apache License 2.0"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/BinomialLLC/basis_universal",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/BinomialLLC/basis_universal",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/BinomialLLC/basis_universal",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/BinomialLLC/basis_universal",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/BinomialLLC/basis_universal",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/BinomialLLC/basis_universal",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "binomialllc2019binomialllc"
  },
  {
   "role": "primary",
   "key": "url:https://registry.khronos.org/KTX/specs/2.0/ktxspec.v2.html",
   "type": "web",
   "title": "KTX File Format Specification Version 2.0",
   "authors": [
    "Mark Callow"
   ],
   "year": null,
   "venue": "registry.khronos.org",
   "url": "https://registry.khronos.org/KTX/specs/2.0/ktxspec.v2.html",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261118030330/https://registry.khronos.org/KTX/specs/2.0/ktxspec.v2.html",
     "timestamp": "20261118030330"
    },
    "page_title": "KTX File Format Specification",
    "host": "registry.khronos.org",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://registry.khronos.org/KTX/specs/2.0/ktxspec.v2.html → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://registry.khronos.org/KTX/specs/2.0/ktxspec.v2.html → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "http",
     "endpoint": "GET https://registry.khronos.org/KTX/specs/2.0/ktxspec.v2.html → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "http",
     "endpoint": "GET https://registry.khronos.org/KTX/specs/2.0/ktxspec.v2.html → 200",
     "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": 0.95,
   "__bib": "callowfile"
  },
  {
   "role": "implementation",
   "key": "gh:khronosgroup/ktx-software",
   "type": "code",
   "title": "KhronosGroup/KTX-Software",
   "description": "KTX (Khronos Texture) Library and Tools",
   "authors": [
    "KhronosGroup"
   ],
   "year": 2013,
   "venue": "GitHub",
   "url": "https://github.com/KhronosGroup/KTX-Software",
   "ids": {
    "repo": "KhronosGroup/KTX-Software"
   },
   "license": "NOASSERTION",
   "extra": {
    "stars": 1415,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-11-17T22:44:51Z",
    "language": "C++",
    "homepage": null,
    "license_name": "Other"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/KhronosGroup/KTX-Software",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/KhronosGroup/KTX-Software",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/KhronosGroup/KTX-Software",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/KhronosGroup/KTX-Software",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/KhronosGroup/KTX-Software",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/KhronosGroup/KTX-Software",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "khronosgroup2013khronosgroupb"
  }
 ],
 "presets": [
  {
   "id": "basis-universal-ktx2-live",
   "title": "Basis Universal / KTX2 — 4x4 ETC1S codebook endpoint quantization (left) vs transcoded UASTC/BC7 PBR shading (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_BLOCK_SCALE": 6,
    "P_QUANT_LEVELS": 0.55,
    "P_GRID_VIS": 0.5,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_BLOCK_SCALE = 6.00; // P 4x4 Block Scale [2.0, 12.0, 0.5]\nconst float P_QUANT_LEVELS = 0.55; // P Endpoint Quant [0.15, 1.0, 0.05]\nconst float P_GRID_VIS = 0.50; // P Block Grid Vis [0.0, 1.0, 0.05]\nconst float P_SPLIT = 0.48; // P ETC1S / UASTC [0.0, 1.0, 0.02]\n\nvec2 rot2(vec2 p, float a) {\n  float c = cos(a);\n  float s = sin(a);\n  return vec2(c * p.x - s * p.y, s * p.x + c * p.y);\n}\n\n// Rich multi-frequency PBR surface albedo + micro-normal texture mapped onto sphere\nvec3 evalTexAlbedo(vec2 tuv) {\n  vec2 p = tuv * 5.0;\n  float wave = sin(p.x * 3.0 + sin(p.y * 2.4) * 1.6) * 0.5 + 0.5;\n  float rings = smoothstep(0.35, 0.65, sin(length(fract(p * 0.5) - 0.5) * 28.0));\n  vec3 cA = vec3(0.14, 0.52, 0.78);\n  vec3 cB = vec3(0.94, 0.44, 0.18);\n  vec3 cC = vec3(0.92, 0.86, 0.68);\n  vec3 base = mix(cA, cB, wave);\n  return mix(base, cC, rings * 0.42);\n}\n\nfloat luma(vec3 c) {\n  return dot(c, vec3(0.299, 0.587, 0.114));\n}\n\n// Simulate 4x4 GPU block compression (ETC1S single-color-endpoint + 2-bit intensity modifier per texel)\nvec3 encodeETC1SBlock(vec2 tuv, float blocksPerUnit, float quantStr) {\n  vec2 bCoord = tuv * blocksPerUnit;\n  vec2 bId = floor(bCoord);\n  vec2 sub = floor(fract(bCoord) * 4.0) / 4.0;\n  vec2 blockCenter = (bId + 0.5) / blocksPerUnit;\n\n  // Compute block mean chroma endpoint (ETC1S shares one base RGB555 endpoint per 4x4 block!)\n  vec3 c0 = evalTexAlbedo((bId + vec2(0.25, 0.25)) / blocksPerUnit);\n  vec3 c1 = evalTexAlbedo((bId + vec2(0.75, 0.25)) / blocksPerUnit);\n  vec3 c2 = evalTexAlbedo((bId + vec2(0.25, 0.75)) / blocksPerUnit);\n  vec3 c3 = evalTexAlbedo((bId + vec2(0.75, 0.75)) / blocksPerUnit);\n  vec3 baseEp = (c0 + c1 + c2 + c3) * 0.25;\n  float bits = mix(14.0, 4.0, quantStr);\n  baseEp = floor(baseEp * bits + 0.5) / bits;\n\n  // Per-texel 2-bit selector modifies only luminance around the shared block endpoint\n  vec3 texVal = evalTexAlbedo((bId + sub + 0.125) / blocksPerUnit);\n  float dL = luma(texVal) - luma(baseEp);\n  float sel = floor(clamp(dL * 5.0 + 2.0, 0.0, 3.0)) - 1.5;\n  return clamp(baseEp + vec3(sel * 0.10), 0.0, 1.0);\n}\n\nvec3 aces(vec3 x) {\n  x = max(x, 0.0);\n  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  float screenX = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  float bScale = clamp(P_BLOCK_SCALE, 2.0, 14.0);\n  float qStr = clamp(P_QUANT_LEVELS, 0.1, 1.0);\n  float gVis = clamp(P_GRID_VIS, 0.0, 1.0);\n\n  vec3 ro = vec3(0.0, 0.22, 2.15);\n  vec3 rd = normalize(vec3(uv.x, uv.y - 0.05, -1.48));\n  vec3 lDir = normalize(vec3(0.58, 0.72, 0.52));\n  vec3 col = mix(vec3(0.05, 0.07, 0.11), vec3(0.14, 0.19, 0.28), smoothstep(-0.5, 0.5, uv.y));\n\n  // Textured floor swatch showing flat 4x4 KTX2 texel blocks clearly\n  float tMin = 1e5;\n  int hitId = 0;\n  vec3 hp = vec3(0.0);\n  vec3 hn = vec3(0.0, 1.0, 0.0);\n  vec2 tuv = vec2(0.0);\n\n  if (rd.y < -0.005) {\n    float tf = (-0.54 - ro.y) / rd.y;\n    if (tf > 0.05 && tf < 14.0) {\n      tMin = tf; hitId = 1; hp = ro + rd * tf; hn = vec3(0.0, 1.0, 0.0);\n      tuv = hp.xz * 0.42 + vec2(iTime * 0.05, 0.0);\n    }\n  }\n\n  // Hero rotating PBR sphere showcasing transcoded KTX2 texture fidelity\n  vec3 sc = vec3(0.0, 0.02, 0.0);\n  vec3 oc = ro - sc;\n  float b = dot(oc, rd), d = b * b - (dot(oc, oc) - 0.54 * 0.54);\n  if (d > 0.0) {\n    float ts = -b - sqrt(d);\n    if (ts > 0.05 && ts < tMin) {\n      tMin = ts; hitId = 2; hp = ro + rd * ts; hn = normalize(hp - sc);\n      vec3 rn = hn;\n      rn.xz = rot2(rn.xz, iTime * 0.35);\n      tuv = vec2(atan(rn.z, rn.x) / 6.2831853 + 0.5, acos(clamp(rn.y, -1.0, 1.0)) / 3.1415926);\n    }\n  }\n\n  if (hitId > 0) {\n    float blocks = bScale * (hitId == 2 ? 4.5 : 3.2);\n    vec3 alb;\n    float gridLine = 0.0;\n    if (screenX < split) {\n      // Left: Low-bitrate ETC1S supercompressed 4x4 block endpoints + block boundary grid\n      alb = encodeETC1SBlock(tuv, blocks, qStr);\n      vec2 bf = fract(tuv * blocks);\n      gridLine = smoothstep(0.06, 0.015, min(min(bf.x, 1.0 - bf.x), min(bf.y, 1.0 - bf.y)));\n    } else {\n      // Right: High-quality UASTC -> BC7/ASTC GPU-native transcoded texture with crisp micro-details\n      alb = evalTexAlbedo(tuv);\n    }\n\n    float ndl = max(dot(hn, lDir), 0.0);\n    float spec = (hitId == 2) ? pow(max(dot(reflect(-lDir, hn), -rd), 0.0), 36.0) * 0.72 : 0.0;\n    float fres = (hitId == 2) ? pow(1.0 - max(dot(hn, -rd), 0.0), 4.0) * 0.45 : 0.0;\n    vec3 shaded = alb * (0.24 + 0.96 * ndl) + vec3(0.85, 0.92, 1.0) * (spec + fres);\n    shaded = mix(shaded, vec3(0.18, 0.94, 1.0), gridLine * gVis * 0.55);\n    col = (hitId == 1) ? mix(col, shaded, exp(-tMin * 0.14)) : shaded;\n  }\n\n  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));\n  col = mix(col, vec3(0.95, 0.98, 1.0), sep);\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "basis-universal-ktx2",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T21:07:05.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.6494,
      "std": 0.1203,
      "min": 0.4306,
      "max": 0.9191
     },
     "image": "/specimens/basis-universal-ktx2-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "block-texture-compression",
  "draco-mesh-compression"
 ],
 "extends": [
  "block-texture-compression"
 ],
 "supersedes": [],
 "combines_with": [
  {
   "id": "draco-mesh-compression",
   "why": "Both shrink glTF delivery size: one compresses geometry, the other textures."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/performance/basis-universal-ktx2.json"
 },
 "solves": [
  "textures too large to download in a web app",
  "one texture file must work on desktop and mobile gpus",
  "gltf textures eat vram and load slowly",
  "don't know which gpu compressed format the device supports"
 ],
 "authority": "BinomialLLC, 2019",
 "url": "https://texelatlas.vercel.app/t/basis-universal-ktx2/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 3.53,
  "tier": "light",
  "p50_ms": 0.1162,
  "p95_ms": 0.1167,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "basis-universal-ktx2-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 3.03,
   "tier": "light",
   "p50_ms": 0.0482,
   "p95_ms": 0.0487,
   "speedup_x": 2.41,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 2.53,
   "tier": "light",
   "p50_ms": 0.0729,
   "p95_ms": 0.0731,
   "speedup_x": 1.59,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}