Squared-length floor below which an interpolated stored normal is not trusted.
Compared against dot(N, N), so this is (1e-6)² — a normal shorter than one
part per million of unit length. Two sources produce them: a legitimately
degenerate triangle (the writer warns rather than rejecting zero-length normals,
spec §3.5), and interpolation across a triangle whose corner normals oppose, which
cancels to ~0 somewhere in between.
Lives HERE rather than once per shader file, and that placement is the point: the
GLSL side needs it as a source string and the TSL side as a JS number, so the
obvious arrangement is two constants — which is a value that can silently drift in
two directions, with the two backends then switching to the derivative fallback on
different fragments. One number, interpolated into the GLSL and passed to TSL
directly, makes that unrepresentable rather than merely tested for.
String(1e-12) is "1e-12", a valid GLSL ES 3.0 floating constant (the exponent
form needs no decimal point), so the interpolation needs no formatting helper.
Squared-length floor below which an interpolated stored normal is not trusted.
Compared against
dot(N, N), so this is(1e-6)²— a normal shorter than one part per million of unit length. Two sources produce them: a legitimately degenerate triangle (the writer warns rather than rejecting zero-length normals, spec §3.5), and interpolation across a triangle whose corner normals oppose, which cancels to ~0 somewhere in between.Lives HERE rather than once per shader file, and that placement is the point: the GLSL side needs it as a source string and the TSL side as a JS number, so the obvious arrangement is two constants — which is a value that can silently drift in two directions, with the two backends then switching to the derivative fallback on different fragments. One number, interpolated into the GLSL and passed to TSL directly, makes that unrepresentable rather than merely tested for.
String(1e-12)is"1e-12", a valid GLSL ES 3.0 floating constant (the exponent form needs no decimal point), so the interpolation needs no formatting helper.