How does the GLSL sampler determine the minimization and therefore the level of the mipmap texture?

I work with OpenGL ES (via WebGL), but I think this question applies to the full OpenGL profile.

Suppose I create an OpenGL texture with full mipmap levels and I set it to TEXTURE_MIN_FILTER NEAREST_MIPMAP_NEAREST. Also suppose I have a fragment shader that displays this texture. The mipmap level is selected depending on the degree of texture minimization, but how is the degree of minimum selection chosen?

In my case, I synthesize (inside the shader) the texture coordinates that I use to try my texture. In fact, my texture coordinates are not based on any incoming changes. Although mipmapping is enabled on this texture, this does not seem to have any effect. Is this expected? Do I need to calculate the LOD myself and use the offset parameter for the 2D texture? (no texture 2DLOD since I use ES)

+7
source share
2 answers

Blocks of adjacent pixels are computed in parallel. (For example, IIRC PowerVR chips perform a 4x4 block). When you call texture2D in your fragment shader, the sampler retrieves all 16 samples for all 16 pixels at the same time and therefore has adjacency information needed to calculate the minimization level. This is part of why it is so important that neighboring pixels are displayed from neighboring areas of the texture.

Please note that this applies only to fragment shaders. Vertex shaders always use the first level of mipmap (unless you are using the Lod version of 2D texture).

+8
source

You are allowed to arbitrarily calculate the texture coordinates, and the shader will act accordingly ... within one constraint. Your calculations cannot contain conditional logic. These can include changes, uniforms, constants, values ​​selected from other textures, no matter what you want. But at the moment when you glide the same way as the operator ?: There (not to mention the if-statement), you have problems.

And since you're in an OpenGL ES environment, you really don't have the tools to get rid of this problem. Desktop GL 3.0 provides a set of textureGrad functions that allows you to calculate gradients before you achieve conditional logic. But without this you cannot do much.

+2
source

Source: https://habr.com/ru/post/897018/


All Articles