程序产生约束景观 [英] Procedural generation of a constrained landscape

查看:208
本文介绍了程序产生约束景观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个程序生成一个地形。 经过深入研究,我想出了,它应该用的梯度(相干)噪音生成算法之一来实现,例如柏林噪声算法的结论。 不过,我不希望发生是完全随机的。我想申请一些制约因素(如在这里应该是一个山脉,或者应该是一个低地等)。

问:

例如我有一个曲线,它重新presents一些景观元素。曲线是一个点的数组

  • 如何改进柏林噪声算法,使沿着这 曲线的噪声将有值的preferred范围(或者,对于 简单起见,值0)?
  • 另外,如果我有一个结构,该结构是一个 的柏林噪声算法(二维数组)的输出,我怎么可以把它 到所需的噪声(由曲线影响)?
解决方案
  我

如何改进柏林噪声算法,以便沿着该曲线的噪声将有值的preferred范围(或者,为简单起见,值0)?

这可以通过一个简单的点改变地图中的每个像素可以实现 - > F(P)数学函数。

考虑一个函数,映射紫线变成了蓝色曲线 - 它强调低级位于高度以及非常高的位于的高度,但使它们之间的过渡更陡(本实施例仅仅是一个余弦函数,使得曲线更小顺利将进行转型更为突出)。

您也可以只使用下半部的曲​​线,使峰更清晰,降低设区扁平化(因此更具可玩性)。

曲线的锐度可以容易地调制功率(使效果更加显着)或平方根(降低效果)。

这个实现实际上是非常简单的(特别是如果你使用余弦函数) - 只是应用功能在地图中的每个像素。如果函数不是那么数学琐碎,查找表只是正常工作(与表中的值之间的三次插值,线性插值造成假象)。

(从我aswer复制到<一个href="http://stackoverflow.com/questions/14006238/tweaking-heightmap-generation-for-hexagon-grids/14009833#14009833">another问题)

如果你需要的是改造产生的噪声为一个已知值范围(如-1.0 - 1.0),使用这种算法:

 函数scaleValues​​To(高度图,newMin,newMax)
{
    VAR分钟=分钟(高度图)
    VAR范围= MAX(高度图) - 分;
    VAR newRange = newMax  -  newMin;

    对于每个坐标X,Y做:
        hrightMap [X,Y] = newMin +(高度图[X,Y]  - 分钟)* newRange /范围;
    结束了
}
 

  

我想申请一些制约因素(如在这里应该是一个山脉,或者应该是一个低地等)。

这是有点复杂,因为你需要指定山上会。最简单的解决方案是创建一个单独的高度图(你可以在程序上做到这一点,或从一个位图加载它,这并不重要)与期望的地形的大致形状,然后与你的噪声地图一起添加。有几件事情要记住:

1)确保有模板的地图上没有锋利的边缘(这将是结合地图上非常明显)。框模糊通常足以用于此目的,但更复杂的过滤器一样的高斯模糊给出更好的结果(在某些情况下,框模糊将preserve地图上的一些尖锐的边缘)。

2)您可能希望对噪声地图在高海拔和低优先级较低的海拔更高的优先级。这可以通过做这样的事情很容易实现: combinedMap [X,Y] = templateMap [X,Y] +(0.2 + 0.8 * templateMap [X,Y])* noiseMap [X,Y]

您可以看到这个图上这种方式:

(我做了这个我自己地形生成项目

I'd like to implement a procedural generation of a terrain. After a thorough research I came up with a conclusion that it should be implemented with one of the gradient (coherent) noise generation algorithms, for instance Perlin Noise algorithm. However, I don't want the generation to be completely random. I'd like to apply some constraints (like where should be a mountain range, or where should be a lowland etc.).

Question:

For example I have a curve which represents some landscape element. The curve is an array of points.

  • How can I improve the Perlin Noise algorithm, so that along this curve the noise will have a preferred range of values (or, for simplicity, value 0)?
  • Alternatively, if I have a texture which is an output of Perlin Noise algorithm (2d array), how can I transform it to the desired noise (influenced by the curve)?

解决方案

How can I improve the Perlin Noise algorithm, so that along this curve the noise will have a preferred range of values (or, for simplicity, value 0)?

This can be achieved by transforming each pixel in the map through a simple p -> f(p) mathematical function.

Consider a function, which maps the purple line into the blue curve - it emphasizes lower located heights as well as very high located heights, but makes the transition between them steeper (this example is just a cosine function, making the curve less smooth would make the transformation more prominent).

You could also only use bottom half of the curve, making peaks sharper and lower located areas flatter (thus more playable).

"sharpness" of the curve can be easily modulated with power (making the effect much more dramatic) or square root (decreasing the effect).

Implementation of this is actually extremely simple (especially if you use the cosine function) - just apply the function on each pixel in the map. If the function isn't so mathematically trivial, lookup tables work just fine (with cubic interpolation between the table values, linear interpolation creates artifacts).

(Copied from my aswer to another question)

If all you need is to transform the generated noise into a known value range (like -1.0 - 1.0), use this algorithm:

function scaleValuesTo(heightMap, newMin, newMax)
{
    var min = min(heightMap);
    var range = max(heightMap) - min;
    var newRange = newMax - newMin;

    for each coordinate x, y do:
        hrightMap[x, y] = newMin + (heightMap[x, y] - min) * newRange / range;
    end for
}

I'd like to apply some constraints (like where should be a mountain range, or where should be a lowland etc.).

This is a bit more complicated, because you need to specify where the mountains will be. The easiest solution is to create a separate height map (you can do this either procedurally or load it from a bit map, it doesn't matter) with the rough shape of the terrain desired and then add it together with your noise map. There are a few things to keep in mind:

1) Make sure there are no sharp edges on the template map (those would be very visible on the combined map). Box blur is usually enough for this purpose, although a more complex filter like Gaussian blur gives better results (in some occasions, box blur will preserve some sharp edges on the map).

2) You may want to give higher priority to the noise map in higher elevations and lower priority in lower elevations. This can be easily achieved by doing something like this: combinedMap[x, y] = templateMap[x, y] + (0.2 + 0.8 * templateMap[x, y]) * noiseMap[x, y].

You can see this approach on this diagram:

(I have made this for my own terrain generation project)

这篇关于程序产生约束景观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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