java - Why do noise algorithms use 256 permutation values? -
i have seen many noise implementations things perlin , simplex noise achieve procedural terrain generation, , seem use 256 permutation values. why this? , effect of using more 256?
you use number of permutation values. reason powers of 2 preferred is, because cheaper compute modulus of n^2.
the reason is:
value % (n^2) is equivalent to
value & (n^2 - 1) and cheaper compute bitwise & instead of %.
for example in code write this:
int v = perm[(x + perm[y % 256]) % 256]; or
int v = perm[(x + perm[y & 255]) & 255]; both give same result second method faster.
of course power of 2 can used this. think reason choosing 256 is balance between variety of pseudo random numbers , low memory consumption.
Comments
Post a Comment