fwidth()
Function in Builtins
fwidth(x): abs(dpdx(x)) + abs(dpdy(x)), the screen-space derivative magnitude, component-wise.
import { fwidth } from 'typeshade'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
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
Source
src/core/ir/node.ts, line 2238, at commit 26de7be8