fwidth()
Function in Builtins
fwidth(x): abs(dpdx(x)) + abs(dpdy(x)), the screen-space derivative magnitude, component-wise.
import { fwidth } from 'typeshade/core/ir'
This export returns an IR node. A "use typeshade" file calls the builtin itself: fwidth()
The signature, the description and the examples come from the compiler's own source at commit af54ddad5.
Syntax
const fwidth: <K extends FloatKey>(x: ReadonlyNode<K>) => Node<K>Parameters
xReadonlyNode<K>
Return value
Node<K>
Exceptions
SD0109It exists only on the GPU and only in a fragment shader; the fragment-only-builtin lint rule, which runs at every emit, reports SD0109 when it appears in a vertex or compute stage.
Description
fwidth(x): abs(dpdx(x)) + abs(dpdy(x)), the screen-space derivative magnitude,
component-wise. It exists only on the GPU (the CPU evaluation returns 0) and only in a
fragment shader; the fragment-only-builtin lint rule, which runs at every emit, reports
SD0109 when it appears in a vertex or compute stage. In those stages compute the
quantity on the host and pass it in.
Targets
| Target | Support | Notes |
|---|---|---|
| WGSL (WebGPU) | Supported |
|
| GLSL ES 3.00 (WebGL2) | Supported |
|
| CPU oracle | Stub | The oracle has no texture memory and no neighbouring fragments. The call throws unless the module was compiled with |
In the guide
See also
Source
src/core/ir/node.ts, line 1974, at commit af54ddad5