select

ifTrue when the condition holds, otherwise ifFalse.

select(cond: Expr, ifTrue: Val, ifFalse: Val): Expr

Import math from shaders/std and use math.select.

Both values are computed at every pixel, so this picks rather than skips work. For a soft transition use mix or smoothstep instead.

Parameters

NameTypeNotes
condExpr
ifTrueVal
ifFalseVal

Example

const rgb = select(lt(dist, radius), params.uniforms.fill.member('rgb'), params.uniforms.background.member('rgb'))

See also

  • lt — True when a is less than b.
  • gt — True when a is greater than b.
  • mix — A blend from a to b by t, where 0 gives a and 1 gives b.

Used by

CarbonFiber, Crystal, ReactionDiffusion