clothCoords

Where on the unfolded cloth a point lands: the material coordinates to draw a pattern in, so it follows the folds instead of floating over them.

clothCoords(
  coords: {along: Expr | number; across: Expr | number},
  folds: Fold[],
  opts: DrapeOptions & {foreshorten?: number},
): {along: Expr; across: Expr}

Import noise from shaders/std and use noise.clothCoords.

Takes the same coords, folds and options as drapedFolds. The cloth riding each ridge moves sideways with its spine, and each flank uses up cloth, so a pattern drawn in these coordinates bends with the ripples and bunches on the steep sides of every ridge. foreshorten (default 0.25) is how much cloth a flank consumes. Rebuild a point from the result with the drape's frame and hand it to a grain word in place of the screen point.

Parameters

NameTypeNotes
coords{along: Expr | number; across: Expr | number}
foldsFold[]
optsDrapeOptions & {foreshorten?: number}

Example

const m = clothCoords(drape.coordsOf(q), folds, {...drapeOpts, foreshorten: 0.25})
const onCloth = add(mul(drape.tangent, m.along), mul(drape.perp, m.across))
const threads = grainNoise(fibre.coordsOf(onCloth), {freq: [12, 420]})

Tip. One more pass over the folds per pixel. Call it once and reuse the point.

See also

  • drapedFolds — The height of a draped cloth at a point: rounded ridges running along one direction, each rippling and swaying along its length, gathered where the cloth is pinned.
  • foldSet — Lays out the ridges of a draped cloth: count folds spread evenly across spread, each nudged sideways, widened and raised by a seeded amount so no two are alike.
  • grainNoise — One octave of smooth signed noise along and across a direction, for grain.

Used by

Satin