Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 slow but pretty algorithm, like Lanczos resampling.

Does it make sense? Will I get any quality gain on modern graphics cards?

like image 536
GhassanPL Avatar asked May 06 '09 21:05

GhassanPL


1 Answers

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.

like image 170
Nils Pipenbrinck Avatar answered Nov 02 '22 23:11

Nils Pipenbrinck