dpdx

How much a value changes from this pixel to the next one to the right.

dpdx(x: Val): Expr

Import math from shaders/std and use math.dpdx.

Works on numbers and vectors. Use it to measure how fast something moves across the screen: a refracted lookup, a reflected direction, a field. Read it before any guarded branch. Derivatives exist only in a pixel body (paint, effect, surface): a compute input cannot use them.

Parameters

NameTypeNotes
xVal

Example

const stepX = local(dpdx(lookupUV), 'stepX')

Tip. Derivatives are only legal outside per-pixel branches: wrap the result in local() before the guard and pass that local to guarded as a dep.

See also

  • dpdy — How much a value changes from this pixel to the next one down.
  • fwidth — How much a value changes across one pixel, in any direction: |dpdx| + |dpdy|.