c++ - 在像素的最近邻插值 OpenGL 中心的情况下会发生什么

标签 c++ opengl nearest-neighbor

当在纹理中计算最近邻插值的像素与两个相邻像素的距离相同,并且该像素与它所在的两个像素的距离相等时,发生最近邻插值时会发生什么尝试在放大的情况下正确插值新像素。

OpenGL 是否采用两个像素并通过从两个相同长度距离的平均值中插入纹理的颜色,或者发生其他事情?

最佳答案

spec非常清楚如何从纹理坐标中选择纹素:

缩小

第 8.14 节指定了缩小行为(我在这里跳过了很多关于环绕模式等的内容,并解释了 2D 情况):

Let [s(x,y), t(x,y)] be the texture coordinates at screen position (x,y). Now we define u(x,y) = s(x,y) * texture_width and v(x,y) = t(x,y) * texture_height. In case of nearest neighbor interpolation, the texel is given by the integer coordinates (i,j), where i = floor(u(x,y)) and j = floor(v(x,y)).

让我们举个例子:假设我们有一个大小为 2x1 的纹理和一个 [0.5, 0.5] 的查找位置。在这种情况下,u(x,y) = 0.5 * 2 = 1 和 v(x,y) = 0.5 * 1 = 0.5。现在我们得到 i = floor(1) = 1 和 j = floor(0.5) = 0。因此,结果将是右侧纹素的颜色。

放大倍数

第 8.15 节指出放大的行为与缩小的行为完全相同。

关于c++ - 在像素的最近邻插值 OpenGL 中心的情况下会发生什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38030310/

相关文章:

c++ - 在两个独立的 opengl 窗口中渲染一个独特的视频流

python - 模拟相关的多变量数据

c++ - 通过函数指针调用函数 - 是否取消引用指针?有什么不同?

c++ - 为什么 std::count(_if) 返回 iterator::difference_type 而不是 size_t?

c++ - new T(...) 与 std::make_unique<T>(...).release()

python - kd-tree 可以用点积构建吗?

c# - 找不到某些 Boost 库函数

c++ - 如何使用 C++ 函数指针作为 C 函数指针/回调的参数

android - GLSL IF 速度与乘数

python - 在 opengl 中混合 2d 和 3d(使用 pyglet)