19

我想知道如果我使用自己的算法而不是内置的自动算法来预生成它们,纹理 mipmap 的质量是否会更好。我可能会使用缓慢但漂亮的算法,例如 Lanczos 重采样。

是否有意义?我会在现代显卡上获得任何质量提升吗?

4

4 回答 4

14

有充分的理由生成自己的 mipmap。但是,下采样的质量不是其中之一。

游戏和图形程序员过去曾尝试过各种下采样算法。最后结果证明,非常简单的“平均四个像素”方法给出了最好的结果。此外,更高级的方法在理论上在数学上更正确,它们往往会从 mipmap 中获得很多清晰度。这给人一种扁平的外观(试试看!)。

出于某些(对我来说无法理解)原因,简单平均方法似乎在抗锯齿和保持 mipmap 清晰之间取得了最佳折衷。

但是,您可能希望使用 gamma 校正来计算 mipmap。OpenGL 不会自行执行此操作。这可以产生真正的视觉差异,尤其是对于较暗的纹理。

这样做很简单。而不是像这样平均四个值:

float average (float a, float b, float c, float d)
{
  return (a+b+c+d)/4
}

做这个:

float GammaCorrectedAverage (float a, float b, float c, float d)
{
  // assume a gamma of 2.0 In this case we can just square
  // the components. 
  return sqrt ((a*a+b*b+c*c+d*d)/4)
}

此代码假定您的颜色分量已标准化为 0 到 1 的范围内。

于 2009-05-06T23:45:05.993 回答
2

As an addition to this question, I have found that some completely different mipmapping (rather than those simply trying to achieve best down-scaling quality, like Lanczos filtering) algorithms have good effects on certain textures.

For instance, on some textures that are supposed to represent high-frequency information, I have tried using an algorithm that simply takes one random pixel of the four that are being considered for each iteration. The results depend much on the texture and what it is supposed to convey, but I have found that it gives great effect on some; not least for ground textures.

Another one I've tried is taking the most deviating of the four pixels to preserve contrasts. It has even fewer uses, but they do exist.

As such, I've implemented the option to choose mipmapping algorithm per texture.

EDIT: I thought I might provide some examples of the differences in practice. Here's a piece of grass texture on the ground, the leftmost picture being with standard average mipmapping, and the rightmost being with randomized mipmapping:

Average mipmapping, trilinear filtering Random mipmapping, trilinear filtering

I hope the viewer can appreciate how much "apparent detail" is lost in the averaged mipmap, and how much flatter it looks for this kind of texture.

Also for reference, here are the same samples with 4× anisotropic filtering turned on (the above being tri-linear):

Average mipmapping, 4× anisotropic filtering Random mipmapping, 4× anisotropic filtering

Anisotropic filtering makes the difference less pronounced, but it's still there.

于 2013-10-10T05:38:18.760 回答
2

这取决于您展示的资产类型。Lanczos 过滤器更接近理想的低通过滤器,如果您并排比较 mip 映射,结果会很明显。大多数人会将混叠误认为是锐度——这又取决于你的资产是否倾向于包含高频——我肯定见过箱式滤波器不是一个好选择的情况。但是由于无论如何都会对 mip 图进行线性插值,因此增益可能不会那么明显。还有一件事要提——大多数人使用箱式过滤器并将输出作为输入传递到下一个阶段——这样你会失去精度和视觉能量(尽管伽马会帮助这个)。

于 2011-07-16T12:33:47.163 回答
2

是什么促使你尝试?您当前的 mipmap 是否生成不佳?(即您看过吗?)请记住,无论如何,您的结果通常仍然是(三)线性插值的,因此在运动之间通常会急剧减少改进重采样的回报。

于 2009-05-06T21:40:28.837 回答