views:

758

answers:

2

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?

+1  A: 

What is motivating you to try? Are the mipmaps you have currently being poorly generated? (i.e. have you looked?) Bear in mind your results will often still be (tri)linearly interpolated anyway, so between that an motion there are often steeply diminishing returns to improved resampling.

simon
Well, the current algorithm can't be very slow, and therefore can't be that good. The cost of pregenerating and storing the mipmaps is low, but I don't know if it's worth it if the results aren't going to be that noticeable.
Kronikarz
I'm not sure how you're doing it now, but these days you can have the GPU generate them, which can be fast and pretty good. More importantly though, you are either looking at these at the wrong resolution, or more likely, linearly interpolating between them. So your beautifully crafted hand-resampled versions usually aren't seen... hence diminishing returns. Are you actually seeing artifacts, or is this purely academic?
simon
+1  A: 

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.

Nils Pipenbrinck
Actually, the "average four pixels" may not be the best way to create mipmaps.http://www.number-none.com/product/Mipmapping,%20Part%201/index.html
Marco Mustapic