scatterPoints

The scattered points of the four grid cells nearest the pixel, so anything drawn up to half a cell from its point shows whole, never clipped at a cell edge.

scatterPoints(coord: Expr, opts: ScatterOptions): ScatteredPoint[]

Import patterns from shaders/std and use patterns.scatterPoints.

Same options and same points as scatterPoint (one random point per cell); returns four of them instead of one. Draw something around each and add the results. Costs four times scatterPoint.

Parameters

NameTypeNotes
coordExpr
optsScatterOptions

Example

const glints = scatterPoints(px, {cellSize: 60, jitter: 0.6, seed: params.uniforms.seed})
    .map(({offset}) => starGlint(offset, {core: 0.9, rayLength: 0.1, rayWidth: 1.6, rays: 0.25, reach: 30}))

Tip. Pair with starGlint's reach set to half the cell size, so a glint has faded out before it could reach a cell this pixel doesn't look at.

See also

  • scatterPoint — One random point in each cell of a square grid: the classic scatter for glitter, stars, dust and sparkles.
  • starGlint — A four-point star of light: a round core with a thin ray along each axis, like a glint off glitter or a star in a photograph.

Used by

Sparkle