gpt4 book ai didi

c++ - 噪音功能实际上是如何工作的?

转载 作者:行者123 更新时间:2023-11-30 01:57:22 29 4
gpt4 key购买 nike

我查看了 libnoise 源并找到了 ValuNoise3D 函数:

double noise::ValueNoise3D (int x, int y, int z, int seed)
{
return 1.0 - ((double)IntValueNoise3D (x, y, z, seed) / 1073741824.0);
}

int noise::IntValueNoise3D (int x, int y, int z, int seed)
{
// All constants are primes and must remain prime in order for this noise
// function to work correctly.
int n = (
X_NOISE_GEN * x
+ Y_NOISE_GEN * y
+ Z_NOISE_GEN * z
+ SEED_NOISE_GEN * seed)
& 0x7fffffff;

n = (n >> 13) ^ n;
return (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
}

但当我看到它时,它对我来说是一种魔法。这实际上是如何工作的?我的意思是为什么写这篇文章的人用了那些质数而不是其他的?为什么会有这样的方程式?他是如何决定使用这些方程式而不是其他方程式的?只是……这怎么理解?

最佳答案

libnoise Web site对这个噪声函数背后的数学有很好的解释。特别是关于素数:

These large integers are primes. These integers may be modified as long as they remain prime; non-prime numbers may introduce discernible patterns to the output.

noise::IntValueNoise3D 实际上分两步操作:第一步将 (x, y, z) 坐标转换为单个整数,第二步将此整数通过整数噪声函数产生一个大约介于 -1073741824 和 1073741824 之间的噪声值。noise::ValueNoise3D 只是将该整数转换为介于 -1 和 1 之间的浮点值。

至于为什么 noise::IntValueNoise3D 执行所有这些复杂的操作,基本上可以归结为这样一个事实,即这个特定的操作序列产生了一个很好的、嘈杂的结果,没有明显的可见模式。这不是唯一可以使用的操作序列;任何产生足够嘈杂结果的东西都会起作用。

关于c++ - 噪音功能实际上是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18809346/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com