Neperi Search
← All Engineering Articles
2026-12-03·6 min readOpen SourceWebGLUI ArchitectureWebAssembly

RePaint: What If React Rendered to GPU Layers Instead of the HTML DOM?

Why we built a tiny ~500-line React-inspired UI engine on WebGL — combining declarative components with total pixel freedom, zero-idle GPU caching, multi-input gradient highlights, and 3D wave physics.

By Neperi Systems Engineering ★ View Source on GitHub →

Every developer who builds rich interfaces eventually runs into an uncomfortable trade-off between convenience and visual freedom.

On one side, you have the HTML DOM and React. Building UIs out of reusable components feels wonderful — until you try to push past what browser layout boxes were designed to do:

  • Render 10,000 interactive rows or thousands of 2D cards without DOM bloat or layout lag.
  • Paint a multi-color gradient inside selected text (something CSS ::selection flat-out forbids).
  • Keep text highlighted across multiple input boxes at once and copy all of them together (window.getSelection() only allows one selection per page).
  • Shoot fireworks out of a live typing cursor without getting clipped by overflow: hidden, or curl five 3D book pages in mid-air at the same time like a real wave of paper.

On the other side, you have raw <canvas> and WebGL (like desktop GDI or game engines). You get 100% pixel freedom — you can draw anything you can imagine! But you lose components. On a raw canvas, there are no buttons, no scrollbars, no text selection, and worst of all: if a single button changes color, a naive canvas loop erases and redraws the entire screen 60 times per second, draining laptop batteries even when nothing is happening.

RePaint was born from a simple question:

What if we kept React's component mindset, gave every component its own cached GPU layer, and only repainted the exact piece that changed?

Today we are open-sourcing RePaint under the MIT License — a lightweight (~530 lines of core engine code) declarative WebGL UI engine for .NET & WebAssembly.

The Big Idea: Every Component Is a Cached "GPU Sticker"

Imagine your screen not as thousands of nested HTML <div> tags, and not as one flat painting you have to scrape clean every frame — but as a stack of transparent, reusable GPU stickers.

1. Declare Like React Components describe their own look and child components right inside OnPaint(). Zero HTML tags · Zero CSS 2. Cache as GPU Stickers Each component paints once onto its own GPU texture. Unchanged? Reuse instantly! 0.00 ms when clean 3. Sleep When Idle Move, scroll, or spin 360° on the GPU. When motion stops, rendering stops. 0% CPU / GPU at rest
RePaint combines React-style component composition with per-component GPU texture caching.

Here is how simple it feels in code. Inside OnPaint, a component draws itself and places its child components in one natural pass:

protected override void OnPaint(PaintEvent e)
{
    // Draw this card's background
    Theme.DrawCard(e.Canvas, box, radius: 13f, SKColors.White, Theme.Border);

    // Place child components just like React props — cached automatically!
    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 ›");
}

That single design unlocks five unique capabilities that feel almost magical in a web browser.

5 Things That Make RePaint Unique

1. Only Repaint What Changed — And Use 0% CPU When Idle

Most WebGL or game-engine UIs run an endless 60fps loop, heating up your laptop even while you are just reading static text.

In RePaint:

  • If you hover a single button on a screen with 50 other components, only that 1 button redraws. The other 49 components stamp their already-cached GPU textures onto the screen in 0.00 ms.
  • The moment animations finish settling, RePaint schedules zero frames — dropping CPU and GPU usage to a true 0% until your next interaction.

2. Spin, Bounce, or Pop Entire Live Forms 360° for Free

In HTML, rotating or scaling a complex container full of text, shadows, and inputs often triggers blurry rasterization or expensive repaints.

Because every RePaint component (a card, a modal popup, or an entire multi-field form) is already a GPU texture, spinning an entire live form 360° with spring physics costs the exact same as spinning a tiny icon: zero text or vector shapes are redrawn during the entire spin.

3. Massive Lists & 2D Grids: Draw Only What Fits Your Eyes

How do you display 10,000 log rows or 2,400 rich graphic cards smoothly?

Instead of only supporting simple 1D vertical lists, RePaint includes a tiny 2D Spatial QuadTree — the same spatial radar technique used in strategy games. Wherever you scroll on a 2D canvas, the QuadTree instantly finds only the ~15–20 items visible in your window, stamps their GPU layers, and automatically frees GPU memory for items that scrolled out of view.

4. Text Inputs Without Browser Handcuffs (Aurora Highlights, Copy All, & Fireworks!)

Standard <input> and <textarea> elements are notoriously rigid. RePaint draws its text inputs 100% on WebGL while quietly syncing with an invisible browser input in the background — meaning Vietnamese accents, Japanese/Chinese IME, emojis, and mobile keyboards still work natively, while unlocking effects HTML simply cannot do:

  • Aurora Gradient ::selection: CSS strictly forbids gradients on selected text. RePaint paints a vivid 4-color Aurora gradient pill behind your selection, cleanly splitting individual letters half-dark and half-white even if your cursor stops mid-character!
  • Multi-Input Copy All Selected: Normal web pages destroy your highlight in Box A the moment you select text in Box B. RePaint lets you highlight phrases across multiple inputs at the same time and right-click Copy All Selected to grab every highlighted snippet in one click (or click anywhere to clear them all instantly).
  • Unclipped Caret Fireworks: Every keystroke shoots glowing neon stars and comet trails right out of your typing cursor — flying freely outside the input borders across the whole form before dissolving into thin air.

5. A 3D Wave Flipbook Where Pages Chase Each Other Mid-Air

If you have ever used a 3D flipbook on the web, try clicking "Next Page" five times fast — most libraries either lock up until the first page finishes turning or stutter badly.

Because RePaint treats every physical sheet of paper as an independent component with its own GPU layer and dynamic spine Z-ordering, you can rapid-click a corner and watch 3, 4, or 5 curved pages fly through the air simultaneously in a smooth, continuous wave — just like fanning a real book with your thumb.

Tiny, Hackable, and 100% Static (MIT License)

Despite everything it can do, RePaint is intentionally tiny and easy to read:

LayerWhat Lives InsideSize
Engine/Component tree, GPU layer cache, compositor, 2D QuadTree & animations~530 LOC
Controls/QuadTree panel, Aurora IME inputs, modal popup, context menu, buttons8 clean files
Demos/10K Virtual List, 2.4K Spatial Grid, Firework Studio & 3D Wave Flipbook4 showcases

Even better: during day-to-day development, dotnet watch Hot Reload updates WebGL drawings live on Ctrl + S in ~1 second, and when you are ready to ship, dotnet publish -c Release compiles everything into 100% static WebAssembly files — no backend server needed, free to host on GitHub Pages or Cloudflare Pages.

Why We Built & Shared This

At Neperi, we love a very specific kind of engineering problem: taking something that usually requires heavy, complicated infrastructure and asking how fast and compact it can become when designed from first principles.

RePaint explored that question for interactive WebGL interfaces. Our core product, Neperi Search, applies that exact same obsession to full-text search and RAG retrieval — finding the right passage through typos, missing accents, unspaced scripts, and noisy OCR scans across 20+ languages on plain CPUs, with zero language analyzer setup.

If you enjoy small, fast, unconventional software, check out the RePaint source code on GitHub — we would love to see what you build with it!