受限景观的程序生成 [英] Procedural generation of a constrained landscape

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

问题描述

我想实现地形的程序生成.经过彻底的研究,我得出一个结论,它应该使用梯度(相干)噪声生成算法之一来实现,例如 Perlin Noise 算法.但是,我不希望这一代完全随机.我想应用一些限制条件(例如哪里应该是山脉,或者哪里应该是低地等).

问题:

例如,我有一条曲线代表一些景观元素.曲线是一组点.

  • 我如何改进 Perlin Noise 算法,以便沿着这个曲线噪声将具有首选的值范围(或者,对于简单,值 0)?
  • 或者,如果我有一个纹理Perlin 噪声算法(二维数组)的输出,我该如何转换它到所需的噪声(受曲线影响)?

解决方案

如何改进 Perlin 噪声算法,以便沿着这条曲线噪声具有首选值范围(或者,为简单起见,值为 0)?

这可以通过一个简单的p->转换地图中的每个像素来实现.f(p) 数学函数.

考虑一个函数,它将紫色线映射到蓝色曲线 - 它强调较低的定位高度以及非常高的定位高度,但使它们之间的过渡更陡峭(这个例子只是一个余弦函数,使曲线更少平滑会使转换更加突出).

您也可以只使用曲线的下半部分,使峰值更锐利,位置较低的区域更平坦(因此更具可玩性).

曲线的锐度"可以很容易地通过功率(使效果更显着)或平方根(降低效果)进行调制.

这个的实现实际上非常简单(特别是如果你使用了余弦函数)——只需在地图中的每个像素上应用这个函数.如果函数在数学上不是那么简单,查找表就可以正常工作(在表值之间使用三次插值,线性插值会产生伪影).

(从我的答案复制到制作了这个)

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天全站免登陆