Noise

noise插件基于一个名为libnoise的Perlin噪声发生器在程序上生成分形地形。我们将解释它在这里如何工作,但你也可以参考libniose文档来获取有关下列属性的含义和应用。

有许多方法来使用noise驱动器,在属性表后面有一些示例。

基本属性:

resolution(分辨率): 生成噪声数据一个周期的线性距离(通常以米为单位)。

scale(尺度): 一个周期内作用于噪声值的偏移量。默认为1.0,即你讲得到[-1…1]范围内的噪声数据。

octaves 通过添加细节级别来改善噪声数据的次数,即噪声发生器在分辨率范围内递归的深度。较高的数值将在你放大时产生出更多细节,默认值为4。

offset(偏移): 对于高程场,将其设为true来生成偏移量而不是绝对高程,它们将从另一个绝对高程图层中添加高程值。

高级属性:

frequency(频率): 上述分辨率(resolution)的倒数。(由于osgEarth是一个投影SDK,因此通常更直观地指定分辨率并将其留空。)

persistence(持久度): 当噪声函数遍历每个较高octave时尺度(scale)降低的速率。Scale(octave N + 1)=Scale(octave N)* Persistence。

lacunarity(空隙率) 当噪声函数遍历每一个较高细节octave时频率(frequency)增长的速率。Freq(octave N+1)=Freq(octave N)* Lacunarity。

seed: 随机数生成器,噪声驱动器是“连贯的”,即(除其他外)在给定相同随机种子的情况下生成相同的值。通过改变这个来改变模式。

min_elevation: 在构建高程场时所生成的最小高程值,使用高程数据来创造一个“楼层(floor)”。

max_elevation: 在构建高程场时所生成的最大高程值,使用高程数据来创造一个“楼顶(ceiling)”。

normal_map: 将此设为true(对于一个图像图层)来创建一个NormalMap地形效果一起使用的凹凸贴图法线纹理。

也可以参考:

tests文件夹中的noise.earthfractal_detail.earthnormalmap.earth示例。

示例

创建一个世界范围程序高程图层:

  1. <elevation driver="noise">
  2. <resolution>3185500</resolution> <!-- 1/4 earth's diameter -->
  3. <scale>5000</scale> <!-- vary heights by +/- 5000m over the resolution -->
  4. <octaves>12</octaves> <!-- detail recursion level -->
  5. </elevation>

通过调整递归属性使其更有趣:

  1. <elevation driver="noise">
  2. <resolution>3185500</resolution> <!-- 1/4 earth's diameter -->
  3. <scale>5000</scale> <!-- vary heights by +/- 5000m over the resolution -->
  4. <octaves>12</octaves> <!-- detail recursion level -->
  5. <persistence>0.49</persistence> <!-- don't reduce the scale as quickly = noisier -->
  6. <lacunarity>3.0</lacunarity> <!-- increase the frequency faster = lumpier -->
  7. </elevation>

通过创建图像层来查看噪声本身。看起来像云:

  1. <image driver="noise">
  2. <resolution>3185500</resolution> <!-- 1/4 earth's diameter -->
  3. <octaves>12</octaves> <!-- detail recursion level -->
  4. </image>

使用noise创建一个偏移图层来向真实高程数据中添加细节:

  1. <!-- Real elevation data -->
  2. <elevation name="readymap_elevation" driver="tms" enabled="true">
  3. <url>http://readymap.org/readymap/tiles/1.0.0/9/</url>
  4. </elevation>
  5. <elevation driver="noise" name="detail">
  6. <offset>true</offset> <!-- treat this as offset data -->
  7. <tile_size>31</tile_size> <!-- size of the tiles to create -->
  8. <resolution>250</resolution> <!-- not far from the resolution of our real data -->
  9. <scale>20</scale> <!-- vary heights by 20m over 250m -->
  10. <octaves>4</octaves> <!-- add some additional detail -->
  11. </elevation>

对于创建偏移高程数据,我们可以使用法线地图(normal map) 来伪装它。法线地图是一种不可见纹理,它模拟了使用真实高程数据时得到的法线向量:

  1. <image name="normalmap" driver="noise">
  2. <shared>true</shared> <!-- share this layer so our effect can find it -->
  3. <visible>false</visible> <!-- we don't want to see the actual texture -->
  4. <normal_map>true</normal_map> <!-- create a normal map please -->
  5. <tile_size>128</tile_size> <!-- 128x128 texture -->
  6. <resolution>250</resolution> <!-- resolution of the noise function -->
  7. <scale>20</scale> <!-- maximum height offset -->
  8. <octaves>4</octaves> <!-- level of detail -->
  9. </image>
  10. ...
  11. <external>
  12. <normal_map layer="normalmap"/> <!-- Install the terrain effect so we can see it -->
  13. <sky hours="17"/> <!-- Must have lighting as well -->
  14. </external>