SMAA算法详解 - SearchTex
SearchTex
SearchTex.png (x10)
边界样式
# This dict returns which edges are active for a certain bilinear fetch:
# (it's the reverse lookup of the bilinear function)
edge = {bilinear([0, 0, 0, 0]): [0, 0, 0, 0],bilinear([0, 0, 0, 1]): [0, 0, 0, 1],bilinear([0, 0, 1, 0]): [0, 0, 1, 0],bilinear([0, 0, 1, 1]): [0, 0, 1, 1],bilinear([0, 1, 0, 0]): [0, 1, 0, 0],bilinear([0, 1, 0, 1]): [0, 1, 0, 1],bilinear([0, 1, 1, 0]): [0, 1, 1, 0],bilinear([0, 1, 1, 1]): [0, 1, 1, 1],bilinear([1, 0, 0, 0]): [1, 0, 0, 0],bilinear([1, 0, 0, 1]): [1, 0, 0, 1],bilinear([1, 0, 1, 0]): [1, 0, 1, 0],bilinear([1, 0, 1, 1]): [1, 0, 1, 1],bilinear([1, 1, 0, 0]): [1, 1, 0, 0],bilinear([1, 1, 0, 1]): [1, 1, 0, 1],bilinear([1, 1, 1, 0]): [1, 1, 1, 0],bilinear([1, 1, 1, 1]): [1, 1, 1, 1],
}
SMAA采用双线性采样加快搜索速度,一次采样可获取4个像素的边界信息。
以左边界为例,存在16种边界样式:
采样偏移值(-0.25, -0.125),如图所示,
采样结果 :
0/32, 21/32, 7/32, 28/32,
3/32, 24/32, 10/32, 31/32,
1/32, 22/32, 8/32, 29/32,
4/32, 25/32, 11/32, 32/32,
每一个值都代表了一种边界样式
纹理大小
为了使用纹理坐标表示上面的16个值,则需要33个像素 [0 - 32]。
同理,上边界需要33个像素,分左右搜索,纹理大小为 66 x 33。
无上下搜索值。上下搜索时,只需要把 x,y 调换,上下就变成了左右。纹理大小就减少一半。
为什么最终的纹理大小为 64 * 16 ?
原始纹理如下:66 x 33
观察原始纹理,存在大部分为 0(黑色)的部分。直接裁掉这些为0的部分,并将其大小变为2次幂。
# Crop it to power-of-two to make it BC4-friendly:
# (Cropped area and borders are black)
image = image.crop([0, 17, 64, 33])
裁剪后纹理,如下
纹理被裁剪了,现纹理与原纹理的UV对应产生了变化。
现纹理与原纹理的对应关系
x : [0 - 66/64] => [0 - 1]
y : [0 - 2] => [0 - 1]
现纹理均有一部分超过了1,超过1的部分认为是被剪裁的值为 0 的部分。
超过的部分没有被保存,但是需要在计算时还原。
在x分量上,x = 1 的部分值为0(最右边一列),只要将纹理采样的 WarpMode 设置为 Clamp,超过1的部分采样后的值即为0。
在y分量上,y = 1 的部分不均为 0 (最下边一行),但是 y = 0 的部分均为0(最上边一行)。
为了与x分量采用相同的优化方式,只需将纹理在y分量上翻转。
image = image.transpose(Image.FLIP_TOP_BOTTOM)
这样就得到了最终的 64*16 的纹理。
纹理颜色
# Delta distance to add in the last step of searches to the left:
def deltaLeft(left, top):d = 0# If there is an edge, continue:if top[3] == 1:d += 1# If we previously found an edge, there is another edge and no crossing# edges, continue:if d == 1 and top[2] == 1 and left[1] != 1 and left[3] != 1:d += 1return d# Delta distance to add in the last step of searches to the right:
def deltaRight(left, top):d = 0# If there is an edge, and no crossing edges, continue:if top[3] == 1 and left[1] != 1 and left[3] != 1:d += 1# If we previously found an edge, there is another edge and no crossing# edges, continue:if d == 1 and top[2] == 1 and left[0] != 1 and left[2] != 1:d += 1return d
从算法可以得出:
纹理中的值只有 0, 1, 2。
但是 0,1,2 三个值非常接近,采样时容易产生误差。
将其变为 0, 127, 254,以此去掉误差,也有助于人眼分辨。
因此,纹理中的颜色为 0, 127, 254
至于以上算法如何得出的,查看SMAA算法详解-SMAASearchXLeft(Right)
SMAA算法详解 - SearchTex相关推荐
- SMAA算法详解 - SMAANeighborhoodBlendingPS
目录 - SMAA代码详解 SMAANeighborhoodBlendingPS //--------------------------------------------------------- ...
- SMAA算法详解 - SMAALumaEdgeDetectionPS
目录 - SMAA代码详解 SMAALumaEdgeDetectionPS /*** Luma Edge Detection** IMPORTANT NOTICE: luma edge detecti ...
- SMAA算法详解 - SMAANeighborhoodBlendingVS
目录 - SMAA代码详解 SMAANeighborhoodBlendingVS /*** Neighborhood Blending Vertex Shader*/ void SMAANeighbo ...
- SMAA算法详解 - SMAASearchYUp(Down)
SMAASearchYUp(Down) SMAASearchYUp 与 SMAASearchXLeft大致相同. 不同点: 在Y方向上偏移2. SearchTex采样时,e.rg 改为 e.gr. S ...
- SMAA算法详解 - AreaTex
AreaTex 以下均在无SubPixel的情况下,即offset = (0,0).subpixel将单独讲解. areaortho.area # Calculates the area under ...
- SMAA算法详解 - SMAABlendingWeightCalculationVS
SMAABlendingWeightCalculationVS /*** Blend Weight Calculation Vertex Shader*/ void SMAABlendingWeigh ...
- SMAA算法详解 - SMAADetectHorizontalCornerPattern
SMAADetectHorizontalCornerPattern 修正水平转角 //--------------------------------------------------------- ...
- SMAA算法详解 - SMAAEdgeDetectionVS
SMAAEdgeDetectionVS 计算从当前像素点到目标像素点的偏移值. /*** Edge Detection Vertex Shader*/ void SMAAEdgeDetectionV ...
- SMAA算法详解 - SMAADetectVerticalCornerPattern
SMAADetectVerticalCornerPattern void SMAADetectVerticalCornerPattern(SMAATexture2D(edgesTex), inout ...
最新文章
- 服务器架设笔记——打通MySQL和Apache
- 使用IDEA新建springboot工程
- ASP用DSN连接数sql数据库
- PowerDesigner16中的对象无效,不允许有扩展属性 问题的解决
- Linux中使用Msmtp+mutt+shell自动发邮件程序安装说明
- iOS中都有什么设计模式?各个设计模式的作用 (转载)
- Ubuntu的奇技淫巧
- 用javascript写Android和iOS naitve应用,实在炫酷。
- JPA getValidationMode()
- Linux:为什么那么多人讨厌systemd?
- 最大权闭合子图(poj 2987 Firing)
- 简述vue-router实现原理
- python bottle 终止返回_关于python的bottle框架跨域请求报错问题的处理
- QML 环形进度条canvas 98行代码实现
- 地理空间坐标系统-城市坐标系与国家统一坐标系之间的转换(含四参数转换代码)
- 闲聊企业数字化转型(1)-供应链数字化
- 立秋是中稻收割的日子
- mysql怎么给root设密码_mysql给root设置密码
- 北京工作居住证的申请条件和可享受的待遇
- FS2712A单片机可替换松翰SN8P2711