Anisotropic Filtering in DirectX Sampler States
Anisotropic filtering in DirectX is configured through a sampler state object to significantly improve texture clarity on surfaces viewed at oblique angles. When enabled, the sampler calculates the projection of a screen-space pixel footprint onto texture space, taking multiple samples along the axis of greatest distortion rather than assuming a symmetrical footprint. By setting the filtering mode to anisotropic and defining a maximum sample limit, developers allow the graphics hardware to dynamically eliminate perspective blur and aliasing on receding geometry without excessive performance penalties.
Configuring the Sampler State
In DirectX (Direct3D 11 and Direct3D 12), anisotropic filtering is
established inside the sampler description structure
(D3D11_SAMPLER_DESC or D3D12_SAMPLER_DESC).
Two specific fields control its behavior:
Filter: Must be set to an anisotropic variant, typicallyD3D11_FILTER_ANISOTROPIC(orD3D12_FILTER_ANISOTROPIC). DirectX also offers comparison variants (such asD3D11_FILTER_COMPARISON_ANISOTROPIC) for depth testing operations.MaxAnisotropy: An integer value ranging from 1 to 16. This value defines the maximum ratio of elongation the sampler will account for, directly dictating the upper limit of samples taken per texture lookup. Setting this value to 1 effectively reduces the operation to standard isotropic (bilinear/trilinear) filtering.
Once created, the sampler state is bound to the pipeline, where the pixel shader references it during texture sampling instructions.
The Underlying Mechanics
Standard bilinear and trilinear filtering treat a screen pixel’s footprint in texture space as an isotropic (square or circular) shape. When a textured polygon is tilted sharply relative to the camera, that square pixel footprint projects into a stretched ellipse in UV space. Standard filtering resolves this by selecting a lower-resolution mipmap level that fits the largest dimension of the ellipse, which results in severe blurring along the shorter dimension.
Anisotropic filtering resolves this distortion through the following steps:
- Derivative Calculation: The GPU evaluates screen-space partial derivatives (\(ddx\) and \(ddy\)) of the texture coordinates across adjacent pixels in a \(2 \times 2\) pixel quad.
- Footprint Mapping: These derivatives define the major (longest) and minor (shortest) axes of the projected ellipse in texture space.
- Anisotropy Ratio Detection: The sampler computes the ratio of the major axis length to the minor axis length. This ratio determines the degree of anisotropy.
- Clamping: The computed ratio is clamped against the
MaxAnisotropyvalue defined in the sampler state. - Sampling Along the Line of Anisotropy: The sampler selects a mipmap level based primarily on the minor axis to preserve high-frequency details. It then takes a series of linearly spaced samples along the major axis within that mipmap level (or across two adjacent mip levels if combined with trilinear filtering).
- Weighting and Reconstruction: The gathered samples are weighted and averaged together to construct the final texel color passed to the shader.
Runtime Performance
The anisotropic sampler in DirectX is adaptive. If a surface faces
the camera directly, the anisotropy ratio remains near 1:1, and the
hardware performs standard isotropic filtering using minimal texture
taps. As the angle of incidence becomes steeper, the hardware
dynamically increases the number of sample taps up to the defined
MaxAnisotropy limit. Consequently, the computational and
memory bandwidth cost scales with geometric orientation rather than
imposing a flat overhead across the entire scene.