OpenImageIO Texture Filtering Options: MIP Mapping and Anisotropic Filtering Explained

OpenImageIO's TextureSystem supports five MIP mapping modes, four interpolation kernels, and configurable anisotropic filtering ratios up to 32 samples to balance quality and performance.

The TextureSystem class in the AcademySoftwareFoundation/openimageio repository provides comprehensive texture filtering options for production rendering pipelines. These controls allow developers to fine-tune sampling behavior for 2D textures, shadow maps, and environment maps through a combination of MIP mapping strategies and anisotropic filtering parameters.

MIP Mapping Modes in TextureSystem

The foundation of texture filtering options in OpenImageIO begins with the Tex::MipMode enumeration defined in src/include/OpenImageIO/texture.h. This enum determines how the system selects and blends between different resolution levels of a MIP-mapped texture.

Available MIP Mapping Modes

  • Default – Equivalent to Aniso, providing the highest quality anisotropic filtering.
  • NoMIP – Disables MIP mapping entirely, sampling only from the highest-resolution level.
  • OneLevel – Selects a single appropriate MIP level without blending between levels.
  • Trilinear – Blends between two adjacent MIP levels using standard trilinear filtering.
  • Aniso – Combines trilinear blending with anisotropic weighting for high-quality filtering of oblique surfaces.

Anisotropic Filtering Controls

Anisotropic filtering represents one of the most powerful texture filtering options for maintaining clarity on surfaces viewed at grazing angles. The TextureOpt structure controls this behavior through the anisotropic member variable.

Configuring Anisotropic Ratio

The uint16_t anisotropic field sets the upper bound on the anisotropic ratio—the maximum number of samples taken along the major axis of the projected texture footprint. The default value is 32, providing high-quality filtering for demanding production scenarios. Setting this value to 1 effectively disables anisotropic filtering, while larger values increase quality at the cost of additional texture samples.

The core mathematical calculations for anisotropic aspect ratios reside in src/libtexture/texture_pvt.h, specifically within the anisotropic_aspect helper functions.

Conservative Filtering

The bool conservative_filter member controls whether the filtering ellipse prefers over-blurring versus potential aliasing. When set to true (the default), the system errs on the side of softness to hide high-frequency ringing artifacts. Disabling this option may yield sharper results but risks aliasing on high-contrast texture details.

Interpolation Modes for Texture Sampling

Within each selected MIP level, the Tex::InterpMode enum determines the reconstruction filter applied to texel samples. This represents a critical texture filtering option for controlling intra-level quality.

  • Closest – Nearest-neighbor sampling (point sampling) with no interpolation.
  • Bilinear – Linear interpolation across the four surrounding texels.
  • Bicubic – Cubic interpolation using sixteen texels for higher-quality reconstruction.
  • SmartBicubic – Automatically selects bicubic when magnifying and bilinear when minifying (default behavior).

Advanced Texture Filtering Options

Beyond the core MIP and interpolation controls, TextureSystem provides additional parameters for specialized rendering scenarios.

Stochastic Sampling

The stochastic attribute enables randomized sampling to reduce pattern artifacts in noisy textures. This bit-field accepts values where bit 1 enables mip-level stochastic sampling and bit 2 enables anisotropic stochastic sampling. Setting stochastic=3 enables both modes simultaneously.

Configure this through the attribute system:

ts->attribute("options", "stochastic=3");

Texture Wrapping Modes

The Tex::Wrap enum controls boundary behavior for texture coordinates outside the [0,1] range. Options include Black, Clamp, Periodic, Mirror, PeriodicPow2, and PeriodicSharedBorder. These apply independently to the s, t, and r dimensions through the swrap, twrap, and rwrap fields.

Blur and Derivative Scaling

The sblur, tblur, and rblur parameters add fixed blur radii (specified as fractions of texture width), while swidth, twidth, and rwidth scale the derivatives used to compute the filtering ellipse. These controls allow artistic adjustment of texture sharpness independent of the automatic filtering calculations.

Implementation Architecture

The texture filtering options described above are implemented across several key source files in the OpenImageIO repository:

Practical Code Examples

High-Quality Anisotropic Lookup

// Create a shared TextureSystem
std::shared_ptr<OIIO::TextureSystem> ts = OIIO::TextureSystem::create();

// Configure for high-quality anisotropic filtering
OIIO::TextureOpt opt;
opt.anisotropic = 16;                    // Limit anisotropy to 16×
opt.mipmode    = OIIO::Tex::MipMode::Aniso;
opt.interpmode = OIIO::Tex::InterpMode::Bilinear;

float result[3];
bool ok = ts->texture("myTexture.exr", opt,
                     0.32f, 0.71f,          // s, t coordinates
                     0.001f, 0.0f,          // dsdx, dtdx derivatives
                     0.0f, 0.001f,          // dsdy, dtdy derivatives
                     3, result);

Fast Nearest-Neighbor Lookup

// Configure for maximum performance
OIIO::TextureOpt fastopt;
fastopt.mipmode    = OIIO::Tex::MipMode::NoMIP;
fastopt.interpmode = OIIO::Tex::InterpMode::Closest;
fastopt.anisotropic = 1;   // Disables anisotropic sampling

float gray;
ts->texture("checker.png", fastopt,
            0.5f, 0.5f, 0,0,0,0, 1, &gray);

Stochastic Trilinear with Custom Wrapping

// Enable stochastic sampling for reduced pattern artifacts
OIIO::TextureOpt stochastic_opt;
stochastic_opt.mipmode = OIIO::Tex::MipMode::Trilinear;
stochastic_opt.interpmode = OIIO::Tex::InterpMode::Bilinear;
stochastic_opt.swrap = OIIO::Tex::Wrap::Mirror;
stochastic_opt.twrap = OIIO::Tex::Wrap::Mirror;
stochastic_opt.anisotropic = 8;

// Enable stochastic sampling via attribute system
ts->attribute("options", "stochastic=3");

Summary

OpenImageIO's TextureSystem provides comprehensive texture filtering options for production rendering:

  • Five MIP mapping modes (Default, NoMIP, OneLevel, Trilinear, Aniso) control level selection and blending strategies.
  • Configurable anisotropic filtering via the anisotropic field in TextureOpt, supporting ratios up to 32 samples for high-quality oblique surface rendering.
  • Four interpolation modes (Closest, Bilinear, Bicubic, SmartBicubic) determine reconstruction quality within individual MIP levels.
  • Advanced controls including stochastic sampling, conservative filtering, wrap modes, and blur/derivative scaling for artistic and technical flexibility.

Frequently Asked Questions

What is the default texture filtering mode in OpenImageIO?

The default configuration uses MipMode::Default (equivalent to Aniso) combined with InterpMode::SmartBicubic. This provides high-quality anisotropic filtering with automatic selection between bicubic interpolation during magnification and bilinear during minification.

How do I disable MIP mapping for pixel-perfect texture lookups?

Set mipmode to OIIO::Tex::MipMode::NoMIP in your TextureOpt structure. This forces the system to sample exclusively from the highest-resolution texture level, effectively disabling all MIP mapping operations and level blending.

What is the maximum anisotropic filtering ratio supported?

The anisotropic field in TextureOpt accepts values up to the maximum representable by uint16_t (65535), though practical implementations typically use values between 1 and 32. The default value of 32 provides high-quality results for most production rendering scenarios while maintaining reasonable performance.

How does stochastic sampling improve texture filtering quality?

Stochastic sampling randomizes the selection of MIP levels and anisotropic samples when enabled via the stochastic attribute. This jittering breaks up regular sampling patterns that can cause moiré or banding artifacts in noisy textures, producing more natural results at the cost of slightly increased variance that typically averages out over multiple samples.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →