MaterialToken
Description
The MaterialToken class implements the concept of material tokens for terrain rendering.
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.
Public / Methods
For
2 overloads
Creates a material token.
Creates a material token.
If the material IDs m0 in, m1 in, m2 in and m3 in are not distinct, the weights will be summed and clamped at 255
.
Mask
Returns the bitmask for the given material token.
A material ID n
is mapped to the bit 2^n
.
- See also
Range
Returns the material weight range for the given material token.
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
WeightFromBlendFactor
Computes independent blend weights from the given blend factors.
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
WeightSum
Returns the material weight sum of the given token.
A weight sum greater than 255
means that the material is overly saturated.
WeightToBlendFactor
Computes dependent blend factors from the given blend weights.
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