Texture Filter Types
It’s rare that the pixels of a texture image match one-to-one with actual screen pixels when a texture is visible onscreen. Usually, it is the case that either a single pixel of the texture is stretched over multiple screen pixels (texture magnification–the texture image is stretched bigger), or the opposite, that multiple pixels of a texture contribute to the color of a single screen pixel (texture minification–the texture image is squished smaller). Often, a single polygon will have some texture pixels that need to be magnified, and some pixels that need to be minified (the graphics card can handle both cases on a single polygon).
You can control how the texture looks when it is magnified or minified by setting its filter type.
filterType is a value from the FilterType enum of SamplerState (Texture in Panda3D versions prior to 1.9). There is a separate filterType setting for magnification and for minification. For both magnification and minification, the filterType may be one of:
Sample the nearest pixel
Sample the four nearest pixels, and linearly interpolate them
For minification only, in addition to the above two choices, you can also choose from:
Point sample the pixel from the nearest mipmap level
Bilinear filter the pixel from the nearest mipmap level
Point sample the pixel from two mipmap levels, and linearly blend
Bilinearly filter the pixel from two mipmap levels, and linearly blend the results. This is also called trilinear filtering
The default filter type for both magnification and minification is
Consider the visual effects of the various filter types on magnification and minification of the following texture:
FT_nearest is used only to achieve a special pixelly effect.
FT_linear is a good, general-purpose choice, though it isn’t perfect.
Many graphics tutorials will go on for pages and pages about exactly what mipmapping means and how it all works inside. We’ll spare you those details here; but you should understand the following things about mipmapping:
It requires 33% more texture memory (per mipmapped texture), but it renders quickly.
It helps the texture look much smoother than filtering alone when it is minified.
Mipmapping doesn’t have anything at all to do with magnification.
It has a tendency to blur minified textures out a little too much, especially when the texture is applied to a polygon that is very nearly edge-on to the camera.
There are four different filter types that involve mipmapping, but you almost
always want to use just the last one,
FT_linear_mipmap_linear. The other
modes are for advanced uses, and sometimes can be used to tweak the mipmap
artifacts a bit (especially to reduce point 4, above). If you don’t understand
the description in the table above, it’s not worth worrying about.
There is one final addition to the texture filtering equation: you can enable anisotropic filtering on top of any of the above filter modes, which enables a more expensive, slightly slower rendering mode that generally produces superior effects. In particular, anisotropic filtering is usually better at handling texture minification than mipmapping, and doesn’t tend to blur out the texture so much.
To enable anisotropic filtering, you specify the degree:
The degree should be a power-of-two integer number. The default value is 1, which indicates no anisotropic filtering; set it to a higher number to indicate the amount of filtering you require. Larger numbers are more expensive but produce a better result, up to the capability of your graphics card. Many graphics cards support up to 16x anisotropic filtering.