Reference transformNormal()

transformNormal()

This API is experimental

Its behavior may change in a future version of p5.js.

Applies a p5.strands transform to a surface direction.

A normal describes which way a surface faces, and lighting uses it to work out how bright each spot should be. Normals can't be moved the way positions are: a move must be ignored, and an uneven resize like scale(t, 2, 1, 1) would tilt them the wrong way if the transform were applied directly. transformNormal() handles both cases and returns a normalized result, so lighting stays correct.

Pass the same transform used with transformPoint() for the position, so the shape and its lighting stay in step.

Note: transformNormal() can only be used inside a p5.strands shader callback.

Examples

Syntax

transformNormal(transform, normal)

Parameters

transform
a transform created with transform2D() or transform3D().
normal
the surface direction to transform.

Returns

the transformed surface direction, normalized.

Related References