struct Tinman.Terrain.Util.MaterialKey

A MaterialKey defines the parameters that define the mapping from color values to material weights.

For each material ID, a MaterialKey is defined in the containing MaterialKeys object. For a given color, material weights are computed for each key and the weighted materials are then combined into a material token.

The weight w for a material key is computed as follows:

  1. The relative color distance dst is computed between the material key color (see Color) and the input color. The Colors.Distance_RGB_RGB method is used as metric.

  2. The distance dst is divided by the configured distance range (see Distance), which reduces the range of the material key.

  3. The distance dst is clamped using the configured clamp amount (see Clamp): dst = max(0, Clamp - dst) / Clamp. This cuts off small material weights while retaining the full weight range.

  4. The distance dst is scaled by the configured weight (see Weight, yielding the final material weight. This affects how strong the material will be realized in relation to the other material keys.

Public / Constants


public static readonly attribute Invalid → (MaterialKey)

The invalid (i.e. non-existent) material key.

Public / Constructors


public constructor MaterialKey → (5)

material in : int32

The material ID or -1 for an invalid material key.

color in : int64

The color key of the material.

distance opt : float64 = 1

The color distance range of this material.

weight opt : float64 = 1

The relative weight of this material.

clamp opt : float64 = 1

The relative clamp amount of this material.

Creates a new instance of MaterialKey.

Public / Methods


public method ComputeWeight → (1)

color in : int64

The color value.

returns → int32

The material weight, as a 14.15 fixed point number.

Computes the material weight for the given color.

Public / Attributes


public readonly attribute Clamp → (float64)

The relative clamp amount of this material.

A clamp amount less than one will cut off small material weights. A clamp amount greater than one will add small material weights.


public readonly attribute Color → (int64)

The color key of the material.


public readonly attribute Distance → (float64)

The color distance range of this material.

The material has full weight where the color distance is zero. The weight drops to zero when this distance value is reached.


public attribute Influence → (get)

value : float64

The relative influence.

The overall influence of this material key.


public attribute IsInvalid → (get)

value : bool

true if this material key is invalid, false if it is valid.

Is this material key invalid?


public readonly attribute Material → (int32)

The material ID in the range [0..255] or -1 if this material key is invalid (see IsInvalid).


public readonly attribute Weight → (float64)

The relative weight of this material.



public static attribute Config → (get)

value : IConfigurator<MaterialKey>

The configurator object.

The configurator object for this type.