【问题标题】:2D Perlin Noise looking odd2D Perlin Noise 看起来很奇怪
【发布时间】: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


【解决方案1】:

您将像素坐标标准化为整个图像。您应该将其标准化为您的单纯形网格的大小。

所以代替你的内部循环代码:

  double x = j/(double)w;
  double y = i/(double)h;

做:

  double x = j / gridsize;
  double y = i / gridsize;

其中网格大小为附加参数,例如:

  double gridsize = 32.0;

(可能应该选择它以均匀地适应图像尺寸。)

【讨论】:

    猜你喜欢
    • 2017-09-04
    • 1970-01-01
    • 2021-07-02
    • 1970-01-01
    • 2021-03-25
    • 2011-07-19
    • 2021-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多