Does it make sense to use own mipmap creation algorithm for OpenGL textures?

后端 未结 4 1222
清歌不尽
清歌不尽 2021-02-05 09:26

I was wondering if the quality of texture mipmaps would be better if I used my own algorithm for pre-generating them, instead of the built-in automatic one. I\'d probably use a

4条回答
  •  失恋的感觉
    2021-02-05 10:33

    There are good reasons to generate your own mipmaps. However, the quality of the downsampling is not one of them.

    Game and graphic programmers have experimented with all kinds of downsampling algorithms in the past. In the end it turned out that the very simple "average four pixels"-method gives the best results. Also more advanced methods are in theory mathematical more correct they tend to take a lot of sharpness out of the mipmaps. This gives a flat look (Try it!).

    For some (to me not understandable) reason the simple average method seems to have the best tradeoff between antialiasing and keeping the mipmaps sharp.

    However, you may want to calculate your mipmaps with gamma-correction. OpenGL does not do this on it's own. This can make a real visual difference, especially for darker textures.

    Doing so is simple. Instead of averaging four values together like this:

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

    Do this:

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

    This code assumes your color components are normalized to be in the range of 0 to 1.

提交回复
热议问题