Mipmap management

Started by
3 comments, last by Vilem Otte 7 years, 5 months ago

Hello. I generate a dds texture with mipmaps (2^n x 2^n down to 1 x 1), compress it and use without problems. But I couldnt find information on how to actually use higher/lower quality mipmaps. Do i need to somehow explicitly say which mip do I want now, or GPU somehow knows which one is most suitable?

Advertisement

Inside the pixel shader, the default texture lookup functions use screen space derivatives to calculate the mip level required. In other shader stages, you typically specify the exact level you wish to sample.

Also note that your texture and/or sampler object should be configured correctly

Configured correctly? All i do is load dds with pregenerated mipmaps and the whole magic is done automatically in the background. And thats what im worried about, i dont have manual control over it. Am i missing something?

For example in Dx11, you have to make sure that your ID3D11SamplerState is created correctly.
For example, setting both minLOD and maxLOD to zero will always sample level 0 (as in do not use mipmaps).
Also the filter on your sampler has influence on the miplevel calculations (bilinear vs trilinear for example)

Inside your shader, you can also control the default 'automatic' mip map calculation
As mentioned, you can use a different sample functions (dx11 syntax):
- SampleLevel -> sample a specific level (and that level is a float so you can have nice interpolation)
- SampleGrad -> sample with specific derivatives (witch are used to control the 'default' mip calulation).
(for other functions see msdn)

Hello,

in OpenGL the actual mipmap level is calculated as:


float miplevel(in vec2 texCoord)
{
    vec2 dx_texCoord = dFdx(texCoord);
    vec2 dy_texCoord = dFdy(texCoord);
    float delta = max(dot(dx_texCoord, dx_texCoord), dot(dy_texCoord, dy_texCoord));
    return max(0.5 * log2(delta) - 1.0, 0.0);
}

As this is returning float, you can either take floor and ceil of that value and linearly interpolate between those (resulting in linear mip filter), or just take one of those values (resulting in point/nearest mip filter).

Assuming you would like some anisotropic filtering there are multiple ways. In general what most vendor implementations do is to take N samples in circle/ellipse and interpolate those (as you have multiple samples of texture coordinates you can actually determine the ideal direction).

There are also another (hacky) ways (like F.e. rip-mapping, which is kind of anisotropic filter). Although as anisotropic filtering is now supported in most hardware for years, I doubt anyone supports this these days.

EDIT: Fixing typos.

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

This topic is closed to new replies.

Advertisement