VideoLogic Vector Quantisation
VideoLogic Vector Quantisation
Vector Quantisation
Subject: A Technology Discussion
Author: VideoLogic Ltd (PowerVR)
File Name: Vector Quantisation.doc
Issue Number: 1.0.8
Issue Date: 26 October 98
Copyright: © VideoLogic Ltd 1998. All rights reserved. POWER VR
This material may not be republished in any format without
the express consent of its authors. Information contained
herein is provided “as-is”, without representations or
warranties, and is subject to change without notice.
Note
This is part of a paper written by Mark Butler and presented by Marc Pinter-Krainer at the Computer Games
Developers Conference 1998.
Author/Speaker
Mark Butler - Programme Manager, VideoLogic Ltd. <[email protected]>
Marc Pinter-Krainer - Developer Relations, VideoLogic Ltd. <[email protected]>
Abstract
In depth discussion on a specific feature: Vector Quantisation texture compression (providing up to 8:1
compression)
Audience prerequisites
General knowledge on the issues associated with texture compression. Previous experience with PowerVR is an
asset but not a must.
Introduction
The use of a texture compression system allows a game to utilise many more and much teger textures. It is
important that the method does not have a performance impact on the rendermg and that it will compress typical
texture images well. Vector Quantisation (VQ) has these properties. It has a high compression ratio and looks
very good on surface textures and sharp edged detail like text. The method will be discussed from the user s
point of view as well as the technical details.
Vector Quantisation is a method of compression that finds similar sections or blocks of an image, creatcsa table
of the blocks and then encodes the image using indices into that code book table. It performs well on high
frequency images like text and also on texture surface images.
User View
You do not have to get artists to rework your artwork to use VQ. The compression can be used on all your
existing textures. Start by compressing all your textures with VQ. If this gives acceptable results then your work
is done. If some of the compressed textures are not of high enough quality, then compress the rest and leave
these uncompressed.
Comparisons
The following images have all been compressed with VQ using 2x2 blocks and a 256-entry table. When studying
the images for compression artefacts, remember that these are the flat images and have not been used m a
rendered scene. As part of the scene they will typically have been filtered, smooth shaded, fogged and so on.
Each operation in the texturing and shading pipeline will help to obscure any differences between the
compressed image and the original.
n
Cows 256x256 16 bit VQ 7.1:1
Cows 256x256 16 bit dithered (Was JPEG)________ _______________________________
This would normally be considered a difficult scene for VQ as it has a nmber of graduations ^d a toge range
of colours and parts to the image. Even so there are remarkably few artefacts. Check banding in the sky
graduations behind the cow’s head. Note that this type of image is not likely to be used extensively m a game.
Sunset 256x256 16 bit dithered (Was JPEG) Sunset 256x256 16 bit VQ 7.1:1
This is potentially a difficult scene for VQ due to the graduations. However it compresses well because there are
few separate colour ranges. This allows the table to use more entries to cover the graduation.
i:
g
ir* ,.J
m
Hi*-.*.
Forest 256x256 16 bit VQ 7.1:1
Forest 256x256 16 bit dithered (Was JPEG)
A good example case for VQ. The image has detail and sharp edges, there is even a fair colour range and yet the
compressed image is almost indistinguishable. However, careful checking c^ detect fee drop m fee ye
components of fee centre leaf. This can be addressed by re-compressmg wife different parameters.
Technology View
This worked example will be done wife a 128x128, 24 bit image. The original image is shown below with fee
resulting VQ image for comparison. The example uses a grid of 2x2 pixels. Each 2x2 block is compared agamst
fee other 2x2 blocks to find similar copies.
Tire search is similar to a palette selection operation. The constraint is fee fixed number of entries available in
fee table, so fee objective is to find a set of values feat reduce fee error for fee image.
Zoom In 4:1 on Rocks 128x128 24 bit Zoom in 4:1 on Rocks 128x128 24 bit 2x2 VQ
s R: ISO
G: 138
B: 129
R: 143
G: 1S7
B: 133
R: 14S
G: 135
B: 116
R:152 I
G:154 ®
B:119 *
Similar Blocks
Original image is processed for similar pixel quads on a 2x2 block
The original image’s data is stored in the RGB format, where eadi pixel contains 24 bit data. 8 bit for each red,
green and blue component
Identical Blocks
Modified image with duplicate 2x2 pixel blocks
During the selection process the 2x2 block will be changed slightly so that several blocks that do not match
exactly will match with very little error. Now there are duplicates the data can be stored in a much mere compact
format.
• • R: Oil R: 013
G: 004 G; 006
• • E: OOS B: 007
R: 148 R: ISS
G: 133 G: 142
B: 105 B: 110
R: 125 R: 138
G: 137 G: 137
B: 125 B: 110
R: 145 R: 145
G: 150 G: 132
B: 126 B: 110
The image is now stored as a series of indices (Index Map) plus the look up table.
Now the compression can be calculated. The original image is 128x128 and now consists of 64x64 index entries,
each 8 bit. This makes 64x64= 4096 bytes. The table is 256 entries each consisting of 4 RGB entries, each entry
is 24 bit data or 3 bytes. This makes 256x4x3= 3042. The total for the VQ image is 7138 bytes. The original
image is 128x128 RGB entries each of 3 bytes. This makes 128x128x3= 49152 bytes: a compression ratio of 6.9
to 1.
Compression Ratios
The worked example above made a number of choices. The follow is a list of the items that need consideration
when using VQ. They all affect the compression ratios and quality of the output:
• Block Size (E.G. 2x2 cx 3x3)
• Source Bit Depth (E.G. 24 bit or 16 bit)
• Target Bit Depth (E.G. 24 bit or 16 bit)
• Number of Table Entries (E.G. 256 or 64) or
Size of the Index values (E.G. 8 bit or 6 bit)
The worked example used 24 bit to simplify the discussion, however in a hardware implementation it is likely
that 16 bit is a more natural dioice.
A set of selections has been made in each of the tables below. They show the effect on the compression ratio at
different image resolutions. In general the formula to work out the number of bytes in the VQ unage is as
follows:
VQ Image Size = IndexMapSize + TableMapSize
= ResX/BlockSizeX*ResY/BlockSizeY*VQBits/8 +
2AVQBits*BIockSizeX*BlockSizeY*BitDepth/8
The following example is a nice balance between the option to generate a good compression and a good image
quality. This is the set of options used by default in PowerVR Second Generation.
Note, however, mat me compression ratio lor smaii uuagcs is nui yay imo is iiwuusv. —---------—
is larger than it needs to be. To address this the number of bits used for the indices can be reduced, this leads to a
smaller code book table. For 6 bit VQ the table has 64 entries. Variable table size is an option on PowerVR
Second Generation.
Compression for 16 bit, 2x2, 6 bit VQ
2*8Bit/8 + VQ Image
256*2x2*16b Image Bytes Bytes Ratio
Performance
When using VQ compressed textures a lookup table entry and an index is required for each texel fill. This is a
similar operatirai to a palletised texture. It may be look as if it would take twice as long m the hardw^e pipeline,
compared to a single 16 bit fetch. However, the table is much smaller than a full size texture is suitable for
caching techniques. This is particularly true during bilinear operations what it is likely that the surrounding
texels are also needed. Performance is also offset against the need to only fetch 8 bits for the index as opposed to
16 bits for a full texel value. Thus a VQ texture implemaitation can be designed to perform as well as a normal
texture.
Summary
VQ is a compression that works well for 3D games. It has a high compression ratio and is easy to use. Evct if
some of your textures remain in normal uncompressed texture surfaces, a typical case of 4MB of on board
texture memory allows around 20MB of textures to be uploaded.