uniformOf

The live GPU value of a prop, for a hand-written builder: uniformOf(p('radius'), params).

uniformOf(ref: PropRef, params: {uniforms: Record<string, Expr>}): Expr

Import uniformOf from shaders/std.

Colors come back as vec4f in linear RGB with alpha, positions as vec2f, numbers as f32. Read a part with .member('rgb') or .member('x'). Throws when the name is not one of the definition's props.

Parameters

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

Example

paint: (params) => {
  const color = uniformOf(p('color'), params)
  const gain = mul(uniformOf(p('intensity'), params), 0.5)
  return vec4(mul(color.member('rgb'), gain), color.member('a'))
}

Tip. A position prop's y is stored flipped: use sub(1, center.member('y')) to compare it with uv.

See also

  • p — Reference one of the definition's props by name, wherever a word asks for a value.
  • resolveScalar — A Scalar or prop ref as a GPU value, for a hand-written builder.
  • resolveArg — Any input value a word accepts (a prop ref, a Scalar, a context token, a number) as a GPU value inside a filter's builder.
  • paintFrame — The coordinate and frame size a hand-written paint: builder should draw in.

Used by

Aurora, Blob, FlowingGradient, GlassTiles, Marble, MeshGradient, Prism, StudioBackground, Waveform