voronoiRegionField

Splits the canvas into shards around random sites and records, per pixel, its shard and the next-nearest one.

voronoiRegionField(opts: {
    count: number
    size: number
    sites: (seed: number) => Float32Array
    seedProp: string
    seedDefault: number
    output: string
}): GpuComputeNode

Import effects from shaders/std and use effects.fracture.voronoiRegionField.

A compute hook for the compute: field. count is the number of shards, size the field's resolution in pixels, sites(seed) your function returning the shard positions as [x, y, x, y, …] in uv, and seedProp the prop that re-rolls them. The field only recomputes when the seed changes. In the fragment, sample computeOutputs[output] with 'nearestClamp': .r is the nearest shard's index, .g the second-nearest.

Parameters

NameTypeNotes
opts`{
count: number
size: number
sites: (seed: number) => Float32Array
seedProp: string
seedDefault: number
output: string

}` | |

Example

compute: voronoiRegionField({count: 16, size: 1024, sites: shardSites, seedProp: 'seed', seedDefault: 2, output: 'voronoiField'})

Tip. Fill your shard data texture from the same sites function, or the cracks drift off their shards.

See also

  • cellLaneUVFor — Where one shard's value sits in a one-row data texture.
  • crackGeom — How much crack there is at a pixel, and which way the shard under it has moved.

Used by

Shatter