chpter13 chinese version

pull/186/head
ray7551 7 years ago
parent 236b16fb2a
commit 159712201c

@ -38,7 +38,7 @@ y *= amplitude*0.06;
现在,让我们把正弦波放在一边,想想 Perlin 噪声Perlin 噪声的基本形式看起来和正弦波有点相似。它的振幅和频率有着某种变化,但振幅保持着合理的连续性,而且频率被限制在一个距离中心频率很小的范围内。尽管它不像正弦波那样规则,并且把几个不同缩放比例的 Perlin 噪声相加更容易制造出随机形态。把一些正弦波相加也是有可能制造随机形态的,但那需要很多不同的波叠加才能把他们的天生的周期性和规则形隐藏起来。
通过在循环(循环次数为 *octaves*)中叠加噪声,并以一定的倍数(*lacunarity*,间隙度)连续升高频率,同时以一定的比例(*gain*,增益)降低 **噪声** 的振幅最终的结果会有更好的细节。这项技术叫“分形布朗运动fractal Brownian Motion*fBM*或者“分形噪声fractal noise最简单的实现如下
通过在循环(循环次数为 *octaves*,一次循环为一个八度)中叠加噪声,并以一定的倍数(*lacunarity*,间隙度)连续升高频率,同时以一定的比例(*gain*,增益)降低 **噪声** 的振幅最终的结果会有更好的细节。这项技术叫“分形布朗运动fractal Brownian Motion*fBM*或者“分形噪声fractal noise最简单的实现如下
<div class="simpleFunction" data="// Properties
const int octaves = 1;
@ -60,21 +60,21 @@ for (int i = 0; i < octaves; i++) {
* 当 octaves 大于 4 时,尝试改变 lacunarity 的值。
* 当 octaves 大于 4 时,改变 gain 的值,看看会发生什么。
Note how with each additional octave, the curve seems to get more detail. Also note the self-similarity while more octaves are added. If you zoom in on the curve, a smaller part looks about the same as the whole thing, and each section looks more or less the same as any other section. This is an important property of mathematical fractals, and we are simulating that property in our loop. We are not creating a *true* fractal, because we stop the summation after a few iterations, but theoretically speaking, we would get a true mathematical fractal if we allowed the loop to continue forever and add an infinite number of noise components. In computer graphics, we always have a limit to how small details we can resolve, for example when objects become smaller than a pixel, so there is no need to make infinite sums to create the appearance of a fractal. A lot of terms may be needed sometimes, but never an infinite number.
注意,随着我们一个八度接一个八度地往上叠加,曲线看起来有越来越多的细节,同时,自相似性也越来越明显。如果你放大看看,曲线的局部和整体看起来很相似,并且,任选两段不同的部分看起来也多少有些相似。这是一个数学上的分形的重要性质,我们在上面的循环中模拟了这个性质。我们不是要创造一个*真的*分形,因为我们在几次循环之后就不再往上叠加了,但理论上说,如果我们一直继续这个循环,不断地往上叠加噪声,就会得到一个真正的数学意义上的分形。在计算机图形领域,我们能处理的细节总是有极限的,比如物体比一个像素还小的时候,所以没有必要不断地往上叠加来制造分形的形态。有时候我们是需要叠加很多次,但不必叠加无限次。
The following code is an example of how fBm could be implemented in two dimensions to create a fractal-looking pattern:
下面的示例代码就是 fBm 的二维实现,生成了分形图案:
<div class='codeAndCanvas' data='2d-fbm.frag'></div>
* Reduce the number of octaves by changing the value on line 37
* Modify the lacunarity of the fBm on line 47
* Explore by changing the gain on line 48
* 在 37 行减小八度OCTAVES的数量
* 在 47 行调试 fBm 的间隙度lacumarity
* 在 47 行调试 fBm 的增益gain
This technique is commonly used to construct procedural landscapes. The self-similarity of the fBm is perfect for mountains, because the erosion processes that create mountains work in a manner that yields this kind of self-similarity across a large range of scales. If you are interested in this, use you should definitly read [this great article by Inigo Quiles about advance noise](http://www.iquilezles.org/www/articles/morenoise/morenoise.htm).
这项技术被广泛地应用于构造程序化风景。fBm 的自相似性能够很完美地模拟山脉,因为山脉形成过程中的腐蚀形成了这种不同尺度上的自相似性。如果你对此感兴趣,你一定要去看看 [Inigo Quiles 这篇关于高级噪声的文章](http://www.iquilezles.org/www/articles/morenoise/morenoise.htm)。
![Blackout - Dan Holdsworth (2010)](holdsworth.jpg)
Using more or less the same technique, it's also possible to obtain other effects like what is known as **turbulence**. It's essentially an fBm, but constructed from the absolute value of a signed noise to create sharp valleys in the function.
使用相同的技术,也可以获得其他效果,比如**湍流**turbulence效果。它本质上是一个 fBm但是由一个有符号噪声的绝对值构成从而在函数中创建了尖锐的山谷。
```glsl
for (int i = 0; i < OCTAVES; i++) {
@ -86,7 +86,7 @@ for (int i = 0; i < OCTAVES; i++) {
<a href="../edit.php#13/turbulence.frag"><img src="turbulence-long.png" width="520px" height="200px"></img></a>
Another member of this family of algorithms is the **ridge**, where the sharp valleys are turned upside down to create sharp ridges instead:
这个算法家族中的另一个成员是**山脊**ridge就是把凹下去的山谷翻上来从而制造山脊
```glsl
n = abs(n); // create creases
@ -96,16 +96,16 @@ Another member of this family of algorithms is the **ridge**, where the sharp va
<a href="../edit.php#13/ridge.frag"><img src="ridge-long.png" width="520px" height="200px"></img></a>
Another variant which can create useful variations is to multiply the noise components together instead of adding them. It's also interesting to scale subsequent noise functions with something that depends on the previous terms in the loop. When we do things like that, we are moving away from the strict definition of a fractal and into the relatively unknown field of "multifractals". Multifractals are not as strictly defined mathematically, but that doesn't make them less useful for graphics. In fact, multifractal simulations are very common in modern commercial software for terrain generation. For further reading, you could read chapter 16 of the book "Texturing and Modeling: a Procedural Approach" (3rd edition), by Kenton Musgrave. Sadly, that book is out of print since a few years back, but you can still find it in libraries and on the second hand market. (There's a PDF version of the 1st edition available for purchase online, but don't buy that - it's a waste of money. It's from 1994, and it doesn't contain any of the terrain modeling stuff from the 3rd edition.)
这个算法的另外一个变种,把噪声分量乘起来(而不是叠加)可以创造一些很有用的东西。另外一个方法是,根据前一次循环中的噪声来缩放后续的噪声。当我们这样做的时候,我们已经走出严格的分形定义了,走入了一个叫“多重分形”的未知领域。多重分形虽不是按数学方式严格定义,但这并不意味着它的用处会更少些。 实际上,多重分形模拟生成地形中在商业软件中非常常见。要了解更多,你可以去读 Kenton Musgrave 的“Texturing and Modeling: a Procedural Approach”第三版的 16 章。很可惜,这本书几年前已经绝版,不过你还可以从图书馆和二手市场找到。网上有卖这本书第一版的 PDF 版,但是别去买——只是浪费钱。这是 1994 年的版本,不包括第三版包含的地形建模的部分。
### 域翘曲Domain Warping
[Inigo Quiles wrote this other fascinating article](http://www.iquilezles.org/www/articles/warp/warp.htm) about how it's possible to use fBm to warp a space of a fBm. Mind blowing, Right? It's like the dream inside the dream of Inception.
[Inigo Quiles 写了另一篇有趣的文章](http://www.iquilezles.org/www/articles/warp/warp.htm),关于如何用 fBm 来扭曲 fBm 空间。很有意思,不是吗?这就像《盗梦空间》里的梦中梦。
![ f(p) = fbm( p + fbm( p + fbm( p ) ) ) - Inigo Quiles (2002)](quiles.jpg)
A less extreme example of this technique is the following code where the wrap is used to produce this clouds-like texture. Note how the self-similarity property is still present in the result.
下面的代码展示了这项技术的一个不那么极端的例子,用它生成类似云一样的纹理。注意自相似性如何表现在结果中。
<div class='codeAndCanvas' data='clouds.frag'></div>
Warping the texture coordinates with noise in this manner can be very useful, a lot of fun, and fiendishly difficult to master. It's a powerful tool, but it takes quite a bit of experience to use it well. A useful tool for this is to displace the coordinates with the derivative (gradient) of the noise. [A famous article by Ken Perlin and Fabrice Neyret called "flow noise"](http://evasion.imag.fr/Publications/2001/PN01/) is based on this idea. Some modern implementations of Perlin noise include a variant that computes both the function and it's analytical gradient. If the "true" gradient is not available for a procedural function, you can always compute finite differences to approximate it, although this is less accurate and involves more work.
用这种方法用噪声扭曲纹理坐标非常有用,非常有趣,也极难掌握。这是个很强大的工具,但要想用好它需要一些经验。一个有用的办法是,用噪声的导数(梯度)替换坐标。[Ken Perlin 和 Fabrice Neyret 的一篇非常著名的“流体噪声”](http://evasion.imag.fr/Publications/2001/PN01/)就是以这个想法为基础。一些现代的 Perlin 噪声的实现不但计算噪声,还计算它的解析梯度。如果“真实”梯度对过程化函数不变计算,你总是可以计算出数值梯度来逼近它,尽管没那么精确而且要花费更多工夫。

Loading…
Cancel
Save