Bilinear and trilinear - can't see a difference

I’m making an application that shows differences between different texture filtering methods. In my mind, from worse to best, it is:
normal->linear->bilinear->trilinear->anisotropic.

Linear works well, smoothing the texture. Then bilinear makes the texture looks better when it’s far, and it’s also faster. Anisotropic is a great effect that is easily noticeable over any other filter.

But I just can’t see any difference between bilinear and trilinear. I know trilinear is supposed to have a less foggy effect that bilinear, like a trilinear texture at 10 meters have the same quality as a bilinear texture at 5 meters.

It just doesn’t work for me. I have a Geforce Titanium with latest drivers and Windows XP. I know it does support trilinear because I can change it in my drivers settings(force bilinear, force trilinear or force none, but it doesn’t seems to change anything). Now I was thinking that my card may use trilinear whatever I choose, just because trilinear looks better without too much performance loss.

Or maybe my coding is wrong? I simply use

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

for bilinear, and then

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);

for trilinear. Mip mapping is actived for both indeed. Anyone have experienced with bilinear and trilinear?

I’m not sure why trilinear would be faster, but the difference between bilinear and trilinear will be subtle. If you use a texture that is black on the left and white on the right, and zoom in so that the white to black transition takes tens of pixels on the screen, I suspect it will be fairly clear.

I meant that bilinear is faster than linear because mipmaps are pre-generated.

If the difference between bilinear and trilinear is really small I think I won’t care about it and just use trilinear.

There are a few things you should understand when learning & experimenting with this stuff:

Magnification filters should only be set to bilinear for best quality, there is no MIP map support for magnification filters, it makes no sense. Only minification filters support MIP map texture. MIPMAP tokens in a magnification filter are illegal.

Under heavy (> 2:1) minification GL_LINEAR should begin to alias until it becomes a shimmering mess, almost indistinguishable from NEAREST. This is when MIP mapping should really improve things. Any lower degree of minification will be pretty indistinguishable from bilinear so to test MIP mapping make sure you really shrink the texture scale on screen.

When MIP mapping there are different filters available, I’ll focus on the most interesting two. One MIP map filter is a bilinear filter: LINEAR_MIPMAP_NEAREST, this should stop the aliasing under heavy minification but show visible transitions between levels of texture resolution across a polygon drawn in perspective under appropriate conditions.

LINEAR_MIPMAP_LINEAR is trilinear MIP mapping and will eliminate all aliasing and hide the transitions between levels of resolution. However MIP mapping is a symmetric filter and under some circumstances (where s coords or t coords have very different scales on screen after projection) it will lose too much detail and blur the texture (the benefit is there is no texture aliasing, this blurring is one of the prices you pay).

Anisotropic texture will sharpen up the texture in situations where detail has been lost due to the ratio of s & t coordinate derivatives in screenspace. To test anisotropic filtering make sure you have a situation where s & t after projection have very different scales, such as looking down the white line in the middle of a road.

There are different degrees of anisotropic filtering which you have control over, the degree of anisotropic filtering 2:1, 4:1 etc is the ratio of ds/dt or dt/ds derivatives that the filter can sharpen up. (I’m over simplifying for illustration & assuming ds & dt are orthogonal after projection which is bogus, but in principal it’s the same if you look at major & minor footprint axes in texture space).

nearest->linear->bilinear->bilinear_mipmap->trilinear_mipmap->anisotropic_2:1->anisotropic_4:1 etc

Note “nearest” instead of “normal”. This is more complex that this linear progression suggests because anisotropic filtering can be applied to non trilinear MIP map filters and can bring them on par of better than basic trilinear MIP map texture. In addition there are a couple of other types of MIP mapping (nearest_mipmap_nearest and nearest_mipmap_linear) supported by OpenGL that further cloud the issue but probably belong between linear and bilinear filtering but it depends a great deal on the circumstances in which they are used.

P.S.

GL_LINEAR is bilinear.

GL_LINEAR_MIPMAP_LINEAR is trilinear MIP mapping

GL_LINEAR_MIPMAP_NEAREST is bilinear MIP mapping

GL_NEAREST_MIPMAP_LINEAR is linear MIP mapping

Linear, bilinear or trilinear refers to the number of interpolation axes in the texture filter, not the number of times the word “linear” appears in the code. OpenGL tokens use “LINEAR” both to describe 2D and 1D interpolation depending on location.

P.P.S.

Any form of MIP mapping will almost always be faster for minification than GL_LINEAR on modern hardware because of the texture cache behaviour. For the price of an extra 1/3 texture memory useage you get faster performance and better quality.

The real decision is whether you go for GL_LINEAR_MIPMAP_LINEAR vs GL_LINEAR_MIPMAP_NEAREST and these days you’re probably better off with the higher quality, hardware makers actually squeeze the trilinear transition zone depending on the display settings making performance almost equivalent.

The actual calculation of the MIP level texture images is a small one-time overhead that shouldn’t be your major concern for most applications.

Thanks that clarified many things. Just have a last question:

GL_LINEAR is bilinear.

GL_LINEAR_MIPMAP_LINEAR is trilinear MIP mapping

GL_LINEAR_MIPMAP_NEAREST is bilinear MIP mapping

GL_NEAREST_MIPMAP_LINEAR is linear MIP mapping
Then GL_NEAREST would be linear?

>> Then GL_NEAREST would be linear?

No. Just reread dorbie’s posts :
“Linear, bilinear or trilinear refers to the number of interpolation axes in the texture filter, not the number of times the word “linear” appears in the code.”

That means that to have linear filter, you need a 1D texture.
Or a 2D texture when linear filtering is only done horizontally OR vertically, but that is not possible with the hardware and APIs I am aware of. It would not have much uses anyway.

GL_NEAREST can be called “point filtering” too. But ‘nearest’ is more precise, it actually takes the color of the nearest texel. Linear[bilinear] interpolation will average the 2[4] nearest texels of the 1D [2D] texture depending on their distance.

Ok now it’s all clear thanks!

Yup, nearest is point filtering (no linear interpolation at all).

One other thing, just for the record and to make it absolutely clear, as I listed in the table, 2D textures can have linear filtering in hardware, if you enable MIP mapping and have NEAREST_MIPMAP_LINEAR, the MIP lod interpolates the two point samples , one from each each MIP level. It is a pretty uninteresting filter but supported by OpenGL and is linear filtering of a 2D texture (albeit with a 3rd axis from the MIP levels).