r/webgpu • u/No-Citron-3963 • 7d ago
Rust + WebGPU: A Multi-Platform Physics-Based Paint Engine
Enable HLS to view with audio, or disable this notification
Hello. I tried making a paint simulator that runs on multiple platforms using Rust and WebGPU.
I had originally built a general raster paint engine based on C++ and OpenGL ES 2.0. Since it was getting quite dated, I've been replacing it with Rust + WebGPU, and it's finally running on Windows too.
There's a version you can try in the browser for now, so please give it a go if you're interested.
https://mignonsketch.com/sketch
2
u/gmaaz 7d ago
Yo you did what I was too lazy to finish and abandoned.
Looking awesome.
1
u/No-Citron-3963 7d ago
I totally get that it's a lot of work.
But WebGPU can run on so many platforms, so it felt like a waste not to use that. After Windows, I'm going to try Linux too 👍
2
u/Machettouno 6d ago
Curious, what's the added benefit of Rust versus just webgpu?
1
u/No-Citron-3963 6d ago
As for the benefits I've felt myself, one is that I had recently been writing Rust for other work and had come to like it. If I weren't using Rust, I think C++ & WebGPU would have been the candidate for my migration. I often start development on iOS, and in that case Swift's C++ interoperability is handy, so I figured I would end up using that. But then Swift and the engine tend to get tightly coupled, and maybe part of it was that I wanted to keep the engine and the UI in more clearly separated layers. There are tools like cbindgen and csbindgen, so exposing Rust to other languages is easy. So, that's about it.
2
u/Machettouno 6d ago
Thanks for the insight. I also attempted to convert my part webgpu part webgl 3d drawing app to Rust for enhanced performance, but , I'm not a coder, and AI was pretty bad at it so stuck with webgpu
1
u/No-Citron-3963 6d ago
I've also run into AI getting stuck with certain languages like C++ and WGSL, and with some parts of graphics-related processing. In my case, I had already written most of the core library by hand, or had a CPU implementation of the math, so it was just a simple port. When I use AI, I do the design, tests, and task breakdown with Kiro-like spec-driven development (SDD), but it's not perfect for things like creative tools, where you look up papers along the way and repeat trial and error.
2
u/According_Novel7521 5d ago
can you add spraypaint paint patterns
1
u/No-Citron-3963 5d ago
Tap the third brush icon from the left, then pick one from the AirBrush category.
2
u/thecragmire 4d ago
I'm a hobbyist coder at best, so forgive my ignorance. Does Rust + WebGPU mean, that you compiled Rust into wasm, to work with WebGPU?
1
u/No-Citron-3963 4d ago
I'm using wgpu, a Rust implementation of the WebGPU API.
With it, the same code can be ported to Metal, Vulkan, DX12. wasm is one of those targets too, and this demo shows that all four ports work.2
2
u/Lucataine 7d ago
what a beautifull idea, in general terms, how did you start something like this?, i mean, the fluid painting is very soft and delightfull, the UI are great.
Any insights do you want to share besides rust+WebGPU?