TINMAN 3D / REALTIME TERRAIN
Software Development Kit - User Manual

class MaterialToken in Tinman.Terrain.Util

The MaterialToken class implements the concept of material tokens for terrain rendering.

static class MaterialToken  

Remarks

A material token is a 64-bit value that defines weights for up to 4 materials out of a palette of 256 possible materials:

Bits     | Name | Description               | Range
---------+------+---------------------------+---------
[0 .. 8[ | w0   | Weight of first material  | [0..255]
[8 ..16[ | w1   | Weight of second material | [0..255]
[16..24[ | w2   | Weight of third material  | [0..255]
[24..32[ | w3   | Weight of fourth material | [0..255]
[32..40[ | m0   | ID of first material      | [0..255]
[40..48[ | m1   | ID of second material     | [0..255]
[48..56[ | m2   | ID of third material      | [0..255]
[56..64[ | m3   | ID of fourth material     | [0..255]
A weight value of 255 means that the material is fully realized, a value of 0 means that the material is completely dissolved. Furthermore, the material ID values of a token always appear in descending order, and the last material ID is duplicated in order to mark the token end:
m0 > m1 > m2 > m3     -> four materials
m0 > m1 > m2, m3 = m2 -> three materials
m0 > m1, m2 = m3 = m1 -> two materials
m0 = m1 = m2 = m3     -> one material
The individual material weights are unrelated. It is up to the application to properly interpret the weights.

Configuration

Config

The configurator object for this type.

public static property Config { get }
type IConfigurator<int64>
value [not-null] The configurator object.

Public / Methods

Count

Counts the number of materials in the given material mask.

[Pure]
public static method Count (int64 mask)
type int32
params mask The material mask (see Mask).
returns [0..64] The number of materials.

Distance

Computes the distance between the given material tokens.

[Pure]
public static method Distance (int64 tokenA, int64 tokenB)
type int32
params tokenA First material token.
  tokenB Second material token.
returns [0..255] The relative distance between the material tokens.

For

Creates a material token.

[Pure]
public static method For (int32 material, int32 weight = 255)
type int64
params material The material ID, in the range [0..255].
  weight The material weight of material, in the range [0..255]. Defaults to 255.
returns The material token.

Creates a material token.

[Pure]
public static method For (int32 m0, int32 m1, int32 m2, int32 m3, int32 w0, int32 w1, int32 w2, int32 w3)
type int64
params m0 The material ID, in the range [0..255] or -1 if not used.
  m1 The material ID, in the range [0..255] or -1 if not used.
  m2 The material ID, in the range [0..255] or -1 if not used.
  m3 The material ID, in the range [0..255] or -1 if not used.
  w0 The material weight of m0, in the range [0..255].
  w1 The material weight of m0, in the range [0..255].
  w2 The material weight of m0, in the range [0..255].
  w3 The material weight of m0, in the range [0..255].
returns The material token.

Remarks:

The material IDs m0, m1, m2 and m3 must be distinct, except when equal to -1.

Mask

Returns the bitmask for the given material token.

[Pure]
public static method Mask (int64 token)
type int64
params token The material token.
returns The material bitmask.

Remarks:

A material ID n is mapped to the bit 2^n.

See also:

Semantic.MaterialMask

MaterialAt

Returns a material ID of the given token.

[Pure]
public static method MaterialAt (int64 token, int32 n)
type int32
params token The material token.
  n The material index, in the range [0..3].
returns [0..255] The material ID.

Mix

Mixes the given material tokens.

[Pure]
public static method Mix (int64 a, int64 b, int32 fa, int32 fb)
type int64
params a First material token.
  b Second material token.
  fa Scale of first material token, in the range [0....255].
  fb Scale of second material token, in the range [0....255].
returns The resulting material token.

Mixes the given material tokens.

[Pure]
public static method Mix (int64 a, int64 b, int64 c, int64 d, int32 fa, int32 fb, int32 fc, int32 fd)
type int64
params a First material token.
  b Second material token.
  c Third material token.
  d Fourth material token.
  fa Scale of first material token, in the range [0....255].
  fb Scale of second material token, in the range [0....255].
  fc Scale of third material token, in the range [0....255].
  fd Scale of fourth material token, in the range [0....255].
returns The resulting material token.

MixCatmullRom

Interpolates between the material tokens b and c using a Catmull-Rom spline.

[Pure]
public static method MixCatmullRom (int64 a, int64 b, int64 c, int64 d, int32 f)
type int64
params a Zeroth control point.
  b First control point.
  c Second control point.
  d Third control point.
  f Interpolation factor, in the range [0..255].
returns The interpolated material token.

MixUniformB

Interpolates between the material tokens b and c using an Uniform-B spline.

[Pure]
public static method MixUniformB (int64 a, int64 b, int64 c, int64 d, int32 f)
type int64
params a Zeroth control point.
  b First control point.
  c Second control point.
  d Third control point.
  f Interpolation factor, in the range [0..255].
returns The interpolated material token.

Range

Returns the material weight range for the given material token.

[Pure]
public static method Range (int64 token)
type int32
params token The material token.
returns The material weight ranges.

Remarks:

A material weight range is a 30-bit integer value, having the following layout:

32      24      16       8       0
 v.......v.......v.......v.......v
  10cccccccccc10bbbbbbbb10aaaaaaaa

a  = minimum weight, in the range [0..255]
b  = maximum weight, in the range [0..255]
c  = maximum weight sum, in the range [0..1020]
10 = guard bits

See also:

RangeMin
RangeMax
RangeSum

RangeMax

Returns the maximum weight of all materials.

[Pure]
public static method RangeMax (int32 weights)
type int32
params weights The weight range.
returns [0..255] The maximum weight.

See also:

Range

RangeMerge

Merges the given weight ranges.

[Pure]
public static method RangeMerge (int32 a, int32 b)
type int32
params a First weight range.
  b Second weight range.
returns The merged weight range.

See also:

Range

RangeMin

Returns the minimum weight of all present materials.

[Pure]
public static method RangeMin (int32 weights)
type int32
params weights The weight range.
returns [0..255] The minimum weight. Will be 0 iff there are no materials present at all.

See also:

Range

RangeSum

Returns the maximum weight sum of all material tokens.

[Pure]
public static method RangeSum (int32 weights)
type int32
params weights The weight range.
returns [0..1020] The maximum weight sum.

WeightAt

Returns a material weight of the given token.

[Pure]
public static method WeightAt (int64 token, int32 n)
type int32
params token The material token.
  n The material index, in the range [0..3].
returns [0..255] The material weight.

WeightFor

Converts the given material token to a weight for the given material.

[Pure]
public static method WeightFor (int64 token, int32 materialId)
type int32
params token The material vector.
  materialId ID of material which weight to return.
returns [0..255] The material weight.

WeightFromBlendFactor

Computes independent blend weights from the given blend factors.

[Pure]
public static method WeightFromBlendFactor (float32 f0, float32 f1, float32 f2)
type Vec3F
params f0 First dependent blend factor.
  f1 Second dependent blend factor.
  f2 Third dependent blend factor.
returns The independent blend weights.

Remarks:

Given the following blend function:

Blend(v0, v1, f) := v0 * (1 - f) + v1 * f
This method computes the independent blend weights X, Y and Z, so that the following holds true:
Blend(Blend(Blend(a, b, f0), c, f1), d, f2)
=
a * (1 - X - Y - Z) + b * X + c * Y + d * Z

See also:

WeightToBlendFactor

WeightSum

Returns the material weight sum of the given token.

[Pure]
public static method WeightSum (int64 token)
type int32
params token The material token.
returns [0..1020] The material weight sum.

Remarks:

A weight sum greater than 255 means that the material is overly saturated.

WeightToBlendFactor

Computes dependent blend factors from the given blend weights.

[Pure]
public static method WeightToBlendFactor (float32 wb, float32 wc, float32 wd)
type Vec3F
params wb Second independent blend weight.
  wc Third independent blend weight.
  wd Fourth independent blend weight.
returns The dependent blend factors.

Remarks:

Given the following blend function:

Blend(v0, v1, f) := v0 * (1 - f) + v1 * f
This method computes the dependent blend factors X, Y and Z, so that the following holds true:
Blend(Blend(Blend(a, b, X), c, Y), d, Z)
=
a * wa + b * wb + c * wc + d * wd
where wa is defined as 1 - wb - wc - wd.

See also:

WeightFromBlendFactor