What Is a Depth Texture?

A depth texture is a texture that contains the data from the depth buffer for a particular scene.

The color of each pixel in the texture represents the depth of the polygon under that pixel, taken from the depth buffer. You can use depth textures to render accurate shadows using a technique called shadow mapping. For this reason, depth textures are also known as shadow maps.

There are two common ways to encode the depth information into a texture. The first is to use a standard RGBA surface format for your texture, and treat all four colors as one 32-bit buffer and copy the depth into that buffer (depth formats normally assign 24 or 32 bits for depth data). The second is to use a floating-point surface format for your texture combined with a floating-point depth buffer. Depth buffers are normally fixed-point. When using the floating-point approach, it is more accurate to subtract the depth from 1.0 before storing it, due to the way floating-point numbers are encoded.

Both of these techniques require a custom vertex and pixel shader. How To: Create a Depth Texture provides an example of a depth texture shader and the code necessary to use it.

See Also

Concepts

3D Graphics Overview

Tasks

How To: Create a Depth Texture
How To: Implement Shadow Mapping