fdSlope

The value and slope of any field at a point: value, dx and dy.

fdSlope(sampleAt: (p: Expr) => Expr, p: Expr, eps: number, hint: string = 'fd'): {value: Expr; dx: Expr; dy: Expr}

Import materials from shaders/std and use materials.fdSlope.

sampleAt is the field as a function of a 2D point, eps the tap distance in that point's units (a few thousandths in uv). The bridge from a height field to a normal: feed dx and dy to nudgeNormal.

Parameters

NameTypeNotes
sampleAt(p: Expr) => Expr
pExpr
epsnumber
hintstringOptional. Default 'fd'.

Example

const relief = fdSlope((at) => heightField(params, at), uv, 0.0035)

Tip. Three taps of the field per pixel. Keep the field cheap or share it.

See also

  • nudgeNormal — Tilts a normal by a slope in x and y, turning a height field into relief.
  • perlinSlope — The slope of smooth noise at a point, for wavy or molten relief.
  • cellNoiseAt — Cellular noise at a 2D point: 0 at each cell's seed point, rising toward the cell walls.

Used by

Crystal