Class TCastleTerrainNoise

Unit

Declaration

type TCastleTerrainNoise = class(TCastleTerrainData)

Description

Terrain heights are generated from a smooth noise, combined with some terrain-specific improvements (Heterogeneous).

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:

Source: scene/castleterrain.pas (line 255).

Hierarchy

Show Additional Members:

Overview

Constants

Public DefaultOctaves = 4.0;
Public DefaultSmoothnes = 2.0;
Public DefaultAmplitude = 8.0;
Public DefaultFrequency = 0.05;
Public DefaultInterpolation = niCosine;
Public DefaultBlur = false;
Public DefaultHeterogeneous = 0.5;

Methods

Protected function GetInternalText: String; virtual;
Protected procedure SetInternalText(const Value: String); virtual;
Protected procedure SetName(const Value: TComponentName); override;
Protected procedure TranslateProperties(const TranslatePropertyEvent: TTranslatePropertyEvent); virtual;
Public procedure CustomSerialization(const SerializationProcess: TSerializationProcess); virtual;
Public procedure SetTransient;
Public procedure AddNonVisualComponent(const NonVisualComponent: TComponent);
Public procedure InsertNonVisualComponent(const Index: Integer; const NonVisualComponent: TComponent);
Public procedure RemoveNonVisualComponent(const NonVisualComponent: TComponent);
Public function NonVisualComponentsIndexOf(const NonVisualComponent: TComponent): Integer;
Public function NonVisualComponentsCount: Integer;
Public function NonVisualComponentsEnumerate: TNonVisualComponentsEnumerator;
Public function ValueIsStreamed: Boolean; virtual;
Public procedure DesignerInfo(const SList: TStrings); virtual;
Public procedure DesignerWarnings(const SList: TStrings); virtual;
Protected procedure DoChange;
Public destructor Destroy; override;
Public procedure AddChangeNotification(const Notify: TNotifyEvent);
Public procedure RemoveChangeNotification(const Notify: TNotifyEvent);
Public constructor Create(AOwner: TComponent); override;
Public function Height(const Coord, TexCoord: TVector2): Single; override;
Public function PropertySections(const PropertyName: String): TPropertySections; override;

Properties

Public property NonVisualComponents [const Index: Integer]: TComponent read GetNonVisualComponents;
Public property IsLoading: Boolean read FIsLoading;
Published property Octaves: Single read FOctaves write SetOctaves default DefaultOctaves;
Published property Smoothness: Single read FSmoothness write SetSmoothness default DefaultSmoothnes;
Published property Amplitude: Single read FAmplitude write SetAmplitude default DefaultAmplitude;
Published property Frequency: Single read FFrequency write SetFrequency default DefaultFrequency;
Published property Interpolation: TNoiseInterpolation read FInterpolation write SetInterpolation default DefaultInterpolation;
Published property Blur: Boolean read FBlur write SetBlur default DefaultBlur;
Published property Seed: Cardinal read FSeed write SetSeed default 0;
Published property Heterogeneous: Single read FHeterogeneous write SetHeterogeneous default DefaultHeterogeneous;

Description

Constants

Public DefaultOctaves = 4.0;

This item has no description.

Source: scene/castleterrain.pas (line 280).

Public DefaultSmoothnes = 2.0;

This item has no description.

Source: scene/castleterrain.pas (line 281).

Public DefaultAmplitude = 8.0;

This item has no description.

Source: scene/castleterrain.pas (line 282).

Public DefaultFrequency = 0.05;

This item has no description.

Source: scene/castleterrain.pas (line 283).

Public DefaultInterpolation = niCosine;

This item has no description.

Source: scene/castleterrain.pas (line 284).

Public DefaultBlur = false;

This item has no description.

Source: scene/castleterrain.pas (line 285).

Public DefaultHeterogeneous = 0.5;

This item has no description.

Source: scene/castleterrain.pas (line 286).

Methods

Protected function GetInternalText: String; virtual;

This item is declared in ancestor TCastleComponent.

This item has no description.

Source: base/castleclassutils.pas (line 575).

Protected procedure SetInternalText(const Value: String); virtual;

This item is declared in ancestor TCastleComponent.

This item has no description.

Source: base/castleclassutils.pas (line 576).

Protected procedure SetName(const Value: TComponentName); override;

This item is declared in ancestor TCastleComponent.

This item has no description.

Source: base/castleclassutils.pas (line 577).

Protected procedure TranslateProperties(const TranslatePropertyEvent: TTranslatePropertyEvent); virtual;

This item is declared in ancestor TCastleComponent.

Enumerate all properties that are possible to translate in this component. E.g. in TCastleLabel it will return TCastleLabel.Caption, in TCastleEdit it will return TCastleEdit.Text and TCastleEdit.Placeholder.

Returns only non-empty properties, thus assuming that if current (by convention, English) text is empty, then there is no point in translating it. Moreover descendants may define boolean properties to exclude particular text from translating, e.g. TCastleLabel.CaptionTranslate, TCastleEdit.TextTranslate, TCastleEdit.PlaceholderTranslate.

It is not recursive (it doesn't enumerate children properties). Use global TranslateProperties procedure to call this on a hierarchy of TComponent.

You usually don't want to call this method (it is called by other engine routines). But you may find it useful to override this, if you define new component.

Source: base/castleclassutils.pas (line 598).

Public procedure CustomSerialization(const SerializationProcess: TSerializationProcess); virtual;

This item is declared in ancestor TCastleComponent.

Override this method to call various methods of SerializationProcess, which in turn allows to serialize/deserialize things that are not published. This allows to serialize/deserialize with more freedom, e.g. to serialize/deserialize some private field.

Source: base/castleclassutils.pas (line 610).

Public procedure SetTransient;

This item is declared in ancestor TCastleComponent.

Ignore this component when serializing parent's TCastleUserInterface.Controls list or TCastleTransform.List, and do not show this component in CGE editor. This simply sets csTransient flag in ComponentStyle.

This is useful for children that are automatically managed by the parent, and should not be modified by user code. For example, TCastleCheckbox is internally composed from TCastleImageControl and TCastleLabel children, but we don't want to serialize or even show these children to user.

Note that if you want to prevent this component from serializing as part of TCastleUserInterface.Controls list or TCastleTransform.List, but you still want it to be visible in CGE editor, then make it a "subcomponent" instead, by SetSubComponent(true).

Note that both csSubComponent and csTransient only disable the component serialization as part of parent's lists enumerated by CustomSerialization (see internal TCastleUserInterface.SerializeChildrenEnumerate , TCastleTransform.SerializeChildrenEnumerate, TCastleTransform.SerializeBehaviorsEnumerate).

If you will make the component published in its own property (which is normal for "subcomponents") then it will be serialized anyway, just as part of it's own property (like TCastleScrollView.ScrollArea). So to really avoid serializing a children component make it csSubComponent and/or csTransient, and do not publish it.

Source: base/castleclassutils.pas (line 663).

Public procedure AddNonVisualComponent(const NonVisualComponent: TComponent);

This item is declared in ancestor TCastleComponent.

Add non-visual component to this component. This is used to organize non-visual components in a tree hierarchy, in CGE designs and editor.

See also
NonVisualComponentsCount
Count of components added by AddNonVisualComponent.
NonVisualComponents
Components added by AddNonVisualComponent.
NonVisualComponentsEnumerate
You can enumerate current non-visual components using loop like for C in MyComponent.NonVisualComponentsEnumerate do ....

Source: base/castleclassutils.pas (line 672).

Public procedure InsertNonVisualComponent(const Index: Integer; const NonVisualComponent: TComponent);

This item is declared in ancestor TCastleComponent.

Insert non-visual component to this component. This is used to organize non-visual components in a tree hierarchy, in CGE designs and editor.

See also
NonVisualComponentsCount
Count of components added by AddNonVisualComponent.
NonVisualComponents
Components added by AddNonVisualComponent.
NonVisualComponentsEnumerate
You can enumerate current non-visual components using loop like for C in MyComponent.NonVisualComponentsEnumerate do ....

Source: base/castleclassutils.pas (line 681).

Public procedure RemoveNonVisualComponent(const NonVisualComponent: TComponent);

This item is declared in ancestor TCastleComponent.

Removes the component previously added by AddNonVisualComponent.

Source: base/castleclassutils.pas (line 684).

Public function NonVisualComponentsIndexOf(const NonVisualComponent: TComponent): Integer;

This item is declared in ancestor TCastleComponent.

Index of the previously added non-visual component. Returns -1 if the component was not found.

Source: base/castleclassutils.pas (line 688).

Public function NonVisualComponentsCount: Integer;

This item is declared in ancestor TCastleComponent.

Count of components added by AddNonVisualComponent.

See also
AddNonVisualComponent
Add non-visual component to this component.
NonVisualComponents
Components added by AddNonVisualComponent.
NonVisualComponentsEnumerate
You can enumerate current non-visual components using loop like for C in MyComponent.NonVisualComponentsEnumerate do ....

Source: base/castleclassutils.pas (line 695).

Public function NonVisualComponentsEnumerate: TNonVisualComponentsEnumerator;

This item is declared in ancestor TCastleComponent.

You can enumerate current non-visual components using loop like for C in MyComponent.NonVisualComponentsEnumerate do .... Do not call this method in other contexts, it is only useful for "for..in" construction.

See also
AddNonVisualComponent
Add non-visual component to this component.

Source: base/castleclassutils.pas (line 705).

Public function ValueIsStreamed: Boolean; virtual;

This item is declared in ancestor TCastleComponent.

Whether the current value of this object should be written to the stream. This should be True if anything inside this object should be serialized (which means it has non-default value or "stored" specifier indicates that it should be serialized).

This is used by CastleComponentSerialize, which is used in Castle Game Engine for all serialization.

In simple cases, this just says whether the current value of this object equals to some default value.

The default implementation of this class returns True (so always write).

Descendants that override this to sometimes return False (so no need to write) must be very careful: any addition of a new field requires extending this method, otherwise new field may not be saved sometimes (when all other fields are default). Descentants of such classes must also be aware of it. This check must include everything that is inside this object in JSON, including subcomponents and children objects (as done e.g. by TSerializationProcess.ReadWriteList). In practice, overriding this method is only reasonable for simple classes that will not change much in the future, like TCastleVector3Persistent.

The name of this method is consistent with TPropertyEditor.ValueIsStreamed in LCL.

Source: base/castleclassutils.pas (line 739).

Public procedure DesignerInfo(const SList: TStrings); virtual;

This item is declared in ancestor TCastleComponent.

Override to add information that should be visible at design-time. Call SList.Add for each new line of information.

Source: base/castleclassutils.pas (line 743).

Public procedure DesignerWarnings(const SList: TStrings); virtual;

This item is declared in ancestor TCastleComponent.

Override to add warnings that should be visible at design-time. Call SList.Add for each new warning.

Source: base/castleclassutils.pas (line 747).

Protected procedure DoChange;

This item is declared in ancestor TCastleTerrainData.

Use this in descendants implementation to notify that data (affecting Height results) changed. In the base class, it takes care to run notifications registered by AddChangeNotification.

Source: scene/castleterrain.pas (line 139).

Public destructor Destroy; override;

This item is declared in ancestor TCastleTerrainData.

This item has no description.

Source: scene/castleterrain.pas (line 142).

Public procedure AddChangeNotification(const Notify: TNotifyEvent);

This item is declared in ancestor TCastleTerrainData.

Add notification when data (affecting Height results) changes.

Source: scene/castleterrain.pas (line 163).

Public procedure RemoveChangeNotification(const Notify: TNotifyEvent);

This item is declared in ancestor TCastleTerrainData.

Remove notification when data (affecting Height results) changes.

Source: scene/castleterrain.pas (line 165).

Public constructor Create(AOwner: TComponent); override;

This item has no description.

Source: scene/castleterrain.pas (line 288).

Public function Height(const Coord, TexCoord: TVector2): Single; override;

This item has no description. Showing description inherited from TCastleTerrainData.Height.

Return height for given terrain point.

Source: scene/castleterrain.pas (line 289).

Public function PropertySections(const PropertyName: String): TPropertySections; override;

This item has no description. Showing description inherited from TCastleComponent.PropertySections.

Section where to show property in the editor.

Source: scene/castleterrain.pas (line 290).

Properties

Public property NonVisualComponents [const Index: Integer]: TComponent read GetNonVisualComponents;

This item is declared in ancestor TCastleComponent.

Components added by AddNonVisualComponent.

Source: base/castleclassutils.pas (line 698).

Public property IsLoading: Boolean read FIsLoading;

This item is declared in ancestor TCastleComponent.

Is the component during deserialization now.

Note: We can't use csLoading in ComponentState because in Delphi it is not possible to control it from CastleComponentSerialize.

Source: base/castleclassutils.pas (line 711).

Published property Octaves: Single read FOctaves write SetOctaves default DefaultOctaves;

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.)

Reasonable values are roughly between 0..20.

Source: scene/castleterrain.pas (line 301).

Published property Smoothness: Single read FSmoothness write SetSmoothness default DefaultSmoothnes;

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.

Reasonable values are roughly between 1..10.

Source: scene/castleterrain.pas (line 325).

Published property Amplitude: Single read FAmplitude write SetAmplitude default DefaultAmplitude;

Amplitude and frequency of the first noise octave. Amplitude scales the height of the result, and Frequency scales the size of the bumps.

Source: scene/castleterrain.pas (line 331).

Published property Frequency: Single read FFrequency write SetFrequency default DefaultFrequency;

This item has no description.

Source: scene/castleterrain.pas (line 332).

Published property Interpolation: TNoiseInterpolation read FInterpolation write SetInterpolation default DefaultInterpolation;

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.

Source: scene/castleterrain.pas (line 352).

Published property Blur: Boolean read FBlur write SetBlur default DefaultBlur;

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.

Source: scene/castleterrain.pas (line 368).

Published property Seed: Cardinal read FSeed write SetSeed default 0;

Determines the random seeds used when generating the terrain.

Source: scene/castleterrain.pas (line 371).

Published property Heterogeneous: Single read FHeterogeneous write SetHeterogeneous default DefaultHeterogeneous;

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").

Reasonable values for this are between 0..2.

Source: scene/castleterrain.pas (line 389).


Generated by PasDoc 0.17.0.snapshot.