1. Why does texture filter (texture filter) be required during texture sampling )?
Our texture is to be attached to the surface of a 3D image, while the pixel center on the 3D image and the Texel center on the texture are not the same (pixel does not necessarily correspond to the sample center Texel on the texture ), the size is not necessarily the same. When a texture is larger than a 3D image surface, a pixel is mapped to many texture pixels. When a dimension is smaller than a 3D image surface, many pixels are mapped to the same texture.
When these situations occur, the textures become blurred or misaligned or mosaic. To solve this problem, we must use technology to smooth the correspondence between Texel and pixel. This technology is texture filtering.
Different filtering modes have different computing complexity, which results in different results. From simple to complex filtering modes, including nearest point sampling, bilinear, trilinear, and anisotropic filtering ).
Before learning about this, it is necessary to know what is mipmap and when it is the same sex and the opposite sex.
2. What is mipmap?
Mipmap was proposed by Lance Williams in a 1983 article "pyramidal parametrics. Wiki has a very detailed introduction (http://en.wikipedia.org/wiki/Mipmap ). for example, a 128 x image doubles the length and width at a time and generates X, 64x64, 32x32, 16x16, 8x8, 4x4, 2x1, and 8 images, form a mipmap, as shown in.
Mipmap is already supported by hardware. The hardware will automatically generate all levels of mipmap for the created texture. In d3d API: createtexture, the levels parameter is used to specify the level at which the mipmap is generated. If it is not specified, it is generated to 1x1.
3. What is the same and the opposite sex?
When the 3D surface to be paxed is parallel to the screen (viewport), The ing is the same. When the 3D surface to be mapped is tilted to a certain angle from the screen, it is the opposite sex.
It can also be understood that, when a texture is attached to a three-dimensional surface from the perspective of camera, the ratio of u to V is still the same after it is projected into the screen space, it can be understood as the same type. The opposite is considered to be the opposite sex.
4. Nearest point sampling (last point sampling)
This is the simplest. The texture coordinates of each pixel do not correspond to a sample point Texel on texture. What should I do? The nearest vertex is used for sampling.
This method is very effective and fast when the texture size is similar to that of the 3D texture. If the size is different, the texture needs to be enlarged or reduced. In this way, the result will become fatter, deformed, or blurred.
5. bilinear (bilinear filtering)
Bilinear filtering is centered on the texture coordinates corresponding to pixel. It extracts the Four pixels around the texture coordinates, obtains the average value, and uses the average value as the sample value.
Bilinear filtering makes the transition between pixels smoother, but it only applies to one mipmap level. It selects the layer of mipmap with the closest size between Texel and pixel for sampling. When the size of the Texel that matches the pixel size is between two-layer mipmap levels, bilinear filtering may not work very well in some cases. So we have three linear filters.
6. trilinear (tri-linear filtering)
Bilinear filtering is based on bilinear filtering. Bilinear filtering is performed for the two layer of mipmap level with the closest pixel size and Texel size respectively, and then linear interpolation is generated for the results obtained by the two layers.
In general, the results of Tri-linear filtering are ideal. So far, we have assumed that texture projected onto the screen space is of the same type. However, the effect is still unsatisfactory when the opposite sex is present, resulting in anisotropic filtering ).
7. Anisotropic filtering (heterosexual filtering)
First, let's look at the results. The left-side graph uses a three-linear filter, and the right-side graph uses an undirected filter.
The same-sex filtering is used to sample rows in the square area during sampling. The aspect of texture and screen space is taken into consideration in the heterosexual filtering. Simply put, it filters a pixel (X: Y =) to correspond to the proportional relationship between U and V in the texture space. When u: when V is not, the final result will be calculated by sampling different numbers of vertices on each side in proportion (in this case, the sampling may be a rectangular area ).
Generally, the anisotropic filtering (AF) is a three-line filter-based anisotropic filtering. Therefore, when u: V is not, anisotropic filtering needs to sample more points than trilinear, the specific quantity depends on the number of X Af. Currently, the maximum number of video cards is 16 x AF.
When 16x AF is enabled, the hardware does not use 16x Af for all texture samples, but needs to calculate the angle between the screen space and the texture space first (after quantification, It is the u mentioned above: v). 16x is used only when the angle is as large as 16 X.
If you want to understand the implementation principle of AF, you can refer to this article paper: "Implementing an anisotropic texture filter ". at present, AF is implemented by hardware, so only a few people know exactly how it is implemented (in fact, I have not figured out the details). In fact, pixel shader can fully implement AF, of course, the performance is not comparable to that of hardware.
8. Performance Comparison of each filtering Mode
The following table lists the number of times sample is required for obtaining a pixel in various filtering modes:
| filter |
sample number |
| nearest point sampling |
1 |
| bilinear |
4 |
| trilinear |
8 |
| anisotropic filtering 4x |
32 |
| anisotropic filtering 16x |
128 |