首页 > 其他分享 >Unity Texture Setting 中 Filter Mode的影响

Unity Texture Setting 中 Filter Mode的影响

时间:2024-05-23 16:30:05浏览次数:15  
标签:采样 filtering LINEAR texture 像素 Filter Unity Texture GL

网友的笔记

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.

标签:采样,filtering,LINEAR,texture,像素,Filter,Unity,Texture,GL
From: https://www.cnblogs.com/dewxin/p/18208544

相关文章

  • unity中animator中Trigger多次触发动画的解决方法(基于 stateInfo和ResetTrigger)
    巧妙地重置動畫控制器觸發(ResetTriggers)_哔哩哔哩_bilibili提出了FSMCleaSignals,会在进和出动画时使相关的trigger变为非激活状态,但是当该动作涉及多layer/多trigger控制时,会在该layer中动作未完成时,其他layer读取到了还未更改的异常激活状态的trigger,从而出错,这种错误主要是......
  • *Unity基础——Transform组件*
    Unity基础——Transform组件一.一些比较重要的点1.首先编辑器面板中的位置信息指的是物体相对于父物体的坐标(本地坐标),如果物体没有父物体,则其父物体可以看作是世界,则该坐标实际上是世界坐标;2.如果在脚本中调用transform组件的position属性,其是一个Vector3类型的对象,指的是......
  • [Unity] 单例基类的实现方式
    Unity单例基类的实现方式游戏开发的过程中我们经常会将各种“Manger”类设为单例,以实现单一资源的全局访问。Unity中的单例一般分为两类,一种是直接继承自Object的普通单例,还有一种是需要继承MonoBehaviour的Mono单例。接下来我将会讲解这两种单例基类的实现方式。注意:由于Unity......
  • Unity安卓IOS一键打包
    添加菜单构建按钮,使用下面API进行构建,注意设置和配置等usingSystem;usingSystem.IO;usingAssetBundles;usingLiXiaoQian.Common.Editor.Tools;usingUnityEditor;usingUnityEngine;///打包工具publicclassBuildTool{[MenuItem("Tools/构建/Android平台")]......
  • Unity控制物体有放缩弹一弹的效果
     usingUnityEngine;usingSystem.Collections;//控制有放缩弹一弹的效果publicclassScaleController:MonoBehaviour{boolismax=false;publicfloatscaleSpeed=0.003f;//可调速度publicfloatscalemax=2,scalemin=1.5f;//可调范......
  • 【unity】在EditorWindow添加自定义的Toolbar按钮
    好久没写了,最近做工具,写了个EditorWindow,为了让使用者方便查看这个工具的文档,想着在导航栏加个问号按钮,点一下打开说明文档就完事~查了下unity手册,发现Unity提供了一个ShowButton 方法,用于在自定义Editor窗口的工具栏中添加自定义内容,下面是实现的例子:privateGUIStyle......
  • Unity制作一个协程管理工具
    IEnumeratorToolusingSystem;usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassIEnumeratorTool:MonoBehaviour{///<summary>///压入的action任务///</summary>publicclassActionTask......
  • Unity设置UI和Render的渲染层级
    通过给UI或物体挂载下面脚本,来设置层级usingUnityEngine;usingSystem.Collections;usingUnityEngine.UI;namespaceCommon{//设置UI和render的层级publicclassUIDepth:MonoBehaviour{publicintorder;publicboolisUI=true;......
  • Asp-Net-Core开发笔记:使用ActionFilterAttribute实现非侵入式的参数校验
    前言#在现代应用开发中,确保API的安全性和可靠性至关重要。面向切面编程(AOP)通过将横切关注点(如验证、日志记录、异常处理)与核心业务逻辑分离,极大地提升了代码的模块化和可维护性。在ASP.NETCore中,利用ActionFilterAttribute可以方便地实现AOP的理念,能够以简洁、高效的方式进行......
  • Unity性能优化:什么是内存泄露?
    内存泄漏是优化方面的名词,主要是由于不再使用的资源没有及时清理,来释放内存,造成内存的浪费,造成系统卡顿。 或者说,内存就像花呗,额度就这么多,有借要有还,而且手里有闲钱的时候就记得还,以保证内存的充足,如果占着不用,就会在其他需要使用的时候内存不足,就容易崩溃出现问题。 Unity......