Contents

Adding mipmap filtering to samplers

Specify how the GPU samples mipmaps in your textures.

Overview

By default, samplers sample data only from mipmap 0. If your texture contains more than one mipmap, and you want it to sample the lower-level mipmaps, you need to specify this behavior when you create the texture sampler.

Create the sampler in your app

If you’re creating an MTLSamplerState instance, create the MTLSamplerDescriptor instance and set its mipFilter property. The following code uses linear filtering for the minification and magnification filter, and uses linear filtering for mipmaps. This combination is usually called trilinear filtering. With this configuration, the GPU chooses the two mipmaps nearest in size and generates a sample by linearly filtering four pixels from each mipmap. Then it blends those two values with a linear interpolation to generate the final sample.

Alternatively, any of these filters could filter from the nearest pixel, instead of a linear filter, resulting in fewer sampled pixels but lower quality. Ultimately, you need to decide the right tradeoffs between sampling performance and quality for your app.

Create the sampler in your shader

If you prefer to create samplers in your shader, specify the mipmap filtering there instead of in your app:

constexpr sampler s(filter::linear, mip_filter::linear)

See Also

Texture mipmapping