listOf

Read a list prop inside a hand-written builder: its live item count and each item's fields.

listOf(params: {uniforms: Record<string, Expr>}, prop: string): ListRef

Import listOf from shaders/std.

listOf(params, 'lights') gives count and at(i), whose .position('position'), .color('color') and .number('intensity') read item i by field name. Throws when prop is not a list prop or a field name is not in its item spec. Loop with accumulate.

Parameters

NameTypeNotes
params{uniforms: Record<string, Expr>}
propstring

Example

const lights = listOf(params, 'lights')
const rgb = accumulate(lights, (i) => mul(lights.at(i).color('color').member('rgb'), lights.at(i).number('intensity')), {zero: 'vec3f'})

Tip. A position field's y is stored flipped; use sub(1, pos.member('y')) to compare it with uv.

See also

  • accumulate — Add up a per-item value over every item of a list, in a real GPU loop over the live count.

Used by

Irradiance