webgl-components

Installation
SKILL.md

WebGL Components

Lessons for embedding shader-driven visuals (identity avatars, ambient orbs, animated textures) into product UI. The failure modes are predictable, and nearly all of them come from treating the widget like a demo instead of like a component that renders fifty times in a list.

Architecture: one context, many instances

Never create one WebGL context per component instance. Browsers cap a document at roughly 8 to 16 live contexts, then silently evict the oldest. A list of avatars hits that cap immediately.

  • Keep one module-level WebGL context rendering offscreen, and give each component instance a cheap 2D canvas. Each frame: draw into the shared GL canvas, then blit the region into the instance's 2D canvas with drawImage.
  • The GL drawing buffer is only valid until the browser composites, so draw and blit within the same task. Never across an await.
  • GL's origin is bottom-left and the 2D canvas' is top-left, so blit from canvas.height - size, not from 0.
  • Grow the shared canvas to fit the largest instance and never shrink it mid-session.
  • Group identical draws. Instances agreeing on every visual input (source, tint, size, pointer state) paint identical pixels, so draw once and blit that result to all of their canvases. A list of same-styled items then costs one draw per frame instead of one per row.

Frame loop discipline

Installs
92
Repository
flornkm/skills
GitHub Stars
110
First Seen
Aug 20, 2026
webgl-components — flornkm/skills