Noureddine RAMDI / ai4anim-webgpu: in-browser neural motion matching with WebGPU compute shaders

Created Sat, 23 May 2026 20:41:14 +0000 Modified Sat, 23 May 2026 20:41:27 +0000

sweriko/ai4anim-webgpu

Neural character animation is usually the domain of powerful desktop GPUs or dedicated engines, but ai4anim-webgpu brings this capability directly into the browser. It ports AI4Animation’s neural-motion-matching system to TypeScript and WebGPU, running both biped and quadruped neural networks entirely client-side with no backend required. The real standout here is how it executes batched inference for multiple animated agents in a single compute dispatch using hand-tuned mixed-precision matrix multiplication kernels optimized for the browser’s GPU environment.

in-browser neural motion matching with WebGPU compute shaders

At its core, ai4anim-webgpu implements a neural motion matching system originally designed in AI4Animation, but rewritten for TypeScript and WebGPU. Neural motion matching is a technique where a neural network predicts appropriate character poses or animations by matching current states against learned motion manifolds. This repo supports both biped and quadruped characters, running their neural networks fully in-browser with WebGPU compute shaders.

The architecture combines several advanced GPU programming techniques. It uses batched inference across all active agents in the scene, consolidating all agent computations into a single dispatch call per frame tick. This keeps GPU overhead low and maximizes throughput.

Under the hood, the system relies on custom mixed-precision matrix multiplication kernels: weights are stored in fp16 (half precision) while accumulation is done in fp32 (single precision). This tradeoff balances memory footprint and compute precision, critical on WebGPU where native fp16 support varies by hardware. For rendering, all characters use a single GPU-instanced SkinnedMesh, minimizing draw calls regardless of how many agents are active.

The codebase is TypeScript-based, leveraging WebGPU APIs for both compute shaders and rendering. This project runs entirely in the browser, which means no external servers or native binaries are necessary. It includes a basic control interface and a live demo showcasing the real-time neural animation in action.

technical strengths and design tradeoffs: mixed-precision batched inference and instanced rendering

What distinguishes ai4anim-webgpu is its focus on making neural character animation practical in a browser environment by squeezing out efficiency through GPU programming.

The batched inference approach is key. Instead of running one network evaluation per agent, it batches all active agents together, issuing a single compute dispatch per tick. This reduces CPU-GPU synchronization overhead and maximizes GPU utilization, crucial for real-time performance in WebGPU contexts.

The mixed-precision matmul kernels are hand-tuned to use fp16 weights but accumulate results in fp32. This is a classic tradeoff: fp16 halves memory bandwidth and storage requirements compared to fp32, but pure fp16 accumulation risks numerical instability. Accumulating in fp32 keeps results stable while still gaining fp16’s memory benefits. Implementing this efficiently in WebGPU shaders takes effort because the API and hardware support for fp16 are not uniform.

Rendering uses GPU instancing to share a single SkinnedMesh among all characters, minimizing draw calls—often a major bottleneck. This architectural choice means the system can scale to many agents without hitting draw call limits, though it also imposes constraints on per-agent visual customization.

The code is surprisingly clean for GPU shader-heavy work, with careful separation of compute and rendering logic. The repo includes shader source files and TypeScript utilities to manage buffers and dispatches.

The main tradeoff is that this is still a research-proof-of-concept level project rather than a fully featured animation engine. For example, the control interface is basic, and the system assumes fixed network architectures and models. Production use would require more extensibility and robustness.

quick start

npm install
npm run dev

These commands install dependencies and start the development server, launching the demo in the browser. This is straightforward for anyone familiar with npm-based front-end projects.

verdict

ai4anim-webgpu is a neat demonstration of how to run neural motion matching fully in-browser using WebGPU’s compute shaders and mixed-precision GPU kernels. It’s especially relevant if you’re exploring WebGPU beyond graphics into general-purpose GPU compute, or if you’re interested in neural character animation without relying on native apps or cloud inference.

The repo is not a drop-in production system yet; it lacks advanced tooling, extensibility, and user-friendly controls. Still, the technical approach to batched inference and instanced rendering is worth understanding if you’re working on real-time animation or GPU compute in the browser.

If you want a hands-on example of pushing WebGPU for ML + animation, this project is a solid reference point. But expect to extend and adapt it heavily for your own use cases.


→ GitHub Repo: sweriko/ai4anim-webgpu ⭐ 241 · TypeScript