参数随机函数对于二维噪声产生 [英] Parametric Random Function For 2D Noise Generation

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

问题描述

我试图产生无限的随机地形。地形应该产生相同的每次给予相同的种子。

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

我使用Java的随机函数尝试,创建使用x和y坐标上的地形网格的给定节点的各种功能的种子。如X * Y + X + Y +种子,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,种子)=随机数

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组合,但它应该是很容易推导出其他号码,一旦我有以上的功能。这将有助于决定地形的高度,而哪些特征(建筑物,树木)将是present。

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:

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

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