hostFieldTexture
The texture a JavaScript-stepped grid is read through.
hostFieldTexture(
params: GpuFragmentParams,
opts: {size: number; label: string},
): {texData: Uint16Array; texture: ReturnType<GpuFragmentParams['registerMediaTexture']>; upload(): void}
Import sim from shaders/std and use sim.grids.hostFieldTexture.
Pack the cells into texData (four half-floats per cell, row by row), call upload(), and sample texture in the fragment.
size is the grid's side in cells. The texture filters smoothly, so a coarse grid reads as a continuous field.
Parameters
| Name | Type | Notes |
|---|---|---|
params | GpuFragmentParams | |
opts | {size: number; label: string} |
Example
const field = hostFieldTexture(params, {size: 32, label: 'flow'})
Tip. Values go in as half-floats: convert each number with
toHalfFloatbefore writing it intotexData.
See also
hostGridProgram— A frame program for a small grid stepped in plain JavaScript: the steps run in order every frame until one returns'skip'.