[ACCEPTED]-Does it make sense to use own mipmap creation algorithm for OpenGL textures?-mipmaps

Score: 14

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

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

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

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

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

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

Do 3 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 2 are normalized to be in the range of 0 to 1 1.

Score: 2

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

Score: 2

It depends on the kind of assets you display. Lanczos 20 filter gets closer to ideal low-pass filter 19 and the results are noticeable if you compare 18 the mip maps side by side. Most people will 17 mistake aliasing for sharpness - again it 16 depends whether your assets tend to contain 15 high frequencies - I've definitely seen 14 cases where box filter was not a good option. But 13 since the mip map is then linearly interpolated 12 anyway the gain might not be that noticeable. There 11 is another thing to mention - most people 10 use box filter and pass the output as an 9 input into the next stage - in this way 8 you lose both precision and visual energy 7 (although gamma will help this one). If 6 you can come up with code that uses arbitrary 5 filter (mind you that most of them are separable 4 into two passes) you would typically scale 3 the filter kernel itself and produce mip 2 map levels from the base texture, which 1 is a good thing.

Score: 2

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

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

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

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

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

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

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

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

More Related questions