fwidth
On this page

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

x ReadonlyNode<K>

Return value

Node<K>

Exceptions

SD0109

It 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

TargetSupportNotes
WGSL (WebGPU) Supported

fwidth(x).

GLSL ES 3.00 (WebGL2) Supported

fwidth(x).

CPU oracle Stub

The oracle has no texture memory and no neighbouring fragments. The call throws unless the module was compiled with { gpuStubs: true }, which returns a placeholder.

In the guide

See also

Source

src/core/ir/node.ts, line 1974, at commit af54ddad5

Edit this page Report a problem