Three.js Texture Memory & Compression Formats

Measure texture memory in Three.js across many unique textures in RGBA8, RGBA5551 and GPU-compressed BC1, with mipmaps on or off, resolution choices, a packed atlas mode, and upload time and GPU texture counts.

Key topics: three.js texture memory, texture compression, bc1, rgba5551, mipmaps, texture atlas, vram

What this code does

- Memory Math: width × height × bytes per pixel, and mipmaps add one third, so 48 RGBA8 textures at 1024² use about 256 MB.
- Formats: RGBA8 is 32 bits, RGBA5551 packs 16 bits, and BC1 block compression stores 4 bits per pixel while staying compressed on the GPU.
- Upload Cost: `renderer.initTexture` uploads immediately so encode and upload time can be measured.
- Mipmaps: precomputed smaller levels prevent shimmering and cache thrash at grazing angles for 33% more memory.
- Atlas: packing every tile into one texture means one texture bind and one material for all quads.
- Controls: format, resolution, texture count, mipmaps and atlas packing.

Continue Learning

JavaScript Implementation

ES6+
// GPU memory per texture ≈ width × height × bytes-per-pixel × (mipmaps ? 4/3 : 1)
//   RGBA8 = 4 B/px · RGBA5551 = 2 B/px · BC1 = 0.5 B/px (8 bytes per 4×4 block)
const rgba5551 = new THREE.DataTexture(packedUint16, 512, 512, THREE.RGBAFormat, THREE.UnsignedShort5551Type)
const bc1 = new THREE.CompressedTexture(mipmaps, 512, 512, THREE.RGB_S3TC_DXT1_Format) // needs WEBGL_compressed_texture_s3tc
renderer.initTexture(bc1)                      // upload now instead of on first render
console.log(renderer.info.memory.textures)     // live GPU texture count