Genesis imperfecta (or: I finally built the pencil)

This is not a scan of a pencil drawing. It’s SVG — computed, deterministic, and, in a sense I’ll get to, exact.

A sphere resting in a gravity well, the sheet's hatching flowing into the dent

For the past few months I’ve been building Krbn, a small open-source rendering engine that draws 3D scenes the way a technical sketch artist would. It’s a childhood idea. Back then I wanted to call it genesis imperfecta, because what fascinated me was — and still is — the idea of going against photorealism: that a human being conveys more meaning in a drawing than any photorealistic render, precisely by renouncing detail, dropping precision, deliberately introducing imperfections. The catch, of course, is the question hiding inside that sentence: which detail do you drop? Which imperfections do you introduce? That question turns out to be an engineering problem, and a lovely one.

The inversion

Most rendering answers “what color is this pixel?” A pencil drawing answers “which lines would an artist draw — and which would they leave out?” So Krbn has no shading model. It derives strokes from geometry and then applies policies to the stroke set:

  • Silhouettes of spheres, cylinders, cones are computed in closed form — they are exact conics; a torus yields its true quartic. No sampling, no meshes pretending to be curves.
  • Hidden lines aren’t z-buffered away; each contour is split analytically into visible and ghosted runs, the way a draftsman keeps the far edge of a box faintly alive.
  • There is no alpha channel. Cross-hatching is inherently see-through — the gaps between strokes reveal what’s behind, exactly like on paper. And the hatching follows each surface’s own curvature field, so form comes from direction, not gradients.
Two trefoil knots, one hatched along its curvature field, one hatched flat

Exactness was a deliberate value, not an optimization: intersections are roots of low-degree polynomials, and the degenerate cases — tangent lines, coincident conics, grazing cusps — are treated as the spec, not as edge cases. The reward is output you can trust: the same scene always emits the same, byte-identical, diffable SVG.

The part stills can’t show

Hand-drawn wobble is easy. Hand-drawn wobble that survives animation is not: re-randomize per frame and the whole drawing “boils.” In Krbn the wobble is seeded on stable stroke identity — each line carries its jitter with it across frames — so an orbiting camera slides the silhouettes while the lines stay calm:

A camera orbit of a mixed scene — the hand-drawn lines stay calm, no boiling

Getting to that calm — persistent stroke identity, hatch that pans with surfaces instead of re-dealing, detail that fades instead of popping — was the hardest part of the project, and my favorite.

The other experiment

I’ll say this plainly, because I put it in the README too: Krbn was built with heavy AI assistance, unapologetically. It doubled as an experiment — how far can a carefully directed human–AI collaboration get on a hard rendering problem? “Carefully directed” is the operative phrase: the architecture, the taste, and the standards are mine, written down and enforced (the working brief and the numerical-robustness rules ship in the repo — judge for yourself). The code was reviewed and tested like any other code. The answer to the experiment, as far as I’m concerned: far. Farther than I expected.

What’s next

Nothing on a schedule — this is a break-time project and I intend to keep it joyful. But the ideas corner is already growing (stippling as an alternate hatch strategy, colored pencils that stay stroke color and never become a fill model, deliberate temporal decoherence à la “Take on Me”), and the repo has an example gallery plus open Discussions.

If you make technical figures, drive a pen plotter, or just share the fascination — come say hello. Or don’t; all is good. The pencil exists now, and twelve-year-old me is satisfied.

Comments

Don't keep it to yourself!…