用于 2D 噪声生成的参数随机函数 [英] Parametric Random Function For 2D Noise Generation

查看:33
本文介绍了用于 2D 噪声生成的参数随机函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试生成无限随机地形.给定相同的种子,地形应该每次都生成相同的.

I'm attempting to generate infinite random terrain. The terrain should generate the same every time given the same seed.

我尝试过使用 Java 的 Random 函数,使用地形网格上给定节点的 x 和 y 坐标的各种函数创建种子.如x*y+x+y+seed、20*x+30*y等

I've tried using Java's Random function, creating the seed using various functions of the x and y co-ordinates of the given node on the terrain grid. Such as x*y+x+y+seed, 20*x+30*y etc.

这种方法的问题是我总是在生成的数字中看到清晰的模式.

The problem with this approach is that I always see clear patterns in the numbers generated.

所以基本上我想要的是:f(x,y) = 随机数

So basically what I want is: f(x,y) = Random Number

如果上面的函数可以包含某种种子,它会很有帮助,使它:f(x,y,seed) = 随机数

It would be helpful if the above function could include a seed of some sort, making it: f(x,y,seed) = Random Number

我需要为每个 x,y 组合生成几个数字,但是一旦我有了上述函数,就应该很容易推导出其他数字.这些将用于决定地形的高度,以及将出现哪些特征(建筑物、树木).

I will need to generate several numbers for each x,y combination but it should be easy enough to derive additional numbers once I have the above function. These will serve to dictate height of the terrain, and what features (buildings, trees) will be present.

请不要提及柏林噪声或其他此类方法.我的问题不是让噪音看起来不错,而是获得可靠的随机"噪音.

Please, no mention of Perlin Noise or other such methods. My problem isn't making the noise look good, it's getting reliably "random" noise.

谢谢,杰米.

推荐答案

您正在寻找散列函数.尝试其中之一:

You are looking for hashing function. Try one of those:

http:///www.concentric.net/~ttwang/tech/inthash.htm

以下是示例用法:

int hash32shift(int key)
{
  key = ~key + (key << 15); // key = (key << 15) - key - 1;
  key = key ^ (key >>> 12);
  key = key + (key << 2);
  key = key ^ (key >>> 4);
  key = key * 2057; // key = (key + (key << 3)) + (key << 11);
  key = key ^ (key >>> 16);
  return key;
}

int noise(int x, int y, int seed)
{
    return hash32shift(seed+hash32shift(x+hash32shift(y)));
}

而且,它看起来像这样:

And, it looks like this:

这篇关于用于 2D 噪声生成的参数随机函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆