Filtering each other texture in OpenGL
1. Basic texture filtration
Texture is a simple matrix arrangement of data - for example, color data, brightness data, or color and alpha (transparency) data. Each independent value in the texture array is often referred to as a texture unit. Texture Mapping is a technique for applying a textured image to an object surface (that is, the image is attached to a polygon constituting the object surface), just as the image is a surface of the object to attach the surface of the object.
So what is texture filtering? When the polygon in the three-dimensional space passes through the coordinate transform, projection, rasterization, etc., when the set of pixels on a two-dimensional screen, the corresponding texture image is required to be sampled, which is called Texture filtration.
Texture filtration is usually divided into 2 cases:
a) Texture is reduced, for example, a piece of 8 x 8 is attached to a square parallel to the XY plane, and finally the square accounts for only 4 x 4 pixel matrix on the screen. In this case, a pixel corresponds to more Texture unit.
b) The texture is enlarged. This is just contrary to the above. If we amplify the square, the final square accounts for a 16 x 16 pixel matrix on the screen, which becomes a texture unit corresponding to multiple pixels.
The usual texture filtration method has two types: linear filtration and tri-linear filtration. It is also possible to set no filtering operations. (OpenGL allows different filtration methods to be separately set for both cases)
a) The fastest speed is the fastest speed, but for each pixel to sample the texture unit closest to it, it can be used for both cases. However, this texture filtration method is the worst, and the image displayed on the screen is very blurred.
b) Linear filtration is also relatively simple, and each pixel is to sample the texture unit matrix closest to its 2 x 2, and the average of 4 texture units can be used for the above two cases. This effect of this texture filtration method is much better than above.
c) Three-linear filtration is relatively complicated, which can only be used for the texture reduction, and the MIPMAP of the texture image is required to construct the texture image. MIP means "many things in the narrow place", MIPMAP is the initial texture A series of resolutions of image constructs reduced and filtered in advance. For a 8 x 8 texture, it is necessary to construct 4 x 4, 2 x 2, 1 x 1 of these three MIPMAPs for it. If the square is reduced to a pixel matrix of 6 x 6 on the screen, the sampling process of a pixel becomes such that the texture unit matrix closest to it 2 x 2 is performed in the texture map of 8 x 8. Sampling (that is, the above linear filtration); followed by repeating the above process in the texture diagram of 4 x 4; then the result of the above two samples is weighted, and the last sampling data is obtained. It can be seen that the entire process has three linear filtrations, so this method is called three-line filtering, and its effect is the best in three texture filtration methods.
2. Differential texture filtration
Alternative texture filters are not used singly or in combination with other filtration methods described above.
Suppose PX is the scale factor of the scaling of the texture in the X coordinate direction; PY is the scale factor of the scaling of the texture in the Y coordinate direction; PMAX is the maximum value in PX and PY; PMIN is the minimum of PX and PY. When PMAX / PMIN is equal to 1, that is, PX is equal to PY, the scaling of the texture is the same; however, if the PMAX / PMIN is not equal to 1 but is greater than 1, PX is not equal to PY, that is, the texture is in the X coordinate direction. And the proportion of the y coordinate direction is different, the scaling of the texture is different, and PMax / Pmin represents the extent of each abutment.
For example, the texture of 64 x 64 is attached to a square starting parallel to the XY plane, but the square is rotated about 60 degrees around the Y-axis, and finally projected to the screen accounts for 16 x 32 pixel matrix. The proportional factor scaled in the X coordinate direction is 64/16 equal to 4, and the proportional factor scaled in the Y coordinate direction is 64/32 equal to 2, PMAX is equal to 4, and Pmin is equal to 2. The degree of extent of the zoom is 2. When each of the abutment filtration and linear filtration, it should be reasonable to sample the texture unit matrix of 4 x 2 closest to pixels, because a pixel corresponds to more texture units in the X coordinate direction. (PX> PY). Even if the texture is narrowed in one axis direction, the process is amplified, and the process of processing is true (note that if the texture is narrowed in one axis direction and amplified in the other axis direction, OpenGL still put it as When the texture is reduced, the filtering method set is set to the texture reduction case is the basic filtration method, and then each of which is differential filtration). Suppose the squares of the maps last on the screen account for a 128 x 32 pixel matrix, the proportional factor scaled in the X coordinate direction is 64/128 equal to 0.5, the proportional factor scaled in the Y coordinate direction is 64/32 equal to 2. Since PY> PX is equal to 4, the texture unit matrix of the 2 x 8 closest to the pixels should be sampled when each of which is combined with each other and linear filtration. Steps of the three-lineary filtration and each of the peripheral filtration combined with the previous three-line filtration method are roughly the same, but the front two steps are used in the previous two steps. Normally, linear filtration or tri-line filtration can have a good effect, but in some special cases, in particular, a texture map of a line-like stripe is attached to an X or a Y-axis rotation angle. When the big polygon is placed, for example, the human hair texture is packed to the polygon of the head of the person, even if the effect of tri-linear filtration cannot be satisfactory, only the abutment filtering method and tri-linear filtration or linear filtration The method combines to get the perfect effect.
3. How to use each heterogeneous texture filter in OpenGL
Filter in OpenGL First Filter Filter First To Run OpenGL implementation support ext_texture_filter_anisotropic this OpenGL extension.
The parameter settings of each of OpenGL are independent of the texture reduction and amplification, that is, it is not necessary to set it separately for both cases. The parameter setting is very simple, only one parameter is the maximum extent (texture_max_anisotropy_ext). Because the degree of the absence of the texture is, the more texture units need to be sampled, so that it is unacceptable on the processing speed, so a maximum extent must be set, and when OpenGL performs each of the heteroscopic filtration At the time, the differential degree parameters employed are the minimum levels of the texture scaling and the maximum degree of extent, that is, when the extent of the absence of the texture is larger than the maximum extent of the settings. The maximum extent of the settings will be used as the parameters used by the filtration. It will be apparent that the parameter is not performed when the parameter is set to 1, and each of which is not performed, 1 is also the default setting set for this parameter. You can also get the maximum extent of the OpenGL implementation support by querying max_texture_max_anisotropy_ext.
Here is a sample program:
/ / Suppose this is a two-dimensional texture and has already set MIPMAP
// Get the maximum extent of supported by the running OpenGL implementation
GLFLOAT LARGEST_SUPPORTED_ANISOTROPY;
GLGETFLOATV (GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT,
& Largest_supported_anisotropy;
// Set the filter method used in the texture shrinkage, set three-line filtering GLTEXPARAMETERI (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_LINEAR);
/ / Set the filtering method used when the texture is enlarged, which is set to linear filtration
Gltexparameteri (GL_Texture_2D, GL_TEXTURE_MAG_FILTER,
GL_LINEAR);
// Set the maximum extent to which the maximum extent to which the maximum extent to be supported by OpenGL
GLTEXPARAMETERF (GL_TEXTURE_MAX_ANISOTROPY_EXT,
Largest_supported_anisotropy);