O'Reilly logo

OpenGL Insights by Christophe Riccio, Patrick Cozzi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

In-Game Video Capture with
Real-Time Texture Compression
Brano Kemen
31.1 Introduction
This chapter discusses techniques for real-time compression of images on the GPU
for use with various types of procedurally or dynamically generated images and virtual
texturing. The techniques are designed to achieve lower memory and bandwidth
requirements while providing high quality. We also describe the use of this technique
in capturing high-quality video directly from the application without significantly
impairing the overall performance.
Figure 31.1. Procedural tree generator in Outerra using real-time compression for clusters
of leaves.
455
31
456 V Transfers
31.2 Overview of DXT Compression
DXT compression, also S3 Texture Compression, S3TC [S3TC 12], refers to a group
of lossy, fixed-rate image-compression algorithms that are now widely supported in
graphics hardware, as they are well suited for hardware-accelerated texture decom-
pression for 3D graphics.
The compression ratio is fixed, either 8:1 or 6:1 for the DXT1 format with 1-
bit transparency or without alpha, respectively. Formats with higher quality alpha
encoding have 4:1 compression ratios.
All compression schemes encode the RGB part in the same way by compressing
blocks of 4 × 4 input pixels in 64 bits of color output. The output consists of two
16-bit RGB 5:6:5 quantized color values, followed by 16 2-bit values that determine
how the corresponding pixel color is computed: either one of the two colors or a
blend between them.
The a lpha component can be encoded in several ways depending on the mode.
F or DXT4 and DXT5, it’s encoded using a scheme similar to the color part but with
two 8-bit alpha values and 3-bit interpolation values for each pixel.
DXT compression has some limitations, and the image quality can be degraded
if used naively on some images with sharp changes in colors (Figure 31.3). However,
it is well suited for most of the textures used in 3D graphics, as these are usually more
homogenous.
The quality loss is offset by the significantly reduced memory and bandwidth
requirements; compressed textures of the same dimensions render faster as the result.
Alternatively, a gain in quality can be achieved by using higher-resolution textures
for the same amount of memory.
31.3 DXT Compression Algorithms
While the decompression algorithm is defined exactly, there are multiple compression
algorithms with different quality output. The quality mainly depends on the way
the two endpoint color values are selected [Brown 06]. High-quality compression
algorithms try to find the best endpoints for the given set of pixels. Testing all possible
endpoints by a bruteforce method is very time consuming, so the goal is to reduce
the number of combinations to be tested.
Colors in a 4 × 4 block can be considered points in 3D RGB space. Resulting
compressed colors must lie on a line between two selected endpoints in this space.
The direction along which the points vary the most can be found using the technique
of principal components analysis. It is likely that this direction, called the principal
axis, is very close to the direction of the line through the optimal endpoints, and it
can b e used to seed the search.
Nevertheless, these algorithms are still too slow for real-time compression, for
which we need a fast selection of the compression line. We can use the extents of

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required