GLSL built-in function

dFdx()

Estimates the rate of change across screen-space fragment x.

Demo version: GLSL ES 1.00 / WebGL 1Demo stage: Fragment

Syntax

genType dFdx(genType p)

genType means float / vec2 / vec3 / vec4; matching placeholders use the same type.

Parameters

p
Packed unsigned integer

Return value

An approximate screen-space x derivative for each component of p, with the same type as p.

Live example

Edit the code and the preview updates as you type.

What dFdx does

Estimates the rate of change across screen-space fragment x.

Read the preview

abs(dFdx(sin(x*24.0))) produces vertical bands because neighboring columns see different sine values. Change both 24.0 constants to 12.0 to halve the band frequency while retaining the amplitude scale.

Core call

abs(dFdx(sin(x*24.0)))*u_resolution.x/24.0;

Fragment stage only; derivatives in non-uniform control flow are undefined.

Experiment

Replace sin(x*24.0) with sin(y*24.0) inside dFdx. The input then varies vertically rather than horizontally, so its x derivative is approximately zero.

Specification

GLSL ES 1.00 built-in functions, chapter 8

Related functions