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 += 1

    return 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 += 1

    return d

从算法可以得出:
纹理中的值只有 0, 1, 2。
但是 0,1,2 三个值非常接近,采样时容易产生误差。
将其变为 0, 127, 254,以此去掉误差,也有助于人眼分辨。
因此,纹理中的颜色为 0, 127, 254

至于以上算法如何得出的,查看SMAA算法详解-SMAASearchXLeft(Right)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值