GLSL 采样器如何确定纹理的缩小以及 mipmap 级别? [英] How does a GLSL sampler determine the minification, and thus the mipmap level, of a texture?

查看:80
本文介绍了GLSL 采样器如何确定纹理的缩小以及 mipmap 级别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 OpenGL ES(通过 WebGL),但我认为这个问题也适用于完整的 OpenGL 配置文件.

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

假设我创建了一个具有完整 mipmap 级别的 OpenGL 纹理,并将其 TEXTURE_MIN_FILTER 设置为 NEAREST_MIPMAP_NEAREST.还假设我有一个片段着色器来采样这个纹理.mipmap级别是根据纹理的缩小程度来选择的,但是缩小程度是如何选择的呢?

Suppose I create an OpenGL texture with full mipmap levels, and I set its TEXTURE_MIN_FILTER to NEAREST_MIPMAP_NEAREST. Also suppose that I have a fragment shader that samples this texture. The mipmap level is chosen based on the degree of minification of the texture, but how is the degree of minification chosen?

在我的例子中,我正在合成(在着色器中)用于对纹理进行采样的纹理坐标.事实上,我的纹理坐标不是基于任何传入的变量.即使我在这个纹理上启用了 mipmapping,它似乎也没有任何效果.这是预期的吗?我需要自己计算 LOD 并使用纹理 2D 的偏差参数吗?(没有texture2DLOD,因为我用的是ES)

In my case, I am synthesizing (inside the shader) the texture coordinates that I use to sample my texture. In fact, my texture coordinates are not based on any incoming varyings. Even though I have mipmapping enabled on this texture, it doesn't seem to have any effect. Is this expected? Do I need to compute the LOD myself and use the bias parameter to texture2D? (there is no texture2DLOD, since I'm using ES)

推荐答案

并行计算相邻像素块.(例如,IIRC PowerVR 芯片一次执行 4x4 块.)当您在片段着色器中调用 texture2D 时,采样器一次获取所有 16 个像素的所有 16 个样本,因此具有计算缩小所需的邻接信息等级.这就是为什么相邻像素从纹理的附近区域采样如此重要的部分原因.

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.

请注意,这只适用于片段着色器.在顶点着色器中,始终使用第一个 mipmap 级别,(除非您使用 Lod 版本的 texture2D.)

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.)

这篇关于GLSL 采样器如何确定纹理的缩小以及 mipmap 级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆