import { Expr } from '../gpu/contract'; /** One item's fields at a loop index, read by field name and kind. */ export interface ListItemAt { /** A `position` field as `vec2f`, in the engine's stored form (y flipped: 1 − the authored y). */ position: (field: string) => Expr; /** A `color` field as `vec4f`, linear RGB with alpha. */ color: (field: string) => Expr; /** A `number` or `boolean` field as `f32` (true is 1, false is −1). */ number: (field: string) => Expr; } /** A list prop bound for reading: the live item count and each item's fields. */ export interface ListRef { /** How many items the list holds right now, as an `f32`. */ count: Expr; /** The fields of item `i`. */ at: (i: Expr) => ListItemAt; } /** * Read a list prop inside a hand-written builder: its live item count and each item's fields. * * `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`. * * @example * ```ts * 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 accumulate */ export declare function listOf(params: { uniforms: Record; }, prop: string): ListRef; /** * Add up a per-item value over every item of a list, in a real GPU loop over the live count. * * `body(i)` returns the value for item `i`. `zero` picks the sum's type: `'f32'` (default) or * `'vec3f'` for a color. Anything the body reads that was computed outside the loop (a * normal, a surface point) goes in `deps`, so it is emitted once before the loop instead of * inside it. `hint` names the sum in the generated code. * * @example * ```ts * const lights = listOf(params, 'lights') * const rgb = accumulate(lights, (i) => { * const light = lights.at(i) * const pos = light.position('position') * const d = length(sub(uv, vec2(pos.member('x'), sub(1, pos.member('y'))))) * return mul(light.color('color').member('rgb'), div(light.number('intensity'), add(1, mul(d, d)))) * }, {zero: 'vec3f', deps: [uv], hint: 'lightSum'}) * ``` * @see listOf */ export declare function accumulate(list: ListRef, body: (i: Expr) => Expr, opts?: { zero?: 'f32' | 'vec3f'; deps?: Expr[]; hint?: string; }): Expr; //# sourceMappingURL=lists.d.ts.map