*it's "MACHO gracias", not "mucho gracias"
*
Anisotropic filtering cannot work pre-render, unless you know exactly how and where the texture will be applied. The aniso filtering is done in the rasterization stage (during the texel lookup phase).
I don't know how current IHVs do implement it, but here's a story...
Here beginneth FakeAniso Cheap Hack (tm):
For simplicity, we'll take nearest sampling mipmapped textures. The mipmaps are build so that each level is obtained by halving the previous level, using a 2x2 average box. The TMU will automagically determine the LOD, based on distance: 0 - 1 - 2 - 3 - 4 ... (those are LOD #s).
Let's take a distance which falls in LOD#1. It is simply an averaged version of the LOD#0. Moreover, it is
uniformly averaged in all planar directions -- a
circular filter, approximated by a
square.
This is okay in particular conditions, but if the texture is being seen under a certain angle (ie: floor texture) it's not enough. It must be an
elliptical filter, approximated by a
rectangle. This means you can't use a 2x2 box. You'll be needing an WxH box.
So, what is to be done? First of all, you can't extract the original pixels from the averaged pixel. So we FORCE the first LOD as far as we can: 0 - 0 - 0 - 1 - 2 .... Okay, we got our pixels, but we still need to have them averaged, using our WxH box.
The hardware cannot do that automatically, so we have to do it ourselves. How? Multipass rendering. We render the texture with original values, then jitter the texture, by jittering the vertex positions/texture coordinates in the correct direction. This step should be overlayed with alpha blending. The process can be repeated several times, by increasing the jittering while decreasing the alpha blending factor.
Caveats:
- interferes with GL_EXT_texture_lod
- interferes with other built-in multipass capabilities of certain renderers (such as MesaFX)
- might be affected by bi-/tri-linear filtering
- interferes with alpha blending
- induces slowness, inherent to multipass techniques
VSA100 users: the native jittering capability of the Napalm could do the trick, at least to some extent. But you'll loose FSAA. And it's beyond the scope of this file, since it's fragment jittering, not vertex jittering. Too many approximations already... And probably Voodoo2 users would find aniso neat, on their hardware, too.
Here endeth FakeAniso Cheap Hack (tm):
The compulsory credits:
Marc Olano, Shrijeet Mukherjee, Angus Dorbie for the wonderful "Vertex based anisoptropic Texturing"
Koolsmoky & big H.(S) for pointing me to the aforementioned doc and the fruitful discussions we've had while I was trying to understand the algorithm. I also remember that Syed Aqueel Hamdani gave me a link to that file too...
So I hope I didn't forget anyone!
<memo to myself> now copy the damn thing somewhere for your own reference, otherwise you might forget how it's done...
*ave, Commodus, morituri te salutant*