Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

DDS textures

Skyrim stores its textures as DirectDraw Surface (.dds) files: terrain LOD tiles and their normal maps, landscape textures, the diffuse textures of models. CreationEngineFormats/Dds/ reads the header and decodes a mip level to RGBA. The layout is Microsoft’s, not Bethesda’s: see the DDS header and the programming guide.

TypeDoes
DdsHeaderThe header layout; TryReadSize reads the top level’s size without decoding
DdsDecoderDecodes the top level, or the first level within a given size, to RGBA with Pfim
DdsMipLevelCuts one mip level out of a texture, so the decoder skips the larger ones
DdsImageA decoded level: top-down, tightly packed RGBA8

File layout

"DDS "             4 bytes, magic
DDS_HEADER         124 bytes: flags, height, width, pitch, depth, mip count, pixel format, caps
DDS_HEADER_DXT10   20 bytes, only when the pixel format's FourCC is "DX10": DXGI format, dimension, array size
level 0            then each smaller level, halving each side down to 1

A level’s size comes from its pitch: 8 bytes per 4x4 block for DXT1, BC1 and BC4, 16 for the other block-compressed formats, and whole bytes per pixel for uncompressed formats.

Decoding

Pfim decodes the pixels. DdsDecoder maps its 24-bit and 32-bit output from BGR(A) to RGBA, and returns null for any other output format. A 32-bit texture without DDPF_ALPHAPIXELS is X8R8G8B8: its fourth byte is padding, not alpha, and vanilla Solstheim terrain LOD tiles leave it 0, so it decodes as opaque.

Asked for a size, DdsDecoder decodes the first level whose sides both fit, or the last level. It copies the header and that level into a one-level texture, so Pfim never reads the larger levels. The texture kinds and formats it can’t cut are listed in Not implemented.