Show HN: 1M+ animated GPU sprites in JavaScript
27 points| phaser-studio | 1 year ago |phaser.io
These pack together simple JS object definitions onto the GPU and renders them using a custom vertex shader. This skips all CPU computation and GPU upload operations, resulting in vastly increased performance. For objects that don't need to be updated by input, physics, or other interactive behaviors, we found it to be a great solution.
In testing, we've easily managed to blast millions of sprites around on moderate desktop-grade GPUs. Indeed, we hit the fill rate limitation of the GPU far sooner than we hit any other type of limitation. But as with all hardware-related things, ymmv. Frankly, we'd love to get our hands on a 5090 to see what we could do.
The link includes 4 demos to play with, and the full source is on GitHub and npm under the MIT license.
Flux159|1 year ago
From reading the code & seeing the examples in the sandbox, it looks like the sprite layer is defined one time (initialization) with specific sprite & animation properties that are exposed to JS via the SpriteGPULayer config https://github.com/phaserjs/phaser/blob/v4.0.0-beta.5/src/ga... , then that class passes the info over to the vertex shader which has ifdefs to determine which animation, other features are enabled for a given SpriteGPULayer - https://github.com/phaserjs/phaser/blob/v4.0.0-beta.5/src/re...
This way you don't end up having to do any updates per frame on the CPU and it remains one draw call for the entire layer right?
Are there other use cases besides from large scale sprite/animated backgrounds that you've thought of?
phaser-studio|1 year ago
Lerc|1 year ago
maglite77|1 year ago
adzm|1 year ago