Three Ways In · Layer 3 of 3 · Node.js 22+ · Zero Dependencies

Build With Your Coding Agent — 5 Rungs + Planted Traps

Build a physically grounded raytracer and Bounding Volume Hierarchy accelerator with your coding agent across five rungs: shadow-acne surface offsets, NaN-safe slab AABB tests, Surface Area Heuristic (SAH) binning, closest-hit front-to-back BVH traversal, and Fresnel total-internal-reflection glass transport. Each rung gives you an architect prompt for Claude Code, Codex, or Cursor, a planted bug that unguided agents write, and a deterministic test suite that catches it.

  1. Shadow-ray bias: Normal-oriented surface origin offset preventing self-shadowing acne — Planted trap: Offsetting along ray direction or failing to flip normal on back-facing hits.
  2. Slab AABB test: IEEE-754 reciprocal slab intersection handling axis-parallel rays on box faces — Planted trap: Producing 0 * Infinity = NaN when an axis-parallel ray lies directly on a slab plane.
  3. SAH BVH builder: Binned Surface Area Heuristic split with leaf-cost stopping rule and median fallback — Planted trap: Splitting degenerate equal-centroid clusters into an empty child and looping infinitely.
  4. Closest-hit traversal: Front-to-back child ordering tightening far = hit.t after each triangle hit — Planted trap: Returning the first leaf hit before testing an overlapping nearer sibling box.
  5. Dielectric glass BSDF: Snell refraction, Schlick Fresnel reflectance, and Total Internal Reflection — Planted trap: Taking Math.sqrt of a negative discriminant at steep internal angles instead of reflecting.
unzip agent-track.zip && cd raytracer-bvh-lab/agent-track
node --test test/*.test.mjs
mkdir -p src/mine && cp -n src/traps/rung-*.mjs src/mine/
RAY_IMPLEMENTATION=src/mine node --test test/rung-01.test.mjs

Download 5-Rung Agent Track (agent-track.zip) Read AGENT-TRACK.md on GitHub Open agent-track/README.md on GitHub

Earlier course edition and 3D tutor

Read the eight chapters · Explore the 3D tutor · Browse the earlier eight-chapter source on GitHub

git clone https://github.com/itsHabib/free-to-learn.git
cd free-to-learn
git switch --detach 7dba0d743224c10a707307769782b0db3f9a2a1a

Browse all courses · Give course feedback · Usage & privacy