Unity Texture Setting 中 Filter Mode的影響

dewxin發表於2024-05-23

網友的筆記

https://blog.csdn.net/u012322710/article/details/50858216

Fiter mode過濾器模式

因為貼圖在螢幕裡肯定會存在放大,縮小的情況,這種時候就會出現鋸齒。 今天看到一個影片有講解到這一塊。

在UNITY3D中點開一張貼圖,Fiter mode過濾器模式 ,下面有3個選項 point , Bilinear ,Trilinear


point :點取樣模式,螢幕畫素會需找最近的貼影像素點,來作為輸出,這種比較生硬,但是效能好,不抗鋸齒。

Bilinear :雙線性取樣模式, 採用最近的4個畫素來做線性插值,有平緩的過渡。可以解決貼圖放大的問題,但是貼圖縮小依然有鋸齒。

縮小可以用mip-map來解決。

Trilinear :三線性取樣模式,可以比較好的解決貼圖縮小和放大。

缺點:畫素處理速度變慢,貼圖大小增加1/3。

優點:畫面好,GPU可以根據光柵化結果匯入一層MIP-MAP到視訊記憶體中,減輕硬體負擔,綜合起來,能彌補畫素處理的速度。

OpenGL 文件 Filtering

https://www.khronos.org/opengl/wiki/Sampler_Object#Filtering

All of the following parameters can be used with the glTexParameter* set of functions. A Sampler Object is an OpenGL Object that stores the sampling parameters for a Texture access inside of a shader. You could say that a texture object contains a sampler object, which you access through the texture interface.

sampler物件是OpenGL用來儲存取樣引數的,shader在訪問texture的時候會用到這些引數。你可以說一個texture物件包含一個sampler物件。

Filtering is the process of accessing a particular sample from a texture. There are two cases for filtering: minification and magnification. Magnification means that the area of the fragment in texture space is smaller than a texel, and minification means that the area of the fragment in texture space is larger than a texel. Filtering for these two cases can be set independently.

Filtering(影像濾波)是從texture材質中訪問一個特定的取樣的過程。取樣會有兩種情況:縮小(minification)和放大(magnification)。 放大(magnification)意味著fragment(螢幕畫素對應面片的那個部分)在texture材質空間的大小是小於材質1畫素的。 縮小(minification)意味著畫素對應面片的部分在材質空間中的大小是大於 材質(圖片)畫素的。 這兩種情況的取樣設定可以分開設定。
放大,也就是意味著原來影像的一個畫素放大到螢幕中的多個畫素了。

The magnification filter is controlled by the GL_TEXTURE_MAG_FILTER texture parameter. This value can be GL_LINEAR or GL_NEAREST. If GL_NEAREST is used, then the implementation will select the texel nearest the texture coordinate; this is commonly called "point sampling". If GL_LINEAR is used, the implementation will perform a weighted linear blend between the nearest adjacent samples.

放大采樣(magnification filter)受GL_TEXTURE_MAG_FILTER引數控制。這個值可以是GL_LINEAR或者是GL_NEAREST。如果使用了GL_NEAREST ,那麼取樣過程會尋則畫素最近的材質座標;這通常叫做點取樣 point sampling。 如果使用了GL_LINEAR,那麼取樣過程會對最近幾個相鄰的樣本做加權線性混合eighted linear blend。

縮小取樣涉及mipmap,需要更詳細地解釋。

When doing minification, you can choose to use mipmapping or not. Using mipmapping means selecting between multiple mipmaps based on the angle and size of the texture relative to the screen. Whether you use mipmapping or not, you can still select between linear blending of the particular layer or nearest. And if you do use mipmapping, you can choose to either select a single mipmap to sample from, or you can sample the two adjacent mipmaps and linearly blend the resulting values to get the final result.

如果選擇了mipmapping,你可以對兩個相鄰的mipmaps取樣,然後混合得到最終結果。

Param Setting Linear within mip-level Has mipmapping Linear between mip-levels
GL_NEAREST No No
GL_LINEAR Yes No
GL_NEAREST_MIPMAP_NEAREST No Yes No
GL_LINEAR_MIPMAP_NEAREST Yes Yes No
GL_NEAREST_MIPMAP_LINEAR No Yes Yes
GL_LINEAR_MIPMAP_LINEAR Yes Yes Yes

Filtering textures that use the sRGB colorspace may be sRGB correct or it may not. Linear interpolation in a non-linear colorspace like sRGB will not produce correct results. The OpenGL specification recommends, but does not require that implementations covert samples to linear RGB before filtering. They may do filtering in sRGB space, then convert to linear. Generally speaking, all GL 3.x+ hardware will do filtering correctly.

線性插值可能發生在 sRGB顏色空間,也可能發生線上性空間。

Unity Sample Mode 解釋

On terminology. This discussion has refrained from using the common filtering terms "bilinear" and "trilinear." This is for a good reason; these terms are often misunderstood and do not carry over to all texture types.

Take the term "bilinear". This term is used because it refers to linear filtering in 2 axes: horizontally and vertically in a 2D texture. A monolinear would be filtering in one axis, and thus trilinear is filtering in 3 axes.

The problem is that what constitutes "bilinear" depends on the texture type. Or specifically, its dimensionality. Setting GL_TEXTURE_MAG_FILTER and MIN_FILTERs to GL_LINEAR will create monolinear filtering in a 1D texture, bilinear filtering in a 2D texture, and trilinear in a 3D texture. In all cases, it is simply doing a linear filter between the nearest samples; some texture types simply have more nearest samples than others.

Unfortunately, what most people think of as "trilinear" is not linear filtering of a 3D texture, but what in OpenGL terms is GL_LINEAR mag filter and GL_LINEAR_MIPMAP_LINEAR in the min filter in a 2D texture. That is, it is bilinear filtering of each appropriate mipmap level, and doing a third linear filter between the adjacent mipmap levels. Hence the term "trilinear".

Unity FilterMode 中 trilinear的選項 意味著 在mipmap中,做 bilinear取樣,也就是雙軸線性插值,然後在兩個相鄰的mipmap之間,再做一次混合, 這被稱為 trilinear

This is easily confused with what is just GL_LINEAR for 3D textures. That is why OpenGL and this discussion does not use these terms.

相關文章