The dozen operations that carry the whole job. No proofs, no Greek - each one gets its formula, its plain-English meaning, and the production situations where it earns its keep.
dot(A,B) = Ax - Bx + Ay - By + Az - Bz |
| With unit vectors: result = cos(angle). 1 same direction - 0 perpendicular - -1 opposite. |
| Use | Recipe |
|---|---|
| Is it in front of me? | dot(fwd, toTarget) > 0 |
| Diffuse lighting | saturate(dot(N, L)) |
| Fresnel / rim mask | 1 - dot(N, V) |
| Slope mask (flat ground) | dot(N, up) > 0.7 ~= <45 deg |
cross(A,B) -> vector perpendicular to both - length = area of the parallelogram |
Order matters: cross(A,B) = -cross(B,A). Flips with handedness - see units & axes. |
| Use | Recipe |
|---|---|
| Face normal from 2 edges | normalize(cross(e1, e2)) |
| Build look-at basis | right = cross(up, fwd) |
| Left-or-right of a line? | sign of cross(lineDir, toPoint).z |
lerp(a,b,t) = a + (b-a) - t - where's t% between a and b |
invLerp(a,b,v) = (v-a)/(b-a) - v is what % between a and b |
| Use | Recipe |
|---|---|
| Any blend / fade / mix | lerp(colorA, colorB, mask) |
| Distance -> 0-1 fade | saturate(invLerp(near, far, d)) |
| Frame-rate-ish damping | pos = lerp(pos, target, 0.1) (per tick) |
remap(v, inA,inB, outA,outB) = lerp(outA, outB, invLerp(inA, inB, v)) |
= Houdini fit() - UE "Remap Value Range" - the function half your graphs secretly are. |
| Use | Recipe |
|---|---|
| Noise -1..1 -> 0..1 | remap(n, -1,1, 0,1) or n - 0.5+0.5 |
| Tri-count -> health score | remap(tris, 0,budget, 100,0) |
step(edge,x): 0 below, 1 at/above. Hard. |
smoothstep(e0,e1,x): 0 below e0, 1 above e1, ease-curve between. Soft - and TAA-friendly, unlike step. |
| Use | Recipe |
|---|---|
| Soft mask edge | smoothstep(0.45, 0.55, mask) |
| Dissolve frontier | smoothstep(p-w, p, noise) |
| Anti-shimmer contrast | replace step with narrow smoothstep |
length(V) = sqrtdot(V,V) - normalize(V) = V / length(V) |
| Rule: normalize before you trust a direction - non-uniform scale un-normalizes normals and dot() lies after that. |
Cheap trick: compare dot(V,V) against r^2 to skip the sqrt in distance checks. |
| You don't need the math - you need the rules: quats are 4 numbers representing orientation, no gimbal lock, always slerp between them (never lerp euler angles across 180 deg), multiply to combine (order matters), negate = same rotation. |
APIs that hand them to you: quaternion(axis, angle) (VEX) - Quaternion.LookRotation (Unity) - FQuat::FindBetween (UE). Use the API's from-to/look-at; hand-rolling is how ragdolls are born. |
pi ~= 3.14159 - tau = 2pi ~= 6.28319 (one full turn) |
degrees -> radians: - pi/180 (~= 0.01745) - radians -> degrees: - 57.2958 |
| cos/sin of common angles: 45 deg -> 0.707 - 30 deg -> cos .866 / sin .5 - 60 deg -> cos .5 / sin .866 |
| slope masks: dot(N,up) thresholds - 0.94~=20 deg - 0.87~=30 deg - 0.71~=45 deg - 0.5=60 deg |
luminance (Rec.709): 0.2126R + 0.7152G + 0.0722B |
Want these with more story? The HLSL page teaches the five shader functions through effects; the Python snippets carry the same family as copy-paste code; and the interview bank shows how dot/cross questions get asked and answered. Print tip: Ctrl+P - the site chrome disappears and the cards pack onto a page.