Question

The textureQueryLod call returns two components:

  1. x - Tells in which proportion are mipmap levels used.
  2. y - Level of detail.

Are they both same?

Was it helpful?

Solution

When you have a problem like this and find it cannot be sufficiently answered by looking at the basic API documentation for a class of GLSL functions, you should consult the formal GLSL specification.

If you read the specification, specifically Section 8.9.1 - Texture Query Functions, you will come across a very detailed explanation of the "used" mipmap level. In short, this value is the fractional component that would be used to select the nearest mipmap level(s) during during minification+mipmap filtering.

Recall that there are two possible ways to resolve a mipmap sample:

  1. Interpolate between the two nearest mipmap LODs (linear mip filter)

    • This is the 3rd linear in a tri-linear filter

  2. Sample the closest mipmap LOD (nearest mip filter)

With that out of the way, you should have the theoretical basis to understand the pseudo-code presented in the specification on pp. 155:

float ComputeAccessedLod(float computedLod)
{
    // Clamp the computed LOD according to the texture LOD clamps.
    if (computedLod < TEXTURE_MIN_LOD) computedLod = TEXTURE_MIN_LOD;
    if (computedLod > TEXTURE_MAX_LOD) computedLod = TEXTURE_MAX_LOD;
    // Clamp the computed LOD to the range of accessible levels.
    if (computedLod < 0.0)
        computedLod = 0.0;
    if (computedLod > (float)
        maxAccessibleLevel) computedLod = (float) maxAccessibleLevel;
    // Return a value according to the min filter.
    if (TEXTURE_MIN_FILTER is LINEAR or NEAREST) {
        return 0.0;
    } else if (TEXTURE_MIN_FILTER is NEAREST_MIPMAP_NEAREST
               or LINEAR_MIPMAP_NEAREST) {
        return ceil(computedLod + 0.5) - 1.0;
    } else {
        return computedLod;
    }
}

There are three branches in this pseudo-code:

  1. Handles the situation where a sampler does not use mipmapping at all
    • The accessed LOD is always 0.0
  2. Handles the situation where a sampler uses a nearest mip filter
    • The accessed LOD is the closest integer
  3. Handles the situation where a sampler uses a linear mip filter
    • The accessed LOD is between the two nearest integer LODs
    • Two LODs would be sampled in this case, and the single returned sample is interpolated between both based on the fractional part of this value

The second component returned by textureQueryLod (...) is the unclamped integer LOD.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top