【发布时间】:2015-03-20 20:25:43
【问题描述】:
我不确定我的 Perlin 噪声生成器是否正常运行,它生成的噪声看起来与我在网上看到的图像大不相同。我的看起来太同质了(这是三个不同的图像):
而我通常看到的是这样的:
我的代码基本上是:
/* Get the coord of the top-left gradient of the grid (y, x) falls in */
int j = floor(x);
int i = floor(y);
/* Get the distance (y, x) is from it */
double dx = x-j;
double dy = y-i;
/* Influence of (g)radient(i)(j) (starting at the top-left one) */
double g00 = dot(grad(hashes, hsize, grads, i, j), dy, dx);
double g01 = dot(grad(hashes, hsize, grads, i, j+1), dy, dx-1);
double g10 = dot(grad(hashes, hsize, grads, i+1, j), dy-1, dx);
double g11 = dot(grad(hashes, hsize, grads, i+1, j+1), dy-1, dx-1);
/* Interpolate the influences using the blending function */
/* Linear interpol the top 2 */
double lt = lerp(g00, g01, fade(dx));
/* Linear interpol the bottom 2 */
double lb = lerp(g10, g11, fade(dx));
/* Linear interpol lb lt, completing the bilienear interpol */
return lerp(lt, lb, fade(dy));
Complete code。它主要基于this 教程。我正在使用this script 来绘制 csv 文件。
我了解基础知识,但是在阅读了几个通常相互矛盾的“教程”和不太可读的“参考实现”之后,我有一些疑问。被插值的(x, y) 点应该在什么间隔内?据我了解,它应该是[0, GRID_SIZE-1](例如[0, 255],如果使用具有 256 个随机值的预计算表)。然而,当(x, y) 映射到[0, 1] 时,我的代码只会产生相当好看的图像,并且我看到一些在线实现将其映射到[0, 255],无论网格大小如何。我也不确定我是否从表格中正确选择了渐变。
【问题讨论】:
-
看起来像 perlin 噪音,只是太缩放了。看看 M Oehm 的答案。
标签: c noise perlin-noise