---
title: "gridSim"
description: "A field of cells advanced every frame by an ordered list of stages."
group: "simulation"
groupTitle: "Simulation"
categoryId: "sim.grids"
categorySlug: "sim-grids"
categoryTitle: "Grid programs"
kind: "function"
sourceUrl: "https://github.com/shader-effects-inc/shaders/blob/main/packages/core/src/std/sim/grids.ts#L126"
---

# gridSim

A field of cells advanced every frame by an ordered list of stages.

```ts
gridSim(build: (params: GpuFragmentParams, root: GridRoot) => GridSimConfig | null): {compute: GpuComputeNode}
```

Import `sim` from `shaders/std` and use `sim.grids.gridSim`.

Spread it into a definition next to a `gpu.fragment` that samples one of its outputs.

The build callback runs once per instance of the layer, with the GPU device, and returns the outputs, the frame-delta clamp and the stages. Return null to run nothing (a required child is missing). Without a GPU the fragment should fall back to the child or to transparent.

## Parameters

| Name | Type | Notes |
|---|---|---|
| `build` | `(params: GpuFragmentParams, root: GridRoot) => GridSimConfig \| null` |  |

## Example

```ts
...gridSim((params, root) => ({outputs: {state}, clampDt: 0.05, stages: [op.values('write', (f) => paramsU.write({dt: f.dt, radius: f.num('radius', 0.4)})), op.pass(update), op.publish(() => output)]}))
```

> **Tip.** Everything created in the build callback (buffers, passes, trackers) belongs to that layer instance. Create nothing at module scope that holds per-frame state.

## See also

- [`op`](/docs/primitives/sim-grids/op) — The stages a grid frame is built from.
- [`hostGridProgram`](/docs/primitives/sim-grids/hostgridprogram) — A frame program for a small grid stepped in plain JavaScript: the steps run in order every frame until one returns `'skip'`.
- [`simulate`](/docs/primitives/simulate/simulate) — Declare a simulation the engine runs for you.
- [`fluidSim`](/docs/primitives/sim-fluids/fluidsim) — A fluid the engine solves every frame.
- [`feedbackSim`](/docs/primitives/sim-feedback/feedbacksim) — A simulation that advances a picture of its own last frame by one step of your rule, every frame.

## Used by

[GridDistortion](/docs/components/griddistortion), [Liquify](/docs/components/liquify), [PixelSort](/docs/components/pixelsort), [ReactionDiffusion](/docs/components/reactiondiffusion)