Re: Trilinear single mip level Optimization not always chea
bloodbob said:
Ehh exactly how many samples should be taken? cause atm they are taking one Bilinear sample ( 4 texels ).
Lets do some math with the 1 bilinear sample
Lets say A is the LOD of the Higher Mipmap and B is the lod of the lower mip map.
Now let X be the actual lod.
As X tends towards B from A the bilinear sample will remain constant. Because you are taking the same exact sample from the higher mipmap every time.
So when X is infinitaly close to B it is still fine by your therom. So unless their is some major jump between "infinitaly close to B" then sample at B should be the same as a sample at A.
So now we can subsitute B for A and we can now use the Next lower MipMap C.
Repeat and we find out as long as we are doing linear downsampling we don't need mipmaps at all.
Your theory isn't correct when using 1 blinear sample it probably is correct when using 16 or 20 tap sample ( 4/5 wieghted bilinear samples ) but at that point it is far far far worse preformance wise.
You must take more than 4 samples in order to have both spacial filteringo n one detail level and smooth detail level transitions to prevent mip level discontinuities.
Lets think about a polygon with a texture, that is paralell with the screen, so that no anisotropy is involved.
How many samples are needed ? If sampling from one mip level, you will need between 4 (exact LOD match) and 16.
Trilinear was created because weighting the 16 samples correctly, and both the bandwith and computations needed are twice as much if using 16 smaples than the 8.
A lower level mip map in this case represents a pre-processing computation to average blocks of 4 texels into one at a lower LOD.
So, lets say you have higher level (higher detail) mip level A. Then you have the next one at exactly half resolution at detail level B.
You start at a point where the polygon is at a LOD larger than A, thus magnification. You bilinearly filter this, because at every pixel there are four texels surrounding it to weight.
As you approach detail level A, the texels get closer together in pixel space. At exactly detail level A, bilinear filtering is still OK and produces no aliasing. once past level A, moving to level B you have a few options:
"classic" bilinear, which just jumps to doing bilinear samples of B, and has a very obvious discontinuity.
Or "classic" Trilinear: Sample bilinearly from A and B, and linearly blend them by weight. This removes the aliasing that you would get if you used just A.
Single mip level Trilinear equivalnet:
Sample 16 pixels from A, the 4 that you would for bilinear in addition to the 12 surrouding ones. The weights are identical to what you would get if you created B by a straght linear downfilter of A and did classic trilinear.
Why do this if there are 16 samples while classic trilinear has the 'advantage' of only 8? Because those texels were probably just used by neighboring pixels, and when traversing a block of pixels the number of texels that must be fetched into the cache from an external source is much smaller than the 16 that are mostly alreay in the cache.
Trilinear has similar cache benefits, but involves two mip levels, and can be more complicated to manage in a cache than one mip level.
Additionally, these extra texels are similar to the extras that are needed for anisotropic filtering... and a combined strategy for doing a really good job of caching the needed texels from one mip level might be easier to impiment.
The two patents linked earlier here spell out the equivalence better than I do.
The reality is, if you are doing trilinear for traditional purposes (texture filtering) then it doesn't matter if you use 16 samples from a higher level mip or 4 from each of two mips and blend them.