Title: Normal%20Map%20Compression%20with%20ATI%203Dc
1Normal Map Compression with ATI 3Dc
- Jonathan Zarge
- jzarge_at_ati.com
- ATI Research Inc.
2Overview
- Normal mapping
- Normal map compression techniques
- DXT compression
- ATI 3Dc
- Swizzled DXT5 compression
3Normal Mapping
- Increase visual realism
- Reduce geometric size of models
- Create detail by simulating geometry
- More efficient than dense geometry
- Textures provide lighting (normal) information
- Used in Half-Life 2, Doom 3, and Far Cry
4Car Paint Demo
5Traditional Lighting Model
n2
n1
Lighting values calculated at vertices and then
interpolated across triangle
Normals interpolated across triangle and lighting
values calculated at each pixel
n0
6Normal Map Lighting
3 component normal map texture
7World Space vs. Tangent Space
8Example Tangent Space Normal Maps
Tangent space normal maps can be efficiently
compressed
9Generating Normal Maps
10Normal Mapping Drawbacks
- Low angle views distorted
- Silhouette edges do not have detail
- High texture bandwidth required
- Large amount of texture memory
- DXT compression not optimal for normal maps
11Benefits of Normal Map Compression
- More detailed normal maps
- More normal maps
- Memory and bandwidth can be diverted to other
resources - Smaller media size
12Normal Map Compression Techniques
- Lower precision texture formats
- Texture formats with fewer channels
- Denormalization
- Palletization
- Direct DXT compression
- ATI 3Dc
- Swizzled DXT5
13DXT Compression
- Designed to compress color data
- No suited for arbitrary data
- One channel dependent on another
- Lossy format
- Image divided into 4x4 pixel blocks
- 16 possible colors in block
- Only 3 or 4 colors in compressed data
- Local similarity in small region enables high
quality color compression
14DXT Compression Color Block
- Image divided into 4x4 blocks
- Two 16-bit 5.6.5 colors stored representing
endpoints of linear color-ramp - One or two interpolated colors calculated
- 16 two-bit indices stored representing index into
color ramp - Effective bit-rate
- 64 (216 162) / 16 4 bits per pixel
15DXTC Color Compression
WHITE
CYAN
BLUE
MAGENTA
GREEN
YELLOW
BLACK
RED
16DXTC Color Decompression
- For the four color case, given color0,
color1, and index1..15 - // calculating interpolated colors
- color2 (2color0 color1 1)/3
- color3 (color0 2color1 1)/3
- // decompressed texel values
- for n 0 to 15
- texeln colorindexn
17DXT5 Compression Alpha Block
- Like color, image divided into 4x4 blocks
- Two 8-bit scalars stored representing endpoints
of linear alpha-ramp - 4 or 6 intermediate alpha values calculated
- 16 three-bit indices stored representing index
into alpha ramp - Effective bit-rate
- 64 (28 163) / 16 4 bits per pixel
18DXTC Alpha Decompression
- For the 8 alpha value case, given alpha0,
alpha1, and index1..15 - // calculating interpolated alpha values
- alpha2 (6alpha0 1alpha1 3)/7
- alpha3 (5alpha0 2alpha1 3)/7
- ..
- alpha7 (1alpha0 6alpha1 3)/7
- // decompressed texel values
- for n 0 to 15
- texeln alphaindexn
19Using DXT Compression for Normal Maps
- Not a good idea!
- Block artifacts
- Normals describe curved surfaces, not lines
- Especially visible in diagonal gradients
- Colors stored in 5.6.5 format
- Fine detail lost
- Errors are amplified for specular lighting
- Storage is inefficient because normalized vectors
can be stored in two values
20ATI 3Dc Texture Format
- Two independent channel texture format
- Exposed in D3D via the FOURCC code ATI2
- Composed of 2 DXT5 alpha blocks
- Extremely useful for normal textures
- Compression
- 41 for 32 bit textures
- 21 for 16 bit textures
21Ruby Demo
22ATI 3Dc Texture Format
- Decompression accomplished in hardware
- Almost no impact on performance
- Can be used for two unrelated scalars
- e.g. shininess, refractive index, transparency
- Library for compressing to 3Dc available from
ati.com/developer - Available in OpenGL using the GL_ATI_texture_comp
ression_3dc extension
23ATI 3Dc Texture Format
24Using ATI 3Dc with Normal Maps
- x and y (of normal) stored in the texture
- z value calculated by x2 y2 z2 1
- z sqrt(1 x2 y2)
- Only positive root used because normal is in
tangent space - Calculation done in pixel shader
- Can also be derived by a texture lookup
- Single channel z component texture
25Using ATI 3Dc
scale, bias, half, one def c0, 2.0f, -1.0f,
0.5f, 1.0f . . texld r1, t1, s1 normal map mad
r1, r1, c0.x, c0.y scale/bias to -1,1
Compute third component dp2add r1.z, r1, -r1,
c0.w 1-xx-yy rsq r1.z, r1.z 1 /
sqrt(1-xx-yy) rcp r1.z, r1.z
sqrt(1-xx-yy)
26Using ATI 3Dc
sampler bump_map float4 ps_main(
PS_INPUT_STRUCT psInStruct ) COLOR0 //
Unpack two component bump map float3 bump
tex2D( bump_map, psInStruct.bump_map )
// Put x and y in -1..1 range and compute z
bump ( bump 2.0f ) - 1.0f bump.z sqrt(1
- dot(bump.xy, bump.xy)) . .
27ATI 3Dc Compression Comparison
28ATI 3Dc Normal Compression Sample
29Drawbacks of ATI 3Dc
- Can only represent tangent space normal maps
- Cannot represent high precision normal maps
- Large areas of low curvature (car hood) may
require 16 bits per component - More pixel shader instructions required
- Not available on all hardware
30Normal Map Compression Using Swizzled DXT5
- For any hardware with at least ps 1.4 support
- Store x and y in alpha and green channels of the
texture map - Shader similar to 3Dc with one extra pixel
shader instruction - Results better than using DXTC directly but not
as good as 3Dc
31Using DXT5 Compression
scale, bias, half, one def c0, 2.0f, -1.0f,
0.5f, 1.0f . . texld r1, t1, s1 normal map mov
r1.x, r1.a restore x from alpha mad r1, r1,
c0.x, c0.y scale/bias to -1,1 Compute third
component dp2add r1.z, r1, -r1, c0.w
1-xx-yy rsq r1.z, r1.z 1 /
sqrt(1-xx-yy) rcp r1.z, r1.z
sqrt(1-xx-yy)
32DXT5 Normal Map Compression RenderMonkey Example
33Summary
- Normal Mapping great feature
- Directly using DXT compression not great for
normal textures - Compression with 3Dc lowers the cost normal
mapping - 3Dc available in D3D and OpenGL
- Swizzled DXT5 compression reasonable alternative
for older hardware
34QUESTIONS?
- Email me jzarge_at_ati.com or devrel_at_ati.com
- More information available at ati.com/developer
- Please go see Chris Oats talk on Advanced
Character Rendering Saturday, 1025am