---
title: "layered"
description: "Builds N variations of one thing from a data list and sums them with weights."
group: "paint"
groupTitle: "Painting"
categoryId: "compose"
categorySlug: "compose"
categoryTitle: "Layering & output"
kind: "function"
sourceUrl: "https://github.com/shader-effects-inc/shaders/blob/main/packages/core/src/std/paint/compose.ts#L53"
---

# layered

Builds N variations of one thing from a data list and sums them with weights.

```ts
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

```ts
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`](/docs/primitives/compose/layers) — Stacks colors into one, first entry at the back.

## Used by

[Aurora](/docs/components/aurora)