The problem
Slot games use particles for coin showers, sparks along win lines and embers around bonus frames. Most PixiJS particle libraries simulate on the CPU, so each particle is JavaScript work on the main thread. On phones, this work is often the first cause of dropped frames in a large win.
Pylinka ("dust" in Russian) runs the simulation on the GPU. This post is about the path from an animator's node graph to a shader, and how that path stays reliable.
From graph to shader
An effect is a graph of nodes: spawn, forces (turbulence, vortex, wind, drag), math, curves, and outputs for position, colour, size and rotation. There are about 80 node types.
@pylinka/compiler does four steps:
- Sorts the graph and validates it: no cycles, matching types.
- Splits each value into "calculated once at birth" and "calculated every frame", to keep per-frame work small.
- Assigns particle attributes to slots in GPU buffers.
- Generates code from one intermediate form: WGSL compute shaders for WebGPU, or GLSL ES 3.00 vertex shaders with transform feedback for WebGL2.
The runtime uses Pixi's own WebGPU device or GL context. Particles are normal objects in the scene graph, so they can sit between a reel and its frame.
Values that an animator wants to adjust live are knobs. A knob is a GPU uniform, not a constant, so a change is one write and needs no recompile.
Locked compiler output
Small compiler changes are hard to review: a reordered expression, a renamed temporary, a moved slot. Any of them can change an effect that a client approved weeks earlier.
Reference graphs therefore compile to WGSL and GLSL files that are committed to the repository. Tests compare new output with these files byte for byte. If the generated code changes, the difference is in the pull request, and a person must accept it.
The preview must match the game
The editor uses an interpreted engine for instant edits. Games use the compiled shaders. In the first months the two behaved differently:
- The interpreted engine added default velocity and scale that the graph did not ask for.
shape.circlespawned inside the disc in one engine and on the ring in the other.- Rotation inputs took radians. An animator typed 45, saw the sprite spin fast, and reported that rotation was broken. The interface made the wrong value easy to enter.
Release 2.0 removed each of these differences and changed angles to degrees. It was a breaking change and was versioned as one. An effect that looks correct in the editor now looks the same in the game.
WebGL1 fallback
Some players still have only WebGL1, which has no transform feedback. Version 2.2 adds a fallback: the interpreted simulation runs on the CPU and the particles are drawn with instancing. It loads only on hosts that need it (about 12 KB gzip).
The README lists the costs. Results are calculated in 64-bit on the CPU instead of 32-bit on the GPU, so they can differ slightly. The main thread pays for every particle: about 0.15 ms per 10,000 particles on a desktop CPU, and about 2 ms with turbulence. That is acceptable for a fallback and not for a default.
Open work
The editor, recipes and a phone preview app are at pylinka.schmooky.dev. The performance targets are written down: at least 50,000 particles at 60 fps on the lowest device tier, and at most 0.1 ms of CPU per system per frame. They are targets until they are measured on phones, and the site does not present them as results.