DDS (.dds)
0
Upvotes
4
Views
0
Downloads
1,500
Words
Description
Learn to work with DDS texture containers (BCn/DXTn), including compression, mipmaps, and GPU-ready data for DirectX-based graphics.
When to Use
explain DDS format and BCn compression | how to work with DDS textures for DirectX | guide me on DDS mipmaps and cube maps | convert textures to DDS BCn | DDS file format specifications
Use Cases
Explain DDS texture format and BCn compression. | Choose DDS formats for DirectX GPU pipelines. | Implement loading of DDS in a game engine. | Generate and validate mipmaps in DDS textures. | Convert textures to DDS BCn for streaming.
SKILL.md Content
---
name: dds
description: "Learn to work with DDS texture containers (BCn/DXTn), including compression, mipmaps, and GPU-ready data for DirectX-based graphics."
metadata:
tags: "file-format, dds, texture-compression, dxt, directx, gpu-textures, mipmaps, texture-pipelines"
source: "https://skilldb.dev/skills/file-formats-skills/dds"
pack: "file-formats-skills"
category: "Technology & Engineering"
---
# DDS (.dds)
## When to use this skill
Use when the user says things like:
- "explain DDS format and BCn compression"
- "how to work with DDS textures for DirectX"
- "guide me on DDS mipmaps and cube maps"
- "convert textures to DDS BCn"
- "DDS file format specifications"
You are a file format specialist with deep knowledge of the DDS texture format, GPU block compression algorithms, mipmap chains, and real-time 3D graphics texture pipelines.
## Overview
DDS (DirectDraw Surface) was introduced by Microsoft as part of the DirectX SDK. Originally designed for DirectDraw (DirectX 7, 1999), it evolved into the primary texture container format for DirectX-based applications and games. DDS stores textures in GPU-native compressed formats (BCn/DXTn), meaning the data can be uploaded directly to the GPU without CPU-side decompression. This enables faster load times and lower memory usage compared to formats that require decompression before GPU upload. DDS supports mipmaps, cube maps, volume textures, and texture arrays. It is the standard texture format for DirectX games and is widely supported in Windows game development toolchains. The DX10 header extension (2006) added support for modern compressed formats and resource arrays.
## Technical Specifications
- **File extension(s):** `.dds`
- **MIME type:** `image/vnd.ms-dds` (unofficial)
- **Compression formats:**
- **BC1 (DXT1):** 4:1 compression, RGB + optional 1-bit alpha. 4 bits/pixel.
- **BC2 (DXT3):** RGB + explicit 4-bit alpha. 8 bits/pixel.
- **BC3 (DXT5):** RGB + interpolated 8-bit alpha. 8 bits/pixel. Most common for general textures.
- **BC4 (ATI1):** Single channel (grayscale, roughness, height). 4 bits/pixel.
- **BC5 (ATI2):** Two channels (normal maps: X+Y components). 8 bits/pixel.
- **BC6H:** HDR RGB (half-float), no alpha. 8 bits/pixel. For HDR textures and lightmaps.
- **BC7:** High-quality RGB/RGBA. 8 bits/pixel. Best quality for general textures, slower to encode.
- Also supports uncompressed formats (R8G8B8A8, R16G16B16A16F, R32G32B32A32F, etc.)
- **Color depth:** Varies by format: 4-128 bits per pixel. BC formats store 4x4 pixel blocks.
- **Max dimensions:** 2^16 (65,536) pixels per dimension (limited by DDS header fields)
- **Mipmaps:** Full mipmap chain support (each level is half the dimensions of the previous)
- **Texture types:** 2D texture, cube map (6 faces), volume/3D texture, 1D texture, texture arrays (DX10 extension)
- **Transparency:** BC2 (4-bit alpha), BC3 (interpolated 8-bit alpha), BC7 (high-quality alpha), or uncompressed RGBA
- **Metadata support:** Minimal (header contains format info, dimensions, mip count, caps flags)
## How to Work With It
### Opening & Viewing
- **Windows:** Native thumbnail support (recent versions), Visual Studio texture viewer
- **DirectX Texture Tool:** Microsoft's official viewer (legacy, from DirectX SDK)
- **RenderDoc:** GPU debugger that can inspect DDS textures
- **NVIDIA Texture Tools Exporter:** View and convert DDS files
- **IrfanView/XnView:** With DDS plugin
- **GIMP:** Via DDS plugin (gimp-dds)
- **Photoshop:** Via NVIDIA Texture Tools plugin or Intel Texture Works plugin
- **Paint.NET:** Via DDS plugin
### Creating & Editing
- **NVIDIA Texture Tools (nvtt):** `nvcompress -bc3 input.png output.dds` (command line)
- **DirectXTex (texconv):** `texconv -f BC7_UNORM -m 0 input.png` (Microsoft's tool, generates mipmaps with `-m 0`)
- **Compressonator (AMD):** GUI and CLI for texture compression with quality preview
- **ISPCTextureCompressor (Intel):** Very fast BC1-BC7 encoder using ISPC SIMD
- **Mipmap generation:** Always include mipmaps for 3D rendering textures. Most tools generate them automatically.
- **Normal maps:** Use BC5 (two-channel) format; reconstruct Z in the shader. Do NOT use BC1/BC3 for normal maps (visible artifacts).
- **sRGB vs Linear:** Mark color textures (albedo/diffuse) as SRGB format variants (e.g., BC7_UNORM_SRGB). Mark data textures (normal, roughness, metallic) as LINEAR.
### Converting To/From
- **PNG to DDS:** `texconv -f BC7_UNORM_SRGB -srgb -m 0 -y input.png`
- **DDS to PNG:** `texconv -ft png -o . input.dds` or `magick input.dds output.png`
- **TGA to DDS:** `texconv -f BC3_UNORM -m 0 input.tga`
- **Batch convert:** `texconv -f BC7_UNORM -m 0 -r *.png`
- **HDR to DDS:** `texconv -f BC6H_UF16 -m 0 input.hdr` (for IBL/environment maps)
- **Python:** `from PIL import Image; import struct` (manual parsing) or use `wand` library with ImageMagick delegate
## Common Use Cases
- Game texture assets (diffuse, normal, specular, roughness, metallic, emissive, AO maps)
- Environment/cube maps for reflections and skyboxes
- Lightmaps (BC6H for HDR light data)
- UI textures in games and real-time applications
- Terrain textures (often large texture arrays)
- Particle effect textures (with alpha for soft particles)
- Decal textures
- Virtual texturing source data
## Pros & Cons
**Pros:**
- GPU-native compression (no CPU decompression needed; uploaded directly to VRAM)
- 4:1 to 8:1 fixed-ratio compression reduces VRAM usage dramatically
- Built-in mipmap support eliminates aliasing and improves texture filtering
- Cube map and texture array support
- BC7 provides excellent quality at 8 bits/pixel
- BC6H enables HDR textures at compressed sizes
- Fast random access (any pixel decodable without reading entire file)
- Industry standard for DirectX game development
**Cons:**
- Lossy block compression introduces artifacts (blocky patterns on gradients)
- Block compression operates on 4x4 pixel blocks (textures should be multiples of 4)
- DDS-specific tools required (not viewable in web browsers or standard image viewers)
- Encoding BC6H/BC7 is computationally slow (ISPCTextureCompressor helps)
- Windows/DirectX-centric (OpenGL/Vulkan ecosystems often prefer KTX/KTX2)
- No metadata or color management
- Legacy header format can be confusing (DX9 vs DX10 headers)
- Not suitable for general image interchange
## Compatibility
| Platform | Support |
|----------|---------|
| DirectX / Direct3D | Native (the defining API) |
| Unreal Engine | Native texture import |
| Unity | Native texture import |
| Godot | Supported |
| NVIDIA tools | Full |
| AMD Compressonator | Full |
| Photoshop | Via plugin (NVIDIA/Intel) |
| GIMP | Via DDS plugin |
| OpenGL/Vulkan | Can load BC textures (but KTX format preferred) |
| Web browsers | Not supported |
## Practical Usage
### Convert textures to DDS with Microsoft's texconv
```bash
# Convert albedo texture to BC7 with sRGB gamma and full mipchain
texconv -f BC7_UNORM_SRGB -srgb -m 0 -y albedo.png
# Convert normal map to BC5 (two-channel, linear)
texconv -f BC5_UNORM -m 0 -y normal_map.png
# Convert HDR environment map to BC6H
texconv -f BC6H_UF16 -m 0 -y environment.hdr
# Batch convert all PNGs to BC7 with mipmaps
texconv -f BC7_UNORM_SRGB -m 0 -r -y textures/*.png -o output/
```
### Read DDS metadata and extract layers with Python
```python
# Using imageio or wand to inspect DDS files
from pathlib import Path
import struct
def read_dds_header(filepath):
"""Parse DDS header to extract format info."""
with open(filepath, 'rb') as f:
magic = f.read(4)
assert magic == b'DDS ', "Not a DDS file"
header = f.read(124)
height = struct.unpack_from('<I', header, 8)[0]
width = struct.unpack_from('<I', header, 12)[0]
mip_count = struct.unpack_from('<I', header, 24)[0]
fourcc = header[72:76].decode('ascii', errors='replace')
print(f"Size: {width}x{height}, Mipmaps: {mip_count}, FourCC: {fourcc}")
# Convert DDS to PNG via ImageMagick (from Python subprocess)
import subprocess
subprocess.run(["magick", "texture.dds", "texture.png"], check=True)
```
### Game engine texture import pipeline (Unreal/Unity)
```bash
# Unreal Engine — import textures via command line (UnrealPak)
# Textures placed in Content/Textures/ are auto-imported as BC7/BC5
# Unity — use TextureImporter settings in an Editor script:
# TextureImporter.textureCompression = TextureImporterCompression.CompressedHQ
# For normal maps: TextureImporter.textureType = TextureImporterType.NormalMap
# Validate DDS textures before import
for f in *.dds; do
texconv -nologo -info "$f"
done
```
## Anti-Patterns
**Using BC1/BC3 for normal maps instead of BC5.** BC1 and BC3 compress all channels together, introducing cross-channel artifacts that cause visible shading errors on normal-mapped surfaces. Use BC5 which stores X and Y channels independently, and reconstruct the Z component in the shader with `z = sqrt(1 - x*x - y*y)`.
**Forgetting to generate mipmaps for 3D rendering textures.** Textures without mipmaps cause aliasing, shimmering, and moire patterns when viewed at a distance. Always generate a full mipmap chain (`-m 0` in texconv) for any texture used in real-time 3D rendering. Only skip mipmaps for UI/HUD textures rendered at 1:1 pixel scale.
**Marking data textures (normal, roughness, metallic) as sRGB.** Data textures contain linear values that are not meant for display. Tagging them as sRGB causes the GPU to apply gamma correction during sampling, producing incorrect lighting. Use `_UNORM` (linear) format variants for all non-color textures; only albedo/diffuse textures should use `_SRGB`.
**Using uncompressed RGBA for textures that could be block-compressed.** Uncompressed 32-bit RGBA uses 4x-8x more VRAM than BC-compressed equivalents. A 4K RGBA texture uses 64 MB uncompressed vs 16 MB with BC7. Always use block compression for runtime textures unless you need exact pixel values (e.g., lookup tables).
**Creating textures with dimensions that are not multiples of 4.** BC compression operates on 4x4 pixel blocks. Non-multiple-of-4 dimensions cause the encoder to pad the texture, wasting memory and potentially creating edge artifacts. Always use power-of-two or at minimum multiple-of-4 dimensions for DDS textures.
## Related Formats
- **KTX / KTX2:** Khronos texture container for OpenGL/Vulkan; supports ASTC, ETC2, and BCn compression
- **ASTC:** Adaptive Scalable Texture Compression (ARM/Khronos); more flexible block sizes, preferred on mobile GPUs
- **ETC2:** Ericsson Texture Compression; required by OpenGL ES 3.0, used on Android
- **PVRTC:** PowerVR Texture Compression (Imagination Technologies); used on older iOS devices
- **Basis Universal (.basis):** Binomial/Google supercompressed format that transcodes to any GPU format at runtime
- **TGA/PNG:** Source texture formats that are converted to DDS during the game build pipeline
- **EXR:** HDR source format; BC6H DDS is the GPU-compressed runtime equivalent