fwidth

How much a value changes across one pixel, in any direction: |dpdx| + |dpdy|.

fwidth(x: Val): Expr

Import math from shaders/std and use math.fwidth.

The pixel footprint of anything you compute: feather an edge by it, or spread samples over it. Like every derivative it exists only in a pixel body, never in a compute input.

Parameters

NameTypeNotes
xVal

Example

const aa = local(fwidth(sdf), 'aa')
const coverage = sub(1, smoothstep(neg(aa), aa, sdf))

Tip. Derivatives are only legal outside per-pixel branches: wrap the result in local() before the guard and pass that local to guarded as a dep.

See also

  • dpdx — How much a value changes from this pixel to the next one to the right.
  • dpdy — How much a value changes from this pixel to the next one down.