How does a GLSL sampler determine the minification, and thus the mipmap level, of a texture?

后端 未结 2 1169
离开以前
离开以前 2021-01-05 10:37

I am working with OpenGL ES (via WebGL), but I think this question is applicable to the full OpenGL profile as well.

Suppose I create an OpenGL texture with full mip

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-05 11:32

    Blocks of adjacent pixels are computed in parallel. (IIRC the PowerVR chips do a 4x4 block at a time, for example.) When you call texture2D in your fragment shader, the sampler is fetching all 16 samples for all 16 pixels at once, and so has adjacency information needed to calculate the minification level. This is part of why it's so important for adjacent pixels to sample from nearby areas of the texture.

    Note that this only applies to fragment shaders. In vertex shaders the first mipmap level is always used, (unless you use the Lod version of texture2D is used.)

提交回复
热议问题