Renderer · function
reflectDirection
Mirror a direction about a normal.
Explained in Hello world.
function reflectDirection(direction: ReadonlyVec3, normal: ReadonlyVec3, out: Float32Array): Float32Arrayimport { reflectDirection } from '@driftengine/core';Parameters
| Parameter | Type | Description |
|---|---|---|
direction | ReadonlyVec3 | |
normal | ReadonlyVec3 | |
out | Float32Array |
In depth
d - 2 (d . n) n, with n normalised first because an interpolated normal is rarely unit — and
a normal of length 1.01 mirrors to a direction that is not unit either, which a march then takes
as a step length.
A direction already leaving the surface is mirrored back into it, and that is not special-cased into something else. A caller that hands over a view vector pointing away from the surface has a bug one level up, and answering plausibly would hide it.