<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hieu Nguyen</title>
    <description>The latest articles on DEV Community by Hieu Nguyen (@neperisearch).</description>
    <link>https://dev.to/neperisearch</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4279587%2F0bf2e4de-ebd0-4303-92af-f25d7bff40f7.png</url>
      <title>DEV Community: Hieu Nguyen</title>
      <link>https://dev.to/neperisearch</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/neperisearch"/>
    <language>en</language>
    <item>
      <title>RePaint: What If React Rendered to GPU Layers Instead of the HTML DOM?</title>
      <dc:creator>Hieu Nguyen</dc:creator>
      <pubDate>Thu, 03 Dec 2026 04:44:52 +0000</pubDate>
      <link>https://dev.to/neperisearch/repaint-what-if-react-rendered-to-gpu-layers-instead-of-the-html-dom-3o8d</link>
      <guid>https://dev.to/neperisearch/repaint-what-if-react-rendered-to-gpu-layers-instead-of-the-html-dom-3o8d</guid>
      <description>&lt;p&gt;If you've ever tried to build a rich, motion-heavy web interface, you've probably felt stuck between &lt;strong&gt;component convenience&lt;/strong&gt; and &lt;strong&gt;animation freedom&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;On one side, you have the &lt;strong&gt;HTML DOM and React&lt;/strong&gt;. Composing reusable UI components feels great — right up until you push animations and custom visuals past what browser layout boxes were meant to handle:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Animating or scrolling through &lt;strong&gt;10,000 interactive rows&lt;/strong&gt; or &lt;strong&gt;thousands of 2D cards&lt;/strong&gt; without DOM bloat or layout jank.&lt;/li&gt;
&lt;li&gt;Painting a &lt;strong&gt;multi-color gradient inside selected text&lt;/strong&gt; (which CSS &lt;code&gt;::selection&lt;/code&gt; simply doesn't allow).&lt;/li&gt;
&lt;li&gt;Keeping text highlighted across &lt;strong&gt;multiple input boxes at once&lt;/strong&gt; and copying all of them together (&lt;code&gt;window.getSelection()&lt;/code&gt; only allows one selection per page).&lt;/li&gt;
&lt;li&gt;Driving &lt;strong&gt;physics-based UI motion&lt;/strong&gt;, shooting &lt;strong&gt;unclipped particle fireworks&lt;/strong&gt; straight out of a live typing cursor, or curling &lt;strong&gt;five 3D book pages in mid-air at the same time&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On the other side, you have &lt;strong&gt;raw &lt;code&gt;&amp;lt;canvas&amp;gt;&lt;/code&gt; and WebGL&lt;/strong&gt;. You get total pixel and animation freedom, &lt;strong&gt;but you lose UI ergonomics.&lt;/strong&gt; 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 &lt;em&gt;entire screen&lt;/em&gt; 60 times a second, chewing through laptop batteries even when the UI is sitting completely still.&lt;/p&gt;

&lt;p&gt;So I started wondering:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;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?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That experiment turned into &lt;strong&gt;&lt;a href="https://github.com/neperisearch/repaint" rel="noopener noreferrer"&gt;RePaint&lt;/a&gt;&lt;/strong&gt; — a lightweight (~530 lines of core code) declarative WebGL UI &amp;amp; animation engine for .NET &amp;amp; WebAssembly. I'm open-sourcing it today under the &lt;strong&gt;MIT License&lt;/strong&gt;, and you can play with the &lt;a href="https://neperisearch.github.io/repaint/" rel="noopener noreferrer"&gt;live demo here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdzozkw36dmr5abpfzuhx.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdzozkw36dmr5abpfzuhx.gif" alt=" " width="720" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Core Idea: Built for Animated WebGL UIs
&lt;/h2&gt;

&lt;p&gt;At its heart, RePaint is designed around one principle that makes high-FPS UI animations effortless: &lt;strong&gt;decoupling &lt;em&gt;painting&lt;/em&gt; from &lt;em&gt;moving&lt;/em&gt;.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Instead of thousands of nested &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; tags — or one flat canvas you have to repaint every frame — RePaint treats your entire UI as a tree of &lt;strong&gt;transparent, GPU-cached component layers&lt;/strong&gt; ("GPU stickers"):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvjmchzh1if3g3rqf193p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvjmchzh1if3g3rqf193p.png" alt=" " width="800" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is how the 3-stage pipeline turns declarative UI code into 60–120 FPS WebGL animations:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Declarative Component Tree (Paint Only When Dirty):&lt;/strong&gt; Just like React, you describe your UI out of composable components. Each component renders its vectors, text, and shadows onto its own off-screen &lt;code&gt;SKSurface&lt;/code&gt; texture &lt;strong&gt;only when its state actually changes&lt;/strong&gt; (&lt;code&gt;Invalidate()&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GPU Texture Cache (0.00 ms Static Reuse):&lt;/strong&gt; Clean components (&lt;code&gt;IsDirty = false&lt;/code&gt;) aren't repainted at all — their pixels stay cached on the GPU ready to be stamped in &lt;code&gt;0.00 ms&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;WebGL Compositor (Zero-Repaint Animation Layer):&lt;/strong&gt; This is where motion lives. Transitions, spring physics, &lt;code&gt;Translate&lt;/code&gt;, &lt;code&gt;Scale&lt;/code&gt;, &lt;code&gt;Rotation&lt;/code&gt;, &lt;code&gt;Opacity&lt;/code&gt;, and &lt;code&gt;ZIndex&lt;/code&gt; reordering all run directly on the GPU compositor at &lt;strong&gt;60–120 FPS&lt;/strong&gt; with &lt;strong&gt;zero pixel repaints&lt;/strong&gt;. The moment an animation settles, the engine stops requesting frames and drops back to &lt;strong&gt;0% CPU/GPU idle&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In code, building a component still feels clean and familiar. Inside &lt;code&gt;OnPaint&lt;/code&gt;, a component draws itself &lt;strong&gt;and&lt;/strong&gt; composes its child components in one pass:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;OnPaint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;PaintEvent&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Draw this card's background once into its cached GPU layer&lt;/span&gt;
    &lt;span class="nc"&gt;Theme&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DrawCard&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Canvas&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;box&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;13f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;SKColors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;White&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Theme&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Border&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Compose child components declaratively — each gets its own GPU layer&lt;/span&gt;
    &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Render&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;TextBlock&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ref&lt;/span&gt; &lt;span class="n"&gt;titleId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Rectangle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;130&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Width&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;tb&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;tb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Title&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Render&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ActionButton&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ref&lt;/span&gt; &lt;span class="n"&gt;btnId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Rectangle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Width&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;96&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;184&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;82&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;btn&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;btn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Details ›"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  5 Fun Things This Architecture Unlocks
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Silky 60–120 FPS Motion — And True 0% CPU When Idle
&lt;/h3&gt;

&lt;p&gt;Most WebGL UIs run an endless &lt;code&gt;requestAnimationFrame&lt;/code&gt; loop, keeping your fans spinning even while you're just reading static text.&lt;/p&gt;

&lt;p&gt;In RePaint:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hovering one button on a screen with 50 other components redraws &lt;strong&gt;only that 1 button&lt;/strong&gt;. The other 49 just stamp their cached GPU textures onto the canvas in &lt;code&gt;0.00 ms&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Animations wake up the render loop smoothly on demand and &lt;strong&gt;schedule zero frames&lt;/strong&gt; the instant motion settles — dropping CPU and GPU usage to a real &lt;strong&gt;0%&lt;/strong&gt; until your next click or keypress.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Spin, Bounce, or Pop Entire Live Forms 360° for Free
&lt;/h3&gt;

&lt;p&gt;In HTML, animating a heavy container packed with crisp text, shadows, and interactive inputs often causes blurry rasterization or expensive layout reflows.&lt;/p&gt;

&lt;p&gt;Because every RePaint component (a card, modal dialog, or full multi-field form) is &lt;em&gt;already&lt;/em&gt; a GPU texture, animating an entire live form with 360° rotation and spring physics costs the exact same as moving a tiny icon: &lt;strong&gt;zero text or vector shapes are redrawn during the entire animation.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Massive Lists &amp;amp; 2D Grids with a Spatial QuadTree
&lt;/h3&gt;

&lt;p&gt;To smoothly pan and animate across &lt;strong&gt;10,000 log rows&lt;/strong&gt; or &lt;strong&gt;2,400 rich graphic cards&lt;/strong&gt; without being limited to 1D vertical lists, I built a small &lt;strong&gt;2D Spatial QuadTree&lt;/strong&gt; 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.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Interactive WebGL Text Inputs Without Browser Handcuffs
&lt;/h3&gt;

&lt;p&gt;Standard &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;textarea&amp;gt;&lt;/code&gt; 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 &lt;strong&gt;Vietnamese accents, Japanese/Chinese IME, emojis, and mobile keyboards still work natively&lt;/strong&gt;, while letting me build visual effects HTML can't touch:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Aurora Gradient &lt;code&gt;::selection&lt;/code&gt;:&lt;/strong&gt; Paints a 4-color gradient behind selected text, cleanly splitting letters half-dark and half-white even when the selection ends mid-character.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-Input &lt;code&gt;Copy All Selected&lt;/code&gt;:&lt;/strong&gt; Highlight phrases across &lt;strong&gt;multiple inputs at the same time&lt;/strong&gt;, then right-click &lt;strong&gt;&lt;code&gt;Copy All Selected&lt;/code&gt;&lt;/strong&gt; to grab every highlighted snippet in one go.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unclipped Caret Fireworks:&lt;/strong&gt; Every keystroke launches animated neon sparks and comet trails right out of your typing cursor — flying freely &lt;em&gt;outside&lt;/em&gt; the input borders across the entire form.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5. A 3D Wave Flipbook Where Pages Chase Each Other Mid-Air
&lt;/h3&gt;

&lt;p&gt;Try clicking "Next Page" five times fast in most web flipbooks — they usually lock up until the first page finishes turning.&lt;/p&gt;

&lt;p&gt;Since RePaint treats &lt;strong&gt;each sheet of paper as its own animated component&lt;/strong&gt; with a separate GPU layer and dynamic Z-ordering, rapid-clicking a corner sends &lt;strong&gt;3, 4, or 5 curved pages flying through the air simultaneously&lt;/strong&gt; in a continuous 3D wave, just like fanning a real book with your thumb.&lt;/p&gt;

&lt;h2&gt;
  
  
  Small, Hackable, and 100% Static
&lt;/h2&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Layer&lt;/th&gt;
&lt;th&gt;What Lives Inside&lt;/th&gt;
&lt;th&gt;Size&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;Engine/&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Component tree, GPU layer cache, WebGL compositor, 2D QuadTree &amp;amp; animation loop&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;~530 LOC&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;Controls/&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;QuadTree panel, Aurora IME inputs, modal popup, context menu, buttons&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;8 files&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;Demos/&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;10K Virtual List, 2.4K Spatial Grid, Firework Studio &amp;amp; 3D Wave Flipbook&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;4 showcases&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;During development, &lt;code&gt;dotnet watch&lt;/code&gt; Hot Reload updates your WebGL UI and animations on &lt;code&gt;Ctrl + S&lt;/code&gt; in &lt;strong&gt;~1 second&lt;/strong&gt;. When you're ready to ship, &lt;code&gt;dotnet publish -c Release&lt;/code&gt; compiles everything into &lt;strong&gt;100% static WebAssembly files&lt;/strong&gt; — no backend server needed, easy to host for free on GitHub Pages or Cloudflare Pages.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;⭐ &lt;strong&gt;GitHub Repo (MIT):&lt;/strong&gt; &lt;a href="https://github.com/neperisearch/repaint" rel="noopener noreferrer"&gt;github.com/neperisearch/repaint&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🚀 &lt;strong&gt;Live Demo:&lt;/strong&gt; &lt;a href="https://neperisearch.github.io/repaint/" rel="noopener noreferrer"&gt;neperisearch.github.io/repaint/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;I'd genuinely love to hear your thoughts, feedback, or edge cases that break it.&lt;/p&gt;

</description>
      <category>webgl</category>
      <category>webassembly</category>
      <category>dotnet</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
