If you've ever tried to build a rich, motion-heavy web interface, you've probably felt stuck between component convenience and animation freedom.
On one side, you have the HTML DOM and React. Composing reusable UI components feels great — right up until you push animations and custom visuals past what browser layout boxes were meant to handle:
- Animating or scrolling through 10,000 interactive rows or thousands of 2D cards without DOM bloat or layout jank.
- Painting a multi-color gradient inside selected text (which CSS
::selectionsimply doesn't allow). - Keeping text highlighted across multiple input boxes at once and copying all of them together (
window.getSelection()only allows one selection per page). - Driving physics-based UI motion, shooting unclipped particle fireworks straight out of a live typing cursor, or curling five 3D book pages in mid-air at the same time.
On the other side, you have raw <canvas> and WebGL. You get total pixel and animation freedom, but you lose UI ergonomics. There are no buttons, no scrollbars, no native text inputs — and if a single element animates or changes color, a naive render loop wipes and redraws the entire screen 60 times a second, chewing through laptop batteries even when the UI is sitting completely still.
So I started wondering:
What if we had a tiny, React-inspired engine built specifically for animated WebGL UIs — where every component lives on its own cached GPU layer, and motion never forces pixels to be redrawn?
That experiment turned into RePaint — a lightweight (~530 lines of core code) declarative WebGL UI & animation engine for .NET & WebAssembly. I'm open-sourcing it today under the MIT License, and you can play with the live demo here.
The Core Idea: Built for Animated WebGL UIs
At its heart, RePaint is designed around one principle that makes high-FPS UI animations effortless: decoupling painting from moving.
Instead of thousands of nested <div> tags — or one flat canvas you have to repaint every frame — RePaint treats your entire UI as a tree of transparent, GPU-cached component layers ("GPU stickers"):
Here is how the 3-stage pipeline turns declarative UI code into 60–120 FPS WebGL animations:
-
Declarative Component Tree (Paint Only When Dirty): Just like React, you describe your UI out of composable components. Each component renders its vectors, text, and shadows onto its own off-screen
SKSurfacetexture only when its state actually changes (Invalidate()). -
GPU Texture Cache (0.00 ms Static Reuse): Clean components (
IsDirty = false) aren't repainted at all — their pixels stay cached on the GPU ready to be stamped in0.00 ms. -
WebGL Compositor (Zero-Repaint Animation Layer): This is where motion lives. Transitions, spring physics,
Translate,Scale,Rotation,Opacity, andZIndexreordering all run directly on the GPU compositor at 60–120 FPS with zero pixel repaints. The moment an animation settles, the engine stops requesting frames and drops back to 0% CPU/GPU idle.
In code, building a component still feels clean and familiar. Inside OnPaint, a component draws itself and composes its child components in one pass:
protected override void OnPaint(PaintEvent e)
{
// Draw this card's background once into its cached GPU layer
Theme.DrawCard(e.Canvas, box, radius: 13f, SKColors.White, Theme.Border);
// Compose child components declaratively — each gets its own GPU layer
e.Render<TextBlock>(ref titleId, new Rectangle(14, 130, Width - 28, 24),
tb => tb.Text = Title);
e.Render<ActionButton>(ref btnId, new Rectangle(Width - 96, 184, 82, 28),
btn => btn.Text = "Details ›");
}
Because every component already sits on its own GPU texture with independent transform properties, animating complex WebGL interfaces stops feeling like writing a game engine and starts feeling like regular UI development.
5 Fun Things This Architecture Unlocks
1. Silky 60–120 FPS Motion — And True 0% CPU When Idle
Most WebGL UIs run an endless requestAnimationFrame loop, keeping your fans spinning even while you're just reading static text.
In RePaint:
- Hovering one button on a screen with 50 other components redraws only that 1 button. The other 49 just stamp their cached GPU textures onto the canvas in
0.00 ms. - Animations wake up the render loop smoothly on demand and schedule zero frames the instant motion settles — dropping CPU and GPU usage to a real 0% until your next click or keypress.
2. Spin, Bounce, or Pop Entire Live Forms 360° for Free
In HTML, animating a heavy container packed with crisp text, shadows, and interactive inputs often causes blurry rasterization or expensive layout reflows.
Because every RePaint component (a card, modal dialog, or full multi-field form) is already a GPU texture, animating an entire live form with 360° rotation and spring physics costs the exact same as moving a tiny icon: zero text or vector shapes are redrawn during the entire animation.
3. Massive Lists & 2D Grids with a Spatial QuadTree
To smoothly pan and animate across 10,000 log rows or 2,400 rich graphic cards without being limited to 1D vertical lists, I built a small 2D Spatial QuadTree into the engine (the same spatial culling trick used in strategy games). Wherever you scroll on a 2D canvas, the QuadTree grabs only the ~15–20 visible items, composites their GPU layers, and automatically frees GPU memory for anything off-screen.
4. Interactive WebGL Text Inputs Without Browser Handcuffs
Standard <input> and <textarea> elements are notoriously hard to animate or style beyond basic CSS. RePaint renders inputs 100% on WebGL while quietly syncing with an invisible browser input behind the scenes — so Vietnamese accents, Japanese/Chinese IME, emojis, and mobile keyboards still work natively, while letting me build visual effects HTML can't touch:
-
Aurora Gradient
::selection: Paints a 4-color gradient behind selected text, cleanly splitting letters half-dark and half-white even when the selection ends mid-character. -
Multi-Input
Copy All Selected: Highlight phrases across multiple inputs at the same time, then right-clickCopy All Selectedto grab every highlighted snippet in one go. - Unclipped Caret Fireworks: Every keystroke launches animated neon sparks and comet trails right out of your typing cursor — flying freely outside the input borders across the entire form.
5. A 3D Wave Flipbook Where Pages Chase Each Other Mid-Air
Try clicking "Next Page" five times fast in most web flipbooks — they usually lock up until the first page finishes turning.
Since RePaint treats each sheet of paper as its own animated component with a separate GPU layer and dynamic Z-ordering, rapid-clicking a corner sends 3, 4, or 5 curved pages flying through the air simultaneously in a continuous 3D wave, just like fanning a real book with your thumb.
Small, Hackable, and 100% Static
Even with retained GPU layers, composited animations, IME text inputs, and a 2D QuadTree, I kept the codebase small enough to read over a cup of coffee:
| Layer | What Lives Inside | Size |
|---|---|---|
Engine/ |
Component tree, GPU layer cache, WebGL compositor, 2D QuadTree & animation loop | ~530 LOC |
Controls/ |
QuadTree panel, Aurora IME inputs, modal popup, context menu, buttons | 8 files |
Demos/ |
10K Virtual List, 2.4K Spatial Grid, Firework Studio & 3D Wave Flipbook | 4 showcases |
During development, dotnet watch Hot Reload updates your WebGL UI and animations on Ctrl + S in ~1 second. When you're ready to ship, dotnet publish -c Release compiles everything into 100% static WebAssembly files — no backend server needed, easy to host for free on GitHub Pages or Cloudflare Pages.
- ⭐ GitHub Repo (MIT): github.com/neperisearch/repaint
- 🚀 Live Demo: neperisearch.github.io/repaint/
I'd genuinely love to hear your thoughts, feedback, or edge cases that break it.


Top comments (0)