# ultra-fast-texture > WebGPU runtime texture compression for the browser: WebP / PNG / JPEG / AVIF images become BC7, BC5, BC4, BC1, ASTC 4×4 / 6×6 / 8×8 or ETC2 / EAC GPU textures with full mip chains, in milliseconds of GPU time, at load time. No WASM, no CPU encoder, no offline KTX2 pipeline. Includes a three.js loader (three 0.186.x, WebGPURenderer) and a GLTFLoader plugin. MIT, plain ESM with TypeScript declarations. Status: pre-release 0.0.0; the v0.1 API is frozen. Key facts: - Entry points: `ultra-fast-texture` (core, three-free, worker-safe: `createTextureEncoder`, `createDevice`, `getCapabilities`, `selectFormat`, `sniffImage`, `FORMATS`, `UFTError`, `VERSION`, `ENCODER_VERSION`), `ultra-fast-texture/three` (`UltraFastTextureLoader`, `UFTTexture`, `SLOTS`), `ultra-fast-texture/gltf` (`GLTFUltraFastTexturePlugin`, `registerUltraFastTexture`), `ultra-fast-texture/vite` (`uftVitePlugin`, `optimizeProject`, `optimizeAsset`, `optimizeGlbBytes`, `auditAssets`, `scanProjectCode`, `watchAssets`, `detectTextureSemantic`, `rightSizeRgba`, `encodeSmartImage`, `initProject`, `createMcpServer`, `startMcpServer`, `convertFileToRCD1`, `convertGlbBytesToRCD1`, `convertGltfToRCD1`, `encodeRgbaToRCD1`, `extractGlbTextures`), `ultra-fast-texture/worker.js` (static worker for strict CSP). - Semantics decide formats: `color` (sRGB; BC7 / ASTC 4×4 / ETC2), `data` (linear: ORM, roughness, metalness), `normal` (tangent; BC5 / EAC RG11, three rebuilds Z), `normal-rgb` (clearcoat / object space), `r` (one channel read as .r: AO, bump, alpha; BC4 / EAC R11), `rg`. Policy order BC → ASTC → ETC2 → RGBA8 fallback with mips. `bitrate: 'medium' | 'low'` selects ASTC 6×6 / 8×8 where supported, then tries BC1 / ETC2 RGB for opaque colour and data. - `roughnessMap` reads .g and `metalnessMap` reads .b in three: never use `r` for them; use `data`. - three loader: `new UltraFastTextureLoader( renderer )`, `await loader.loadAsync( url, { semantic } )`; `load()` is synchronous after `await loader.init()` and swaps a placeholder for the compressed texture; `flipY` defaults to true; receipts in `texture.userData.ultraFastTexture`; WebGL backend → plain three textures. - glTF: `registerUltraFastTexture( new GLTFLoader(), loader )`; pre-scans materials for semantics; blocking: `loadAsync` resolves with every texture compressed; report in `gltf.userData.ultraFastTexture`. - Core: `const encoder = await createTextureEncoder( device ); const out = await encoder.encode( source, { semantic } )` → `out.texture` (GPUTexture, every mip), `out.format`, `out.release()`. Resolves at `queue.submit`; never waits for the GPU. Sources: URL, Request, Response, Blob, ArrayBuffer, ImageBitmap, VideoFrame, ImageData, canvases, HTMLImageElement, `{ data, width, height }` RGBA8, same-device RGBA8 GPUTexture. - Opt-in: `worker: 'decode' | 'full'` (falls back to the main thread, never rejects), `cache: 'persistent'` (KTX2 in Cache Storage), `exportKTX2` / `importKTX2` (device-specific). - CSP: works under `script-src 'self'` without 'unsafe-eval' or 'wasm-unsafe-eval'; worker mode needs `worker-src blob:` or `workerURL`. - Limits: WebGPU required; ≈ 4096² max source on default devices (`createDevice( { requiredLimits: 'adapter' } )` lifts it); three's default device lacks texture-compression-unaligned (758×600 → 760×600; `createDevice()` enables unaligned sizes except affected Apple compressed mip widths); no HDR, BC3 or punch-through; 'high' tier = 'default' in v0.1; output bit-exact per adapter only. - Selective loading: normal page encoding loads BC7, BC4/BC5, BC1, ASTC 4×4, ASTC 6×6/8×8, ETC2 or EAC as needed, each with both tiers. Default warmup is ['color']; warmup: [] defers codec loading to first encode. Full workers retain complete-family loading. Built-in decode workers use a separate small payload. - Size (min + brotli q11, build 0.0.0+8a5d4f4e491c, 2026-11-03): eager core 12,215 B (budget 16,000, met); `codecs/bc` family 7,498 B; `codecs/astc` family 9,416 B (budget 10,000, met); `codecs/etc` family 7,042 B; selected BC7 kernel 3,901 B; first BC7 texture through three, everything included, 36,523 B; decode worker client 4,371 B. Loading every format increases total bytes. See dist/sizes.json and PERFORMANCE.md. - All-codec GPU kernel speeds (Apple M3 Max, Chrome 156, hardware `timestamp-query`, 2026-11-03, all mip levels down to 1×1, `fast` / `default`): - Full BC7 intake + mips + kernel: `0.16 / 0.42 ms` (`1024²`, 11 levels), `1.03 / 2.19 ms` (`4096×2048`, 13 levels; kernel only `0.33–0.46 / 1.29 ms`). - `ASTC 4×4` (`2048×1024`, 12 levels): `0.20 / 0.71 ms`; `ASTC 6×6` / `8×8` (`2048×1024`, 12 levels): `0.53 / 0.96 ms` & `0.62 / 1.04 ms`. - `ETC2 RGB` (`4096×2048`, 13 levels): `0.94 / 10.16 ms`; `ETC2 RGBA` (`1024×512`, 11 levels): `0.45 / 1.19 ms`. - `BC5` / `EAC RG11` normal (`2048×1024`, 12 levels): `0.13 / 0.79 ms` & `0.99 / 1.96 ms`. - `BC4` / `EAC R11` single-channel (`1024²`, 11 levels): `0.06 / 0.42 ms` & `1.30 / 2.08 ms`; `BC1` (`4096×2048`, 13 levels): `0.51 / 0.78–1.15 ms`. - 3 Runtime-Supported GPU Delivery Formats ("What to Use When", measured on Apple M3 Max, 4-texture 3.1 MP scene → BC7): 1. `avif-fast` (64×64 SB + Sharp-YUV / automatic 4:4:4 chroma on normals & sharp chroma edges, grayscale `data` `4:2:0` with `enable-cfl-intra=0`, WebCodecs `VideoFrame` GPU YUV→RGB fast path, no CDEF/restoration): default for general 3D web, `.glb` & single textures (`294.2 KiB`, `35.91 dB`, `4.12 ms` warm batch / `3.29 ms` 1-tex, `49.5 ms` single cold local, `10.96 ms` @ 1 Gbps; `-q lossless` gives exact identity-matrix RGBA lossless). 2. `webp-fast` (`-f 0` zero loopfilter + tandem BC7 preconditioning, single-frame WebP by default; optional `--strips 4` `ANMF`): universal drop-in WebP (`337.9 KiB`, `3.94 ms` warm batch / `1.41 ms` earth, `8.12 ms` warm in High tier at `40.62 dB`; `-q lossless` gives exact RGBA lossless). 3. `rcd1` (`0x31444352`, `.rcd` universal compact GPU Golomb-Rice + 8×8 IDCT with 6 channel modes `r`, `xy-normal`, `rg`, `la`, `ycocg`, `ycocg-a`, automatic grayscale promotion, `f16` quantizers & Lagrangian RDOQ): **0.00 ms CPU image decode** (14-asset corpus as shipped in `samples/corpus/delivery/`, `step = 8`: `1,863.4 KiB` at `39.92 dB` mean PSNR, CLI default `1,944.4 KiB` at `40.74 dB`; `AVIF-Fast` is `1,850.4 KiB` at `43.18 dB` and `WebP-Fast` is `1,663.2 KiB` at `42.61 dB`, so at equal PSNR `rcd1` needs about 1.28× the bytes of `avif-fast` and 1.10× those of `webp-fast`, or 1.62× and 1.17× from the upstream three.js originals. Against Basis UASTC `.ktx2` after BC7, paired with the smallest `rcd1` file at least as sharp, `rcd1` is smaller and faster in 13 of 16 settings, 2.5–3.6× smaller at RDO 3–6. Warm 1-tex: `3.58 ms` for brick 1024² at `step = 8` (`236.6 KiB` at `32.40 dB`, 2026-11-16 run); with the 2026-11-03 files, `4.94 ms` 4-tex warm and `6.84 ms` High tier at `41.37 dB`, #1 PSNR in that tier). - Experimental multi-texture batch containers (`av1-stream` `.ivf` and `webp-atlas` / `avif-atlas` `UFAT`) live in `bench/delivery/` for research benchmarking and have no runtime decoder in `src/`; use `--atlas` or `--remap-uv` for standard MaxRects atlases. - Automatic optimization CLI (`npx uft` / `npx ultra-fast-texture`) & MCP server: - `npx uft audit [--check] [--fail-on high|any] [--json]`: scans `.glb`/`.gltf`, images, and JS/TS code (`scanProjectCode` for loader/material slot hints), infers semantics via filename + pixels, computes RGBA8 vs UFT GPU VRAM, and flags duplicates, constant textures, unpacked AO+MR pairs, over-authored resolutions, and Three.js slot risks (`--check` exits non-zero on CI blocking issues). - `npx uft optimize [--in-place] [--clean] [--rewrite-refs] [--manifest] [--force] [-f auto|avif-fast|webp-fast|rcd1] [--zero-cpu] [--min-psnr ] [--max-size ] [--dry-run] [--json]`: runs lossless GLB hygiene (dedupe + AO/MR -> ORM packing), shrinks constant textures (`>16×16`) to `8×8`, detail-aware `2×` downscales only when global `PSNR >= 45 dB` and worst `8×8` patch `PSNR >= 38 dB`, enforces closed-loop PSNR quality floors, protects `.glb` files with a whole-GLB never-inflate guard, optionally removes replaced originals (`--clean`), rewrites code/glTF references (`--rewrite-refs`), or tracks companion `.uft-manifest.json` idempotency (`--manifest`). - `npx uft watch [--dir ]`: debounced recursive watcher re-optimizing modified images and `.glb`/`.gltf` models while ignoring self-writes. - `npx uft init [--dir ] [--json]`: wires `uftVitePlugin()` into `vite.config.*`, adds `optimize:assets` / `audit:assets` / `watch:assets` npm scripts + `ci` workflow snippets, and installs `.agents/skills/ultra-fast-texture/`. - `npx ultra-fast-texture mcp`: zero-dependency stdio MCP JSON-RPC 2.0 server exposing `uft_audit_assets`, `uft_optimize_assets`, `uft_detect_semantic`, and `uft_setup_project`. - Texture & `.glb`/`.gltf` conversion CLI tools (work everywhere, zero external npm/crate dependencies required): - Node CLI (`tools/uft-convert.mjs`): `npx uft-convert [-f rcd1|avif-fast|webp-fast] [-o ] [--out-dir ] [--step 8] [--quality lossless|ultra|high|default|fast|low] [--semantic color|data|normal|normal-rgb|rg|r] [--channel-mode auto|r|xy-normal|rg|la|ycocg|ycocg-a] [--source-channel r|g|b|a] [--slow] [--atlas] [--remap-uv] [--extract] [--in-place] [--verify] [--json]`. Pure Node.js (`>=22`) PNG/PNM/RGBA + GLB/glTF v2 binary parser/builder + automatic system bridge (`dwebp`/`ffmpeg`/`sips`/`magick`/`cwebp`/`avifenc --stdin`) for WebP/AVIF/JPEG. Directly rewrites embedded `.glb`/`.gltf` textures (including `BLEND`/`MASK` alpha textures via native `la` / `ycocg-a`) to `rcd1`, `avif-fast`, or `webp-fast`. - Standalone Rust CLI & crate (`tools/uft-rcd1-rs/`): `cargo build --release --manifest-path tools/uft-rcd1-rs/Cargo.toml` (zero external crates, 100% bit-exact with JS across all 6 channel modes, compiles in ~1 s on macOS/Linux/Windows/CI) and `pnpm convert:rs -o --step 8 --verify`. - Native Runtime Support (`ultra-fast-texture`, `ultra-fast-texture/three`, `ultra-fast-texture/gltf`): `createTextureEncoder`, `UltraFastTextureLoader`, and `registerUltraFastTexture` decode `.rcd` files and embedded `image/x-uft-rcd1` `.glb` `bufferViews` (named by `texture.extensions.EXT_uft_texture_rcd1.source`, required when the texture has no other image) natively on the GPU (`fusedRcd` zero-RGBA-intermediate prep + lazy `dctP` compile). - Vite & production bundler integration: - Zero-config ESM for standard WebP/AVIF/PNG/JPEG/GLB in Vite, webpack 5, Rollup, esbuild, Next.js (no `new URL(import.meta.url)`). - Automatic & query-based Vite plugin (`import { uftVitePlugin } from 'ultra-fast-texture/vite'` or `'./tools/vite-plugin-uft.mjs'`): - `uftVitePlugin()` (zero options) defaults to `format: 'auto'`, `autoGlb: true`, `convertPublic: 'glb'` (optimizing `public/*.glb` in `outDir` while leaving `public/` images untouched unless `convertPublic: true`), smart image optimization (`avif-fast` / `webp-fast` on >= 4 KiB images), and closed-loop PSNR + GLB hygiene (`optimize: true`). Passing explicit `step`, `emitCompanionRcd`, or `forceRcd1` keeps `'rcd1'` defaults; pass `auto: false` for query-only mode, `auto: 'all'` to convert all images in any format, or `?no-rcd1`/`?no-uft` to bypass. - Explicit query imports (`import url from './albedo.png?rcd1&quality=high'`, `import webpUrl from './albedo.png?webp-fast&q=82'`, or `import modelUrl from './scene.glb?rcd1'`) also work out of the box. - Shipped Agent Skill (`skills/ultra-fast-texture/SKILL.md` and `.agents/skills/ultra-fast-texture/SKILL.md`): bundled with the package for AI coding assistants (Antigravity, Claude Code, Cursor, `npx skills add`). - Recommended production flags with hashed URLs: `cache: 'persistent', cacheValidation: 'url', worker: 'decode'`. ## Docs - [README](https://github.com/Makio64/ultra-fast-texture/blob/main/README.md): pitch, install, quick starts, formats, sizes, support, limits - [User guide index](https://github.com/Makio64/ultra-fast-texture/blob/main/docs/guide/README.md) - [Getting started](https://github.com/Makio64/ultra-fast-texture/blob/main/docs/guide/getting-started.md) - [three.js loader](https://github.com/Makio64/ultra-fast-texture/blob/main/docs/guide/three.md) - [glTF plugin](https://github.com/Makio64/ultra-fast-texture/blob/main/docs/guide/gltf.md) - [Core API: devices, sources, options, receipts, events](https://github.com/Makio64/ultra-fast-texture/blob/main/docs/guide/core.md) - [Formats and semantics](https://github.com/Makio64/ultra-fast-texture/blob/main/docs/guide/formats.md) - [Workers and caching](https://github.com/Makio64/ultra-fast-texture/blob/main/docs/guide/workers-and-caching.md) - [Authoring guide](https://github.com/Makio64/ultra-fast-texture/blob/main/docs/guide/authoring.md) - [CSP and deployment](https://github.com/Makio64/ultra-fast-texture/blob/main/docs/guide/csp.md) - [Troubleshooting and limits](https://github.com/Makio64/ultra-fast-texture/blob/main/docs/guide/troubleshooting.md) ## API contracts - [Core types (index.d.ts)](https://github.com/Makio64/ultra-fast-texture/blob/main/src/index.d.ts) - [three adapter types](https://github.com/Makio64/ultra-fast-texture/blob/main/src/three/index.d.ts) - [glTF plugin types](https://github.com/Makio64/ultra-fast-texture/blob/main/src/gltf/index.d.ts) ## Optional - [Demo guide and query flags](https://github.com/Makio64/ultra-fast-texture/blob/main/docs/guide/demo.md) - [PERFORMANCE.md](https://github.com/Makio64/ultra-fast-texture/blob/main/PERFORMANCE.md): dated speed measurements - [QUALITY.md](https://github.com/Makio64/ultra-fast-texture/blob/main/QUALITY.md): PSNR and angular error per format - [Design spec](https://github.com/Makio64/ultra-fast-texture/blob/main/docs/design/SPEC.md) - [Contributor guide (AGENTS.md)](https://github.com/Makio64/ultra-fast-texture/blob/main/AGENTS.md)