Divooka Reference

Heightmap Splatmaps

3 nodes

On this page 3

Calculate Material Id

Function

Gives each cell the index of its heaviest layer: a material ID map for engines and shaders that take one material per cell.

Signature
CalculateMaterialId -> Scalar Field
    weights: Scalar Field Array
    normalizeToUnitRange: Truth
ScalarField2D CalculateMaterialId(
    ScalarField2D[] weights,
    bool normalizeToUnitRange = false)

Parameters

nametypedefaultdescription
weightsScalar Field Array—Layer weights or masks, all the same size.
normalizeToUnitRangeTruthFalseFalse for the raw index (0, 1, 2, ...); true to divide by the last index so the map views as a 0..1 greyscale.

Returns

resultScalar Field
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Heightmap Splatmaps
Package
Procedural Generation

Normalize Weights

Function

Converts material masks into layer weights that sum to 1 at every cell.

Signature
NormalizeWeights -> Scalar Field Array
    masks: Scalar Field Array
    layered: Truth
    includeBaseLayer: Truth
    contrast: Number
ScalarField2D[] NormalizeWeights(
    ScalarField2D[] masks,
    bool layered = true,
    bool includeBaseLayer = true,
    double contrast = 1)

Parameters

nametypedefaultdescription
masksScalar Field Array—Material masks in 0..1, bottom layer first, all the same size.
layeredTruthTrueTrue to stack masks in order, false to share overlaps proportionally.
includeBaseLayerTruthTrueTrue to add a remainder layer at index 0 of the output.
contrastNumber1Exponent applied to every mask first; above 1 sharpens transitions between layers, below 1 widens them.

Returns

resultScalar Field Array

Remarks

Masks are given bottom first: each later mask is a layer above the earlier ones. Layered, a layer covers the layers below it by its own weight, the way paint layers stack (a cell with rock 0.8 over grass 1 is 80 % rock, 20 % grass). Not layered, overlapping masks share the cell in proportion to their values. With a base layer, whatever no mask claims goes to an extra layer placed first in the output; without one, the bottom mask takes it (layered) or the masks are scaled up to fill the cell (not layered, split equally where every mask is 0).

Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Heightmap Splatmaps
Package
Procedural Generation

Pack Weights

Function

Packs layer weights four to an image, in the red, green, blue and alpha channels, the layout terrain engines read splatmaps in.

Signature
PackWeights(weights: Scalar Field Array) -> Pixel Image Array
PixelImage[] PackWeights(ScalarField2D[] weights)

Parameters

nametypedefaultdescription
weightsScalar Field Array—Layer weights, normally from HeightmapSplatmaps.NormalizeWeights.

Returns

resultPixel Image Array

Remarks

Layer i goes to image i / 4, channel i % 4 (R, G, B, A); unused channels of the last image are 0. Bytes are rounded so that, where the weights sum to 1, the channels of all the images together sum to exactly 255 (largest-remainder rounding), so no cell loses or gains coverage to rounding.

Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Heightmap Splatmaps
Package
Procedural Generation