OpenGL _ texture filtering

Source: Internet
Author: User

I. texture filtering:

When the polygon in a 3D space changes to a set of pixels on a two-dimensional screen through coordinate transformation, projection, raster, and other processes, each pixel needs to be sampled in the corresponding texture image, this process is called texture filtering.

Ii. texture filtering is generally divided into two types: 
A) The texture is reduced to gl_texture_min_filter.
For example, if an 8x8 texture is attached to a square parallel to the XY plane, the square occupies only a 4x4 Pixel matrix on the screen, in this case, the next pixel corresponds to multiple texture units.
B) The texture is enlarged to gl_texture_mag_filter.
This is just the opposite of how the texture is enlarged. If we enlarge the square, the last square occupies a 16x16 pixel matrix on the screen, in this way, a texture unit corresponds to multiple pixels.

Iii. Different texture filtering methods: 
1. Last point sampling gl_nearest
2. Linear texture filtering (bilinear filtering) gl_linear
3. mipmap texture filtering (tri-linear filtering) gl_linear_mipmap_linear
4. Heterosexual Filtering

A) last point sampling
The latest point sampling method is the fastest and simplest without any filtering operations. It only samples the texture units closest to each pixel and can be used in the preceding two cases. However, this texture filtering method has the worst effect, and the images displayed on the screen are very blurred.
 

B) bilinear interpolation
Linear filtering is also relatively simple. Each pixel needs to sample the Texture unit matrix closest to its 2X2, and take the average value of the four texture units, it can also be used in the preceding two cases. This texture filtering method is much better than above.
This is a better way of processing material image interpolation. We will first find the four elements closest to the pixel, and then make a difference between them, the final result will be pasted to the position of the pixel, so that the "Mosaic" phenomenon will not be seen. This processing method is more suitable for static images with a certain depth of field, but cannot provide the best quality. The biggest problem is that when a 3D object becomes very small, a kind of object called depth aliasing artifacts (deep pseudo-sample sawtooth) is not applicable to moving objects.
 

C) trilinear Interpolation
Tri-linear filtering is relatively complex. It can only be used when the texture is reduced. We need to first construct the texture image's mipmap, which means "a lot of things in a narrow place ", mipmap is a series of texture images with reduced resolutions and pre-filtered textures constructed for the initial texture image. For an 8x8 texture, we need to construct 4x4, 2x2, and 1x1 mipmaps for it. If a square is reduced to a 6x6 Pixel matrix on the screen, the sampling process of a pixel becomes like this, first, sample the Texture unit matrix closest to 2x2 in the 8x8 texture graph (that is, the linear filter above ); the second step is to repeat the above process in the 4x4 texture graph. Then, the weighted average of the above two sampling results is obtained to obtain the final sample data. It can be seen that the entire process has carried out a total of three linear filtering, so this method is called Three linear filtering, and its effect is the best among the three texture filtering methods.
This is a more complex method of texture image interpolation, which uses a considerable number of texture images, and the size of each image is exactly 1/4 of that of the other. For example, if a material image contains 512x512 elements, the second image will contain 256x256 elements, and the third image will contain 128x128 elements, in short, the smallest one is 1 × 1. with these multi-resolution texture images, high-quality texture effects can be provided in scenarios with a large depth of field (such as flight simulation. A "two-line filter" requires three Mixing Times, while a "three-line filter" requires seven Mixing Operations, so each pixel requires more than 21/3 times of computing time. It also requires two times the memory clock bandwidth. However, "three-line filtering" can provide the highest texture quality, which will remove the material's "flashing" effect. Only three-line filtering can provide acceptable material quality for scenarios that require a large amount of dynamic objects or depth of field.

D) anisotropic interpolation Filtering
Heterosexual filtering is the latest filtering method. It needs to sample eight or more pixels around the ing point and map them to the pixels after obtaining the average value. For many 3D accelerator cards, it is almost impossible to use over 8 pixel sampling to filter the ry, because it requires more pixel filling rate than the tri-linear filter. However, for 3D games, ry filtering is a very important feature, because it can make the screen more realistic and naturally process it more slowly than tri-linear filtering.
Texture filtering of different features is not used independently but used together with other filtering methods described above. It takes 8 or more pixels for processing during sampling, and the quality is the best.
Assume that PX is the scale factor of the texture in the X direction, Py is the scale factor of the texture in the Y direction, and Pmax is the maximum value in PX and Py; pmin is the minimum value in PX and Py. When Pmax/pmin is equal to 1, that is, PX is equal to py, And the textures are scaled in the same direction. However, if Pmax/pmin is not equal to 1 but greater than 1, PX is not equal to py, that is to say, the texture scales differently in the X direction and in the Y direction, and the texture scales in different directions. Pmax/pmin represents the degree of variation.
For example, a 64x64 texture is attached to a square that begins to be parallel to the XY plane, but the square rotates 60 degrees around the Y axis, at last, a 16x32 Pixel matrix is projected onto the screen. The Scale Factor of the texture in the X direction is 64/16 or 4, the scale factor in the Y direction is 64/32 or 2, Pmax is 4, and pmin is 2. The zoom degree is 2. When combining different-Direction Filtering and linear filtering, it is reasonable to sample the Texture unit matrix closest to the pixel 4x2, because a pixel corresponds to more texture units (PX> Py) in the X pixel direction ). Even if the texture is scaled down in one axis and enlarged in the other axis, the processing process is the same (Note that if the texture is scaled down in the direction of one axis and enlarged in the direction of the other axis, OpenGL still treats it as a situation where the texture is reduced, the basic filtering method will be used to filter the texture reduction, and then the different features will be added ). Assume that the paxed square occupies 128 of the total number on the screen.
X 32 Pixel matrix. The proportional factor of the texture in the X-ray direction is 64/128 or 0.5, and the proportional factor in the Y-ray direction is 64/32 or 2, because py> PX and Pmax/pmin are equal to 4, when we combine different-Direction Filtering and linear filtering, sample the 2x8 Texture unit matrix closest to the pixel. The steps for filtering methods that combine three-linear filtering and different-direction filtering are roughly the same as those of the preceding three-linear filtering method, the preceding two steps only use a combination of different-Direction Filtering and linear filtering.
In general, linear filtering or tri-linear filtering can achieve good results, but in some special cases, in particular, when a texture graph with linear Stripes is attached to a polygon with a large rotation angle around X or Y axis, for example, the human hair texture is attached to a polygon that forms the top of the human head, even the results of Tri-linear filtering are not satisfactory. Only by combining different methods of filtering with tri-linear filtering or linear filtering can we achieve perfect results.

// Use OpenGL to set the maximum degree of divergence supported
Gltexparameterf (gl_texture_2d, gl_texture_max_anisotropy_ext, XXX );
// Note: Here XXX represents the parameter of the degree of divergence of the heterosexual filtering.
// You can set it to 4, 8, 16, and so on. You can also write it in the initgl ()-driven OpenGL function.
Int lrgsupolyaniline;
Glgetfloatv (gl_max_texture_max_anisotropy_ext, & lrgsupolyaniline );
Then XXX must be less than or equal to lrgsupolyaniline.

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.