layered
Builds N variations of one thing from a data list and sums them with weights.
layered<T>(
layerData: readonly T[],
build: (layer: T, index: number) =,
> {value: Expr; weight: Expr}): {weightedSum: Expr; totalWeight: Expr}
Import compose from shaders/std and use compose.layered.
Give it a list of plain data and a function that turns one entry into {value, weight}. You get weightedSum and totalWeight back and choose the blend yourself, usually weightedSum / (totalWeight + 0.001). Slice the list to change how many layers are built.
Parameters
| Name | Type | Notes |
|---|---|---|
layerData | readonly T[] | |
build | (layer: T, index: number) => {value: Expr; weight: Expr} |
Example
const {weightedSum, totalWeight} = layered(CURTAINS.slice(0, count), ({offset, weight}) => ({value: curtain(offset), weight: math.mul(alpha, weight)}))
Tip. Cheap depth: aurora curtains, cloud banks, echo trails are all a few layers of one recipe.
See also
layers— Stacks colors into one, first entry at the back.