---
id: "basis-universal-ktx2"
title: "Basis Universal / KTX2 supercompression"
aliases: [Basis Universal, KTX2, UASTC]
domain: "performance"
stage: "performance"
realtime: "realtime"
platforms: [webgl2, webgpu, desktop-gpu, mobile-gpu]
year_introduced: 2019
inputs: [texture]
outputs: [texture]
style: "both"
dynamic: "both"
cost: "cheap"
authority: "BinomialLLC, 2019"
url: "https://texelatlas.vercel.app/t/basis-universal-ktx2/"
sources_verified_at: "2026-11-29"
---
# Basis Universal / KTX2 supercompression (BinomialLLC, 2019)

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

## Reach for it when

- 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

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

One 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 it

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 (BC7 / ASTC)](https://texelatlas.vercel.app/t/block-texture-compression.md) 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

cheap — Runtime cost is transcoding at load; GPU cost equals that of the chosen block format.
Measured GPU Weight: 3.53× baseline (light) — 0.1162 ms median / 0.1167 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 3.03× baseline (light) — 0.0482 ms median (2.41× faster on L4).
Ampere A100 scaling: 2.53× baseline (light) — 0.0729 ms median (1.59× faster on A100).

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

## Engine support

- babylonjs: builtin — `KhronosTextureContainer2 / KHR_texture_basisu loader (KTX2 Basis transcoding)` (evidence: https://github.com/BabylonJS/Babylon.js/blob/9.38.0/packages/dev/core/src/Misc/khronosTextureContainer2.ts, checked 2026-12-01)
- godot: builtin — `Import dock > Compress > Mode = Basis Universal (stores KTX2/UASTC/ETC1S)` (evidence: https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/CompressedTexture2D.xml, checked 2026-12-01)
- threejs: official — `import { KTX2Loader } from 'three/addons/loaders/KTX2Loader.js'` (evidence: https://github.com/mrdoob/three.js/blob/r187/examples/jsm/loaders/KTX2Loader.js, checked 2026-12-01)
- unity: official — `Package Manager > KTX for Unity (com.unity.cloud.ktx)` (evidence: https://docs.unity3d.com/Packages/com.unity.cloud.ktx@3.0/manual/index.html, checked 2026-12-01) — Official Unity package (KTX 2.0 / Basis Universal).

## Dataflow

- Inputs: texture
- Outputs: texture
- Platforms: webgl2, webgpu, desktop-gpu, mobile-gpu

## Presets

### Basis Universal / KTX2 — 4x4 ETC1S codebook endpoint quantization (left) vs transcoded UASTC/BC7 PBR shading (right) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_BLOCK_SCALE": 6,
  "P_QUANT_LEVELS": 0.55,
  "P_GRID_VIS": 0.5,
  "P_SPLIT": 0.48
}
```

```glsl
const float P_BLOCK_SCALE = 6.00; // P 4x4 Block Scale [2.0, 12.0, 0.5]
const float P_QUANT_LEVELS = 0.55; // P Endpoint Quant [0.15, 1.0, 0.05]
const float P_GRID_VIS = 0.50; // P Block Grid Vis [0.0, 1.0, 0.05]
const float P_SPLIT = 0.48; // P ETC1S / UASTC [0.0, 1.0, 0.02]

vec2 rot2(vec2 p, float a) {
  float c = cos(a);
  float s = sin(a);
  return vec2(c * p.x - s * p.y, s * p.x + c * p.y);
}

// Rich multi-frequency PBR surface albedo + micro-normal texture mapped onto sphere
vec3 evalTexAlbedo(vec2 tuv) {
  vec2 p = tuv * 5.0;
  float wave = sin(p.x * 3.0 + sin(p.y * 2.4) * 1.6) * 0.5 + 0.5;
  float rings = smoothstep(0.35, 0.65, sin(length(fract(p * 0.5) - 0.5) * 28.0));
  vec3 cA = vec3(0.14, 0.52, 0.78);
  vec3 cB = vec3(0.94, 0.44, 0.18);
  vec3 cC = vec3(0.92, 0.86, 0.68);
  vec3 base = mix(cA, cB, wave);
  return mix(base, cC, rings * 0.42);
}

float luma(vec3 c) {
  return dot(c, vec3(0.299, 0.587, 0.114));
}

// Simulate 4x4 GPU block compression (ETC1S single-color-endpoint + 2-bit intensity modifier per texel)
vec3 encodeETC1SBlock(vec2 tuv, float blocksPerUnit, float quantStr) {
  vec2 bCoord = tuv * blocksPerUnit;
  vec2 bId = floor(bCoord);
  vec2 sub = floor(fract(bCoord) * 4.0) / 4.0;
  vec2 blockCenter = (bId + 0.5) / blocksPerUnit;

  // Compute block mean chroma endpoint (ETC1S shares one base RGB555 endpoint per 4x4 block!)
  vec3 c0 = evalTexAlbedo((bId + vec2(0.25, 0.25)) / blocksPerUnit);
  vec3 c1 = evalTexAlbedo((bId + vec2(0.75, 0.25)) / blocksPerUnit);
  vec3 c2 = evalTexAlbedo((bId + vec2(0.25, 0.75)) / blocksPerUnit);
  vec3 c3 = evalTexAlbedo((bId + vec2(0.75, 0.75)) / blocksPerUnit);
  vec3 baseEp = (c0 + c1 + c2 + c3) * 0.25;
  float bits = mix(14.0, 4.0, quantStr);
  baseEp = floor(baseEp * bits + 0.5) / bits;

  // Per-texel 2-bit selector modifies only luminance around the shared block endpoint
  vec3 texVal = evalTexAlbedo((bId + sub + 0.125) / blocksPerUnit);
  float dL = luma(texVal) - luma(baseEp);
  float sel = floor(clamp(dL * 5.0 + 2.0, 0.0, 3.0)) - 1.5;
  return clamp(baseEp + vec3(sel * 0.10), 0.0, 1.0);
}

vec3 aces(vec3 x) {
  x = max(x, 0.0);
  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
  float screenX = fragCoord.x / max(iResolution.x, 1.0);
  float split = clamp(P_SPLIT, 0.0, 1.0);
  float bScale = clamp(P_BLOCK_SCALE, 2.0, 14.0);
  float qStr = clamp(P_QUANT_LEVELS, 0.1, 1.0);
  float gVis = clamp(P_GRID_VIS, 0.0, 1.0);

  vec3 ro = vec3(0.0, 0.22, 2.15);
  vec3 rd = normalize(vec3(uv.x, uv.y - 0.05, -1.48));
  vec3 lDir = normalize(vec3(0.58, 0.72, 0.52));
  vec3 col = mix(vec3(0.05, 0.07, 0.11), vec3(0.14, 0.19, 0.28), smoothstep(-0.5, 0.5, uv.y));

  // Textured floor swatch showing flat 4x4 KTX2 texel blocks clearly
  float tMin = 1e5;
  int hitId = 0;
  vec3 hp = vec3(0.0);
  vec3 hn = vec3(0.0, 1.0, 0.0);
  vec2 tuv = vec2(0.0);

  if (rd.y < -0.005) {
    float tf = (-0.54 - ro.y) / rd.y;
    if (tf > 0.05 && tf < 14.0) {
      tMin = tf; hitId = 1; hp = ro + rd * tf; hn = vec3(0.0, 1.0, 0.0);
      tuv = hp.xz * 0.42 + vec2(iTime * 0.05, 0.0);
    }
  }

  // Hero rotating PBR sphere showcasing transcoded KTX2 texture fidelity
  vec3 sc = vec3(0.0, 0.02, 0.0);
  vec3 oc = ro - sc;
  float b = dot(oc, rd), d = b * b - (dot(oc, oc) - 0.54 * 0.54);
  if (d > 0.0) {
    float ts = -b - sqrt(d);
    if (ts > 0.05 && ts < tMin) {
      tMin = ts; hitId = 2; hp = ro + rd * ts; hn = normalize(hp - sc);
      vec3 rn = hn;
      rn.xz = rot2(rn.xz, iTime * 0.35);
      tuv = vec2(atan(rn.z, rn.x) / 6.2831853 + 0.5, acos(clamp(rn.y, -1.0, 1.0)) / 3.1415926);
    }
  }

  if (hitId > 0) {
    float blocks = bScale * (hitId == 2 ? 4.5 : 3.2);
    vec3 alb;
    float gridLine = 0.0;
    if (screenX < split) {
      // Left: Low-bitrate ETC1S supercompressed 4x4 block endpoints + block boundary grid
      alb = encodeETC1SBlock(tuv, blocks, qStr);
      vec2 bf = fract(tuv * blocks);
      gridLine = smoothstep(0.06, 0.015, min(min(bf.x, 1.0 - bf.x), min(bf.y, 1.0 - bf.y)));
    } else {
      // Right: High-quality UASTC -> BC7/ASTC GPU-native transcoded texture with crisp micro-details
      alb = evalTexAlbedo(tuv);
    }

    float ndl = max(dot(hn, lDir), 0.0);
    float spec = (hitId == 2) ? pow(max(dot(reflect(-lDir, hn), -rd), 0.0), 36.0) * 0.72 : 0.0;
    float fres = (hitId == 2) ? pow(1.0 - max(dot(hn, -rd), 0.0), 4.0) * 0.45 : 0.0;
    vec3 shaded = alb * (0.24 + 0.96 * ndl) + vec3(0.85, 0.92, 1.0) * (spec + fres);
    shaded = mix(shaded, vec3(0.18, 0.94, 1.0), gridLine * gVis * 0.55);
    col = (hitId == 1) ? mix(col, shaded, exp(-tMin * 0.14)) : shaded;
  }

  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));
  col = mix(col, vec3(0.95, 0.98, 1.0), sep);
  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}
```

Attribution: MIT — written for this index.

## Lineage

- extends [Block texture compression (BC7 / ASTC)](https://texelatlas.vercel.app/t/block-texture-compression.md)

## Combines with

- [Draco mesh compression](https://texelatlas.vercel.app/t/draco-mesh-compression.md): Both shrink glTF delivery size: one compresses geometry, the other textures.

## Sources

1. [primary] BinomialLLC (2019) BinomialLLC/basis_universal. https://github.com/BinomialLLC/basis_universal License: Apache-2.0. (verified via github on 2026-11-29)
2. [primary] Mark Callow KTX File Format Specification Version 2.0. registry.khronos.org. https://registry.khronos.org/KTX/specs/2.0/ktxspec.v2.html (verified via http on 2026-11-29)
3. [implementation] KhronosGroup (2013) KhronosGroup/KTX-Software. https://github.com/KhronosGroup/KTX-Software License: NOASSERTION. (verified via github on 2026-11-29)

## Cite this entry

Texel. "Basis Universal / KTX2 supercompression." https://texelatlas.vercel.app/t/basis-universal-ktx2/ (accessed 2026-12-01).
