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
| Name | Type | Notes |
|---|---|---|
x | Val |
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 toguardedas a dep.