The MaterialToken class implements the concept of material tokens for terrain rendering.
static class
|
MaterialToken
|
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 materialThe individual material weights are unrelated. It is up to the application to properly interpret the weights.
The configurator object for this type.
public
static
property
|
Config
{
get
}
|
||
type
|
IConfigurator<int64>
|
||
value
|
|
The configurator object. |
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
|
|
The number of materials. |
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
|
|
The relative distance between the material tokens. |
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
.
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.MaterialMaskReturns 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
|
|
The material ID. |
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. |
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. |
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. |
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:
RangeMinReturns the maximum weight of all materials.
[Pure]
|
||||
public
static
method
|
RangeMax
(int32 weights)
|
|||
type
|
int32
|
|||
params
|
weights
|
The weight range. | ||
returns
|
|
The maximum weight. |
See also:
RangeMerges 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:
RangeReturns the minimum weight of all present materials.
[Pure]
|
||||
public
static
method
|
RangeMin
(int32 weights)
|
|||
type
|
int32
|
|||
params
|
weights
|
The weight range. | ||
returns
|
|
The
minimum
weight.
Will
be
0
iff
there
are
no
materials
present
at
all.
|
See also:
RangeReturns the maximum weight sum of all material tokens.
[Pure]
|
||||
public
static
method
|
RangeSum
(int32 weights)
|
|||
type
|
int32
|
|||
params
|
weights
|
The weight range. | ||
returns
|
|
The maximum weight sum. |
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
|
|
The material weight. |
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
|
|
The material weight. |
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 * fThis 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:
WeightToBlendFactorReturns the material weight sum of the given token.
[Pure]
|
||||
public
static
method
|
WeightSum
(int64 token)
|
|||
type
|
int32
|
|||
params
|
token
|
The material token. | ||
returns
|
|
The material weight sum. |
Remarks:
A
weight
sum
greater
than
255
means
that
the
material
is
overly
saturated.
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 * fThis 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 * wdwhere
wa
is
defined
as
1
-
wb
-
wc
-
wd
.
See also:
WeightFromBlendFactor