fwidth
Function
The screen-space width is the sum of absolute horizontal and vertical derivatives. It estimates how much a value varies across a pixel.
Compare examples
Compare a flat field, a horizontal ramp, and a diagonal ramp. Both directions contribute positively.
Model assumptionsf(px, py) = a × px + b × py + c
Example 1a = 0; b = 0; c = 5
5555 - Result
0
Example 2a = 0.25; b = 0; c = 0
00.2500.25 - Result
0.25
Example 3a = 0.25; b = -0.5; c = 1
11.250.50.75 - Result
0.75
The examples are calculation models and do not run GPU work. The reference below gives the complete call signatures. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.
When to use it
Use it to soften a procedural edge by approximately one pixel.
Inputs and limits
The example uses affine fields. It is a pixel footprint estimate, not a gradient length or a CPU derivative. This operation belongs in fragment-stage uniform control flow.
For shader input rules and precision, consult WGSL and GLSL ES 3.00.
Related functions
- WGSL
fwidth(a)- GLSL ES 3.00
fwidth(a)
The signature, the sentence and any message are the compiler's own text at commit af54ddad5.
Returns the sum of the absolute screen-space derivatives of x in both directions, abs(dpdx(x)) + abs(dpdy(x)), componentwise over vectors.
Syntax
declare function fwidth(a0: f32): f32declare function fwidth<V extends vec2 | vec3 | vec4>(a0: V): Vdeclare function fwidth<T extends Numeric>(a0: T): TA signature may name a type the ambient file declares for its own use. These are those declarations.
Numerictype Numeric = number | vec2 | vec3 | vec4 | vec2i | vec3i | vec4i | vec2u | vec3u | vec4u
Parameters
A parameter named by position (a0, a1) carries a name the ambient file generates. A call passes its arguments in order and names none of them.
-
a0f32VT
Return value
f32VT
Description
Fragment stage only; the CPU oracle returns zero.
Targets
- WGSL
-
fwidth(a) - GLSL ES 3.00
-
fwidth(a)