Unity Texture Setting 中 Filter Mode的影响

网友的笔记

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.

posted @ 2024-05-23 16:28  dewxin  阅读(363)  评论(0编辑  收藏  举报