skip to content

How do bilinear, trilinear and anisotropic texture filtering differ, and which artefact on a tiled stone floor does each one fix?

level: middleimportance: must knowfreq 66%

answer

  1. texel footprint per pixel
  2. four texels, then eight
  3. bands where the level switches
  4. long, thin footprints at grazing angles
  5. probes along the major axis

basics

~20 s

Bilinear blends the four nearest texels within one mip level; trilinear also blends two adjacent levels, removing visible mip bands; anisotropic takes several probes along a stretched footprint, so grazing-angle floors stay sharp instead of smearing.

solid answer

~50 s

The GPU measures how far the texture coordinate moves per pixel in screen x and y, in texels, and sets `lod = log2(longer axis)`. **Bilinear** reads the 2x2 texels around the sample in one rounded level; on a long stone floor a visible band appears where that level switches. **Trilinear** does a bilinear lookup in `floor(lod)` and in the next coarser level and blends them by the fraction, eight texels, so sharpness changes smoothly and the bands vanish. Both are isotropic: at a grazing angle the footprint might span 16 texels along the view and 1 across, and sizing by the long side blurs the floor 16 times too much across. **Anisotropic** filtering takes `n = min(ceil(long / short), cap)` probes along the long axis from a finer level chosen by `long / n`, keeping the far floor sharp. Under magnification (`lod < 0`) all of them use the base level.

code

pseudocode · 17 lines
pseudocode
// dUVdx, dUVdy: change of the texture coordinate per pixel step in screen x and y
// texSize: (width, height) of mip level 0
function chooseLevel(dUVdx, dUVdy, texSize, bias, maxAniso, mipCount):
    px = length(dUVdx * texSize)          // footprint along screen x, in texels
    py = length(dUVdy * texSize)          // footprint along screen y, in texels
    pMax = max(px, py, 1e-6)
    pMin = max(min(px, py), 1e-6)

    // isotropic (bilinear or trilinear): size the lookup by the longer axis
    lodIso = clamp(log2(pMax) + bias, 0, mipCount - 1)

    // anisotropic: n probes along the major axis, each at a finer level
    n = clamp(ceil(pMax / pMin), 1, maxAniso)
    lodAniso = clamp(log2(pMax / n) + bias, 0, mipCount - 1)

    // trilinear blends levels floor(lod) and floor(lod) + 1 by fract(lod)
    return lodIso, lodAniso, n

go deeper

for a junior

Recall what each mode reads: bilinear four texels in one level, trilinear two levels blended, anisotropic several probes along a stretched footprint. Name the floor artefact each one fixes.

for a middle

Explain level-of-detail selection from the texel footprint and log2, why isotropic filtering blurs at grazing angles, and how the anisotropic probe count and finer level follow from the footprint's two axes.

for a senior

Diagnose from symptoms: bands that slide with the camera, smeared floors, shimmer after a sharpening bias. Know what each mode costs in bandwidth and where addressing modes create seams.

for a principal

Own the filtering defaults: anisotropic caps per material class and platform, when a LOD bias is allowed, and how those settings interact with rendering below output resolution.

## Magnification and minification Every texture lookup starts with one question: how big is this pixel's footprint on the texture? If one texel covers several pixels, the texture is **magnified**; if one pixel covers several texels, it is **minified**. The three named filtering modes, bilinear, trilinear and anisotropic, differ mostly in how they handle minification. ## Estimating the footprint and the level of detail The GPU knows how much the texture coordinate changes from one pixel to the next, horizontally and vertically (how it obtains those screen-space derivatives belongs to the shader programming model). Scaled by the texture's size, they give two vectors in texels: the footprint's extent along screen x and along screen y. The **level of detail** is ``` lod = log2(max(length(dx_texels), length(dy_texels))) + bias ``` A `lod` below 0 means magnification and uses the base level. A `lod` of 2.3 means each pixel spans about 2^2.3, roughly 5 texels, so levels 2 and 3 bracket it. Distance matters only through the footprint: dense UVs, a steep viewing angle or a lower screen resolution all raise `lod`. ## Bilinear filtering **Bilinear** filtering reads the 2x2 texels around the sample point in one mip level and blends them by the fractional position, which turns blocky magnified texels into smooth gradients. With mipmaps it uses a single level, rounded from `lod`. Its weakness shows on a long tiled stone floor: where the chosen level switches from 1 to 2, a visible line, a **mip band**, crosses the floor because the two sides suddenly differ in sharpness, and it slides along as the camera moves. ## Trilinear filtering **Trilinear** filtering does a bilinear lookup in level `floor(lod)` and another in the next coarser level, then blends the two by the fractional part of `lod`. That is eight texel reads instead of four, and sharpness now changes continuously with distance, so the bands disappear. Trilinear is still **isotropic**: it treats the footprint as a square sized by its longer side. ## Anisotropic filtering Viewed at a grazing angle, the floor's footprint is long and thin: along the view direction a pixel may span 16 texels, across it only 1. Isotropic filtering sizes the lookup by the long side and selects level 4, since 2^4 = 16, which is right along the view direction but 16 times too blurry across it, so the far floor smears into mush. **Anisotropic** filtering measures both axes. With a major axis `pMax` and a minor axis `pMin`: 1. It takes `n = min(ceil(pMax / pMin), maxAniso)` probes, where `maxAniso` is a cap the application sets, commonly up to 16. 2. It selects the level from `pMax / n`, which is finer than the isotropic choice. 3. It spreads the `n` probes along the major axis and averages them, each probe usually a bilinear or trilinear lookup. The floor stays sharp across the view direction and still free of aliasing along it. Most hardware takes only as many probes as the footprint needs, so the cost falls where surfaces are steep and is close to nothing on screen-aligned surfaces such as UI. Probe placement and the approximations used differ between GPUs; the model above is what they share. ## Addressing at the texture's edges Filtering near an edge reads texels outside the 0 to 1 range, and the **addressing mode** decides what those texels are: - **Wrap (repeat)** uses the opposite edge, so a tileable floor texture blends seamlessly across tile boundaries and coordinates above 1 repeat the pattern. - **Clamp to edge** repeats the last texel, which suits decals and non-tiling textures; a tileable texture drawn with clamp shows a faint seam at every tile edge. - **Mirror** flips the texture on every repeat, hiding seams on textures that do not tile but making the symmetry obvious. - **Border** returns a fixed colour outside the range, useful for projected textures that must fade to nothing. ## Comparing the modes | Mode | Texel reads per lookup | Fixes | Still shows | |---|---|---|---| | Nearest, no mips | 1 | nothing; keeps hard texel edges | shimmer, blockiness | | Bilinear with mips | 4 | blockiness, most shimmer | mip bands, grazing blur | | Trilinear | 8 | mip bands | grazing blur | | Anisotropic, n probes | up to about 8 x n | grazing blur | higher bandwidth on steep surfaces | A **LOD bias** shifts `lod` for every lookup on a texture: a negative bias sharpens at the price of aliasing, a positive one blurs. It is a tuning knob, not a substitute for anisotropic filtering, because it moves both axes at once.

  • Why not force the anisotropic cap to its maximum on every texture?
    The extra probes cost texel reads and memory bandwidth on steep surfaces. Most hardware adapts the probe count to the footprint, so screen-aligned surfaces pay little, but on bandwidth-limited hardware with many steep, large textures it adds up. A common policy is a high cap for floors, roads and terrain and a lower one for small or rarely steep textures.
  • What does a negative LOD bias do, and when is it justified?
    It selects finer mip levels than the footprint calls for, so textures look sharper but alias and shimmer more. It is justified when the frame is rendered below output resolution and a temporal technique reconstructs detail: biasing by about log2(render width / output width) keeps texture detail matched to the output rather than the internal resolution.
  • Why does a tileable floor texture show seams at tile edges with clamp addressing but not with wrap?
    Bilinear lookups near an edge need texels beyond it. With wrap they come from the opposite edge, which is exactly the neighbouring tile's content, so the blend is seamless. With clamp they repeat the edge texel, so the blend across the boundary differs from the interior and a thin line appears at every tile edge.

  • Trilinear filtering means sampling three texels.
  • Anisotropic filtering simply picks a sharper mip level for the whole texture.
  • The mip level is chosen from the distance between the camera and the surface.
  • Bilinear filtering on the base level alone stops distant surfaces shimmering.
  • Trilinear filtering also removes the blur on floors seen at grazing angles.