Improve texture ing quality

Source: Internet
Author: User

Author: Shen Chen

In this article, I will introduce how to improve the texture ing quality. Including MIP map, bilinear filtering, and tri-linear filtering.

When a polygon changes from near to far or from far to near, the area projected to the screen will also grow from large to small. In this way, a screen pixel corresponds to multiple points on the polygon or multiple pixels on the screen correspond to a point on the polygon. If the polygon is attached with a texture, it will correspond to multiple texture elements (Texel) in a pixel on the screen, or vice versa. This will cause flickering, Mosaic, and other distortion. MIP map technology can be used to deal with the situation that multiple texture elements correspond to screen pixels, bilinear filtering and tri-linear filtering can be used to eliminate mosaic, but can also be used with MIP map to achieve better ing effect. First, let me introduce MIP map.

The idea of MIP map is to paste a higher-resolution texture when the polygon is closer to the observer, and a lower-resolution texture when the polygon is farther away. The method to reduce the resolution is to reduce the original texture. For ease of calculation, the original texture is usually reduced by the power of 2. If the original texture is 8x8, the MIP map is 4x4, 2x2, 1X1. In order to reduce the texture without causing serious distortion, we need to filter the original texture. The procedure is as follows.

If we have a texture A, its size is 8 × 8. The value of each texture element is represented by.

Texture
A00 A10 A20 A30 A40 A50 A60 A70
A01 A11 A21 A31 A41 A51 A61 A71
A02 A12 A22 A32 A42 A52 A62 A72
A03 A13 A23 A33 A43 A53 A63 A73
A04 A14 A24 A34 A44 A54 A64 A74
A05 A15 A25 A35 A45 A55 A65 A75
A06 A16 A26 A36 A46 A56 A66 A76
A07 A17 A27 A37 A47 A57 A67 A77

We reduced it by half and then obtained a 4 × 4 texture B, as shown below.

Texture B
B00 B10 B20 B30
B01 B11 B21 B31
B02 B12 B22 B32
B03 B13 B23 B33

B00 = (a00 + A10 + A01 + A11)/4. Other texture elements can be obtained in the same way. That is, one texture element in texture B is the average value of the four adjacent texture elements corresponding to texture. We can also narrow down texture B in the same way, so we can get the desired set of MIP map. We can select an appropriate MIP map based on the distance between the polygon and the observer.

MIP map can improve the quality of texture ing, but it also has some shortcomings. Generally, in order to reduce the storage space occupied by textures, we can only classify the original textures for a limited number of times. However, the distance between the polygon and the observer can indeed be varied. For example, if we have a polygon, the corresponding group of MIP maps is 8x8, 4x4, 2x2, 1X1. The most suitable texture size for a specific time should be 5.7 × 5.7, but the corresponding MIP map does not have this resolution texture, if we choose 8x8 or 4x4, it is not very accurate. Another case is that the most suitable MIP map of the polygon is 9 × 9, which is the largest MIP map in this group of MIP maps, if we select 8x8, the mosaic effect will be generated.

The solutions to these problems are bilinear filtering and tri-linear filtering. I will first introduce bilinear filtering. Suppose we have a polygon whose MIP map is 5.7 × 5.7, then we will select one of the 8 × 8 and 4 × 4 MIP maps, we choose a smaller one, that is, 4 × 4. When we use the scanning line method to fill this polygon, we get a texture space coordinate (0.3, 0.6) of the texture corresponding to the 4x4 MIP map (1.2, 2.4 ). In this case, we do not simply set it to an integer. Instead, we take four points around it, C1 (1.0, 2.0), C2 (1.0, 3.0), C3 (2.0, 2.0 ), c4 (2.0, 3.0) Then interpolation the four points in the X and Y directions. First, interpolation is performed on C1, C3, C2, and C4 in the X direction. Assume that the 4 × 4 MIP map is as follows.

Texture B
B00 B10 B20 B30
B01 B11 B21 B31
B02 B12 B22 B32
B03 B13 B23 B33

We perform Interpolation on C1 and C3 in the X direction to obtain a new value P1, where
P1 = 0.8 * B12 + 0.2 * B22.
Interpolation C2 and C4 to get P2, where
P2 = 0.8 * B13 + 0.2 * B23.
Then, perform Interpolation on P1 and P2 in the Y direction to obtain
P3, P3 = 0.6 * P1 + 0.4 * P2.
P3 is the texture element obtained after bilinear filtering.

Three-linear filtering is similar to Bilinear filtering. The difference is that three-linear interpolation requires interpolation between two MIP maps. We also use the above MIP map as an example. We get a polygon and its corresponding 5.7 x MIP map. In this case, we do not take 4x4 MIP map, but take 8x8 and 4x4 MIP maps at the same time. When a polygon is filled with the scanning line method, the texture elements of a screen pixel corresponding to the two MIP maps are calculated respectively. Then, the two texture elements are obtained through bilinear interpolation as described above, respectively, P44 and p88. Then interpolation the two texture elements to get p, where
P = (1-5.7/(8 + 4) * P44 + 5.7/(8 + 4) * p88.
P is the texture element obtained after tri-linear filtering.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.