---
title: "Pointer fields"
description: "Push fields the pointer stirs."
group: "effects"
groupTitle: "Filters & effects"
categoryId: "effects.pointerFields"
categorySlug: "effects-pointerfields"
wordCount: 5
curated: true
sourceUrl: "https://github.com/shader-effects-inc/shaders/blob/main/packages/core/src/std/effects/pointerFields.ts"
editUrl: "https://github.com/shader-effects-inc/shaders/edit/main/packages/core/docs/std/effects.pointerFields.md"
---

# Pointer fields

Push fields the pointer stirs. Each word is a whole simulation: a grid of cells, each holding
how far the layer inside should shift there, that the cursor pushes and that settles back on
its own. Spread the word into a warp definition with `...sim.grids.gridSim(word)` and it
publishes the field under its `output` name; the warp's `map:` then reads it with
`warps.gridCellDisplace` (per cell, blocky) or `warps.liquidDisplace` (smoothly, scaled by an
intensity prop). The definition needs `usesPointer: true`.

[`pointerSplatField`](/docs/primitives/effects-pointerfields/pointersplatfield) smears pixels along the cursor and lets them fade back; its grid size is a
prop, so pair it with [`clampSplatGridSize`](/docs/primitives/effects-pointerfields/clampsplatgridsize) in a recompile rule. [`springLatticeField`](/docs/primitives/effects-pointerfields/springlatticefield) is a cloth
of springs on a fixed 64-cell grid that stretches, rings and settles like fabric. Both stop
computing once the field has settled, and both give a displacement in uv.

```ts
import {effects} from 'shaders/std'
```

## Reach for it when

| When you need | Use |
|---|---|
| a smear that follows the cursor and fades | [`pointerSplatField`](/docs/primitives/effects-pointerfields/pointersplatfield) |
| fabric or liquid that ripples after a push | [`springLatticeField`](/docs/primitives/effects-pointerfields/springlatticefield) |
| the grid-size prop's recompile rule | [`clampSplatGridSize`](/docs/primitives/effects-pointerfields/clampsplatgridsize) |
| the range that rule holds the grid to | [`SPLAT_MIN_GRID`](/docs/primitives/effects-pointerfields/splat-min-grid), [`SPLAT_MAX_GRID`](/docs/primitives/effects-pointerfields/splat-max-grid) |

## Example

```ts
import {defineShader, p, effects, sim, warps, recompileWhen, transformEdges} from 'shaders/std'

const {pointerSplatField, clampSplatGridSize} = effects.pointerFields

// Smear: the layer inside follows the cursor in coarse cells and eases back when it stops.
export const Smear = defineShader({
  name: 'Smear',
  usesPointer: true,
  props: {
    intensity: {default: 1},
    decay: {default: 3},
    radius: {default: 1},
    // Rebuild the simulation only when the cell count really changes, not on every slider step.
    gridSize: {default: 20, recompile: recompileWhen((prev, next) => clampSplatGridSize(prev as number) !== clampSplatGridSize(next as number))},
    edges: {default: 'stretch', transform: transformEdges, compileTime: true},
  },
  ...sim.grids.gridSim(pointerSplatField({
    gridSize: p('gridSize'), decay: p('decay'), intensity: p('intensity'), radius: p('radius'),
    output: 'displacement',
  })),
  map: warps.gridCellDisplace({gridSize: p('gridSize'), output: 'displacement'}),
  // Before the field exists (no GPU yet), the warp passes the layer through untouched.
  uvRemapIdentityWhen: ({computeOutputs}) => !computeOutputs?.displacement,
})
```

## Words

- [`pointerSplatField`](/docs/primitives/effects-pointerfields/pointersplatfield) — A field the cursor smears: cells near the pointer move with it, then fade back to rest.
- [`springLatticeField`](/docs/primitives/effects-pointerfields/springlatticefield) — A cloth of springs the cursor pushes: it stretches, rings and settles like fabric.
- [`clampSplatGridSize`](/docs/primitives/effects-pointerfields/clampsplatgridsize) — The grid size `pointerSplatField` really uses for a prop value: floored, then held to 8–128.
- [`SPLAT_MIN_GRID`](/docs/primitives/effects-pointerfields/splat-min-grid) — The smallest grid `pointerSplatField` runs on: 8 cells per side.
- [`SPLAT_MAX_GRID`](/docs/primitives/effects-pointerfields/splat-max-grid) — The largest grid `pointerSplatField` runs on: 128 cells per side.