微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Perli 噪声 - 散列函数不返回相同的向量

如何解决Perli 噪声 - 散列函数不返回相同的向量

我正在尝试使用置换表和散列函数来实现柏林噪声。

散列函数应该为网格点返回相同的向量,但它似乎没有这样做。

我用一个小的排列表做了一些测试 P = [0,3,1,2] 其中值 0 到 3 然后用于分配向量

def get_constant_vector(p):
    # p is the value from the permutation table
    h = p % 3 # p & 3
    
    if h == 0:
        return [1.0,1.0]
    elif h == 1:
        return [-1.0,1.0]
    elif h == 2:
        return [1.0,-1.0]
    else:
        return [-1.0,-1.0]

所以如果表中的值相同并且向量也相同。 这就是我如何从一个点周围的边界框的每个角的排列表中确定值。

P = [0,2]
P = P * 42 # to absolutely prevent index out of range

for x in range(5):
    x = x + 0.5
    for y in range(5):
        y = y + 0.5

        X = int(x) % 4
        Y = int(y) % 4
        
        value_TL = P[P[X] + Y + 1] # top left corner
        value_TR = P[P[X + 1] + Y + 1] # top right corner
        value_BR = P[P[X + 1] + Y] # bottom right corner
        value_BL = P[P[X] + Y] # bottom left corner
        
        print(f"x={x},y={y},BL = {value_BL},BR = {value_BR},TL = {value_TL},TR = {value_TR}")

这会产生以下结果:

x=1.5,y=1.5,BL = 0,BR = 1,TL = 3,TR = 2    vector here is BR   1
x=1.5,y=2.5,BL = 3,BR = 2,TL = 1,TR = 0    vector here is TR   0
x=2.5,BL = 1,TL = 2,TR = 0    vector here is BL   1
x=2.5,BL = 2,BR = 0,TL = 0,TR = 3    vector here is TL   0

他们认为是一样的,但事实并非如此。

我的假设哪里错了?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。