Castle Game Engine: CastleTerrain: Class TTerrainNoise

# Class TTerrainNoise
Description | Hierarchy | Fields | Methods | Properties
## Unit CastleTerrain ## Declaration `type TTerrainNoise = class(TTerrainImage)` ## Description Procedural terrain: data from a procedural noise. "Synthesized noise" means it's not simply something random. We take the noise (integer noise, i.e. hash), smooth it (how well, and how fast — see Interpolation and Blur), and add several functions ("octaves") of such noise (with varying frequency and amplitude) together. This is the kind of noise used to synthesize textures, terrains and all other procedural stuff. For more info about math inside: [http://en.wikipedia.org/wiki/Fractional_Brownian_motion]. This is the idea of summing up octaves of noise. Ken Musgrave's dissertation has a lot of info and interesting references: [http://www.kenmusgrave.com/dissertation.html] Blender's source code is informative, interesting file is blender/source/blender/blenlib/intern/noise.c The simplest practical introduction to the idea is on [http://freespace.virgin.net/hugo.elias/models/m_perlin.htm]. It describes how to get nice noise very easily, and my approach follows theirs. This descends from TTerrainImage, so you add an image to your function result. ## Hierarchy TObject TTerrain TTerrainImage TTerrainNoise ## Overview ### Methods
| `constructor Create;`
| `function Height(const X, Y: Single): Single; override;`
### Properties
| `property Octaves: Single read FOctaves write FOctaves default 4.0;`
| `property Smoothness: Single read FSmoothness write FSmoothness default 2.0;`
| `property Amplitude: Single read FAmplitude write FAmplitude default 1.0;`
| `property Frequency: Single read FFrequency write FFrequency default 1.0;`
| `property Interpolation: TNoiseInterpolation read FInterpolation write SetInterpolation default niCosine;`
| `property Blur: boolean read FBlur write SetBlur default false;`
| `property Seed: Cardinal read FSeed write FSeed default 0;`
| `property Heterogeneous: Single read FHeterogeneous write FHeterogeneous default 0.0;`
## Description ### Methods
| `constructor Create;`
| `function Height(const X, Y: Single): Single; override;`
### Properties
| `property Octaves: Single read FOctaves write FOctaves default 4.0;`
Number of noise functions to sum. This linearly affects the time for Height call, so don't make it too much. Usually ˜a few are Ok. (The fact that it's a float is just a simple trick to allow smooth transitions from x to x+1. In fact, it's executed like Trunc(`Octaves`) * some noises + Frac(`Octaves`) * some last noise.)
| `property Smoothness: Single read FSmoothness write FSmoothness default 2.0;`
How noise amplitude changes, when frequency doubles. When we double frequency, amplitude is divided by this. Smaller values <=> larger frequency noise is more visible, so terrain is less smooth (more noisy). This is elsewhere called fractal increment, fractal dimension parameter, "H", spectral exponent (see e.g. Blender sources, Musgrave's dissertation). Do not confuse this with "lacunarity" (how frequency changes in each octave), that is simply hardcoded to 2.0 in our code currently. In [http://freespace.virgin.net/hugo.elias/models/m_perlin.htm], the inverse of this 1/`Smoothness` is called "Persistence". I decided to call it "`Smoothness`", since this is the practical intuitive meaning. Value equal 1.0 means that amplitude doesn't change at all, each noise frequency is visible the same, so in effect you will just see a lot of noise. And values < 1.0 are really nonsense, they make more frequency noise even more visible, which means that the terrain is dominated by noise.
| `property Amplitude: Single read FAmplitude write FAmplitude default 1.0;`
`Amplitude` and frequency of the first noise octave. `Amplitude` scales the height of the result, and Frequency scales the size of the bumps.
| `property Frequency: Single read FFrequency write FFrequency default 1.0;`
| `property Interpolation: TNoiseInterpolation read FInterpolation write SetInterpolation default niCosine;`
How integer noise is interpolated to get smooth float noise. Setting this to niNone turns off `interpolation`, which means that your terrain is a sum of a couple of blocky noises — ugly. Using niLinear (means "bilinear", since this is 2D case) is also usually bad. Unless you use octaves of really high frequencies, usually sharp edges / flat in-betweens will be visible. Using niCosine in right now the best. Using niSpline is even better looking (usese Catmull-Rom splines, which are special case of cubic Hermite spline, see http://en.wikipedia.org/wiki/Cubic_Hermite_spline, http://en.wikipedia.org/wiki/Bicubic_interpolation). But it's more time consuming under current implementation.
| `property Blur: boolean read FBlur write SetBlur default false;`
Resulting noise octaves may be blurred. This helps to remove the inherent vertical/horizontal directionality in our 2D noise (it also makes it more smooth, since that's what blurring is about; you may want to increase Frequency * 2 to balance this). This is independent from Interpolation. Although the need for `Blur` is most obvious in poor/none interpolation methods (none, linear), it also helps for the nicer interpolation methods (cosine, cubic). Note about [http://freespace.virgin.net/hugo.elias/models/m_perlin.htm]: this "blurring" is called "smoothing" there. I call it blurring, as it seems more precise to me.
| `property Seed: Cardinal read FSeed write FSeed default 0;`
Determines the random seeds used when generating the terrain.
| `property Heterogeneous: Single read FHeterogeneous write FHeterogeneous default 0.0;`
If non-zero, then we generate terrain using `heterogeneous` fBm. Intuitively, the idea is that the terrain details (from higher octaves) are more noisy when ground is higher. This is realistic (debris gathers in lower terrain, smoothing it more). More precisely, this means that we accumulate multiplied previous noise, at each step dividing this accumulated result by `Heterogeneous`, and clamping at 1.0. So when `Heterogeneous` is very small, this always ends up 1.0, and we get normal (homogeneous) generation. When `Heterogeneous` is larger, the details (at lower ground) are scaled down (terrain is smoother). This is called "threshold" in Musgrave's dissertation (see algorithm in section 2.3.2.5 "A Large Scale Terrain Model").
Generated by PasDoc 0.13.0 on 2015-06-15 04:43:12