Bilinear, trilinear, and anistropic filtering in texture filtering Mode)

Source: Internet
Author: User

1,Why is it necessary for texture sampling?Texture Filter(Texture filtering ).

Our texture is to be attached to the surface of a 3D image.PixelCenter and TextureTexelCenter is not 1 (PixelNot necessarilyTextureSampling center onTexel), And 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 the dimension is smaller than the surface of a 3D image, many pixels are mapped to the same texture.

When these situations occur, the textures become blurred or misaligned or mosaic. To solve such problems, we must use technology to smoothTexelAndPixel. This technology is texture filtering.

Different filtering modes have different computing complexity, which results in different results. From simple to complex filtering modes include:Nearest point sampling(Last point sampling ),Bilinear(Bilinear filtering ),Trilinear(Tri-linear filtering ),Anisotropic Filtering(Heterosexual filtering ).

Before learning about this, it is necessary to understand what isMipmapAnd when is the same, the opposite sex.

2,What isMipmap?

MipmapByLance Williams In1983AArticle"Pyramidal parametrics.WikiHas a very detailed introduction(Http://en.wikipedia.org/wiki/Mipmap).For example256x256To double the length and width of the graph at a time:128 x, 64x64, 32x32, 16x16, 8x8, 4x4, 2X1, Consisting of eight imagesMipmap,As shown in.

MipmapAlready supported by hardware, the hardware will automatically createTextureGenerateMipmap. InD3dOfAPI:CreatetextureThere is a parameterLevelsIs used to specify the generationMipmapTo which level, it will be generated all the time when it is not specified1x1.

3,What is the same and the opposite sex?

When the 3D surface to be mapped is parallel to the screen(Viewport)Is the same type. 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 asTextureAttached to a 3D surface fromCameraIt seems that there is no deformation. After it is projected into the screen spaceUDirection andVThe aspect ratio is still the same, so 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 are not exactly matched.TextureA sampling point onTexelWhat should I do? Sampling from the nearest VertexTexelSample.

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 FilteringPixelThe corresponding texture coordinates are centered around the texture coordinates4ItemsTexelAnd then take the average value. The average value is used as the sample value.

Bilinear filtering makes the transition between pixels smoother, but it only acts on oneMipmap level,It selectsTexelAndPixelThe layer closest to each otherMipmapSample. When andPixelSize matchedTexelThe size is in two layers.Mipmap levelIn some cases, bilinear filtering is not very effective. So we have three linear filters.

6,Trilinear(Tri-linear filtering)

Bilinear filtering is based on bilinear filtering. YesPixelSize andTexelThe nearest two layersMipmap levelPerform bilinear filtering, and then generate linear interpolation for the results obtained by two layers.

In general, the results of Tri-linear filtering are ideal. So far, we assume thatTextureThe projection to the screen space is of the same type. However, when the case of the opposite sex, the effect is still not ideal, so it producesAnisotropic Filtering(Heterosexual 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 outPixel (X: Y = 1:1)CorrespondsUAndVDirectionUAndVProportional Relationship, whenU: VNo1:1The final result will be calculated by sampling different numbers of vertices from different vertices.(At this time, the sampling may be a rectangular area.).

We generally referAnisotropic filtering (AF)All are based on three-line filtering.Anisotropic FilteringTherefore, whenU: VNot1:1, ThenAnisotropic FilteringRatioTrilinearThe number of sampling points depends on the number of sampling points.XOfAF,Currently, most video cards are supported16x af.

When enabled16x afHardware is notTextureSampling16x afTo calculate the angle between the screen space and the texture space.(After quantification, this is what we mentioned above.U: V)Only when the angle is large enough16xWill be used16x.

If you want to know AF For more information, see Paper:" Implementing an anisotropic texture filter ". Now AF Hardware Implementation, so only a few people are clear AF It's all about how it is implemented (I have not figured out the details ). Pixel shader To achieve AF Of course, the performance is not comparable to that of hardware.

8,Performance Comparison of each filter mode.

 The following table shows one filter mode.PixelYesSampleTimes:

sample number

nearest point sampling

1

bilinear

4

trilinear

8

anisotropic filtering 4x

32

Anisotropic filtering 16x

128

anisotropic filtering 16x best effect, however, the performance of the video card is greatly reduced, of course, it is also a good way to test your graphics card Texture unit . If you think your video card is good enough, set AA and AF try again when they reach the maximum value :)

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.