Specify how the GPU samples mipmaps in your textures.
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 are creating a
MTLSampler object, create the
MTLSampler object and set its
mip 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: