r/webgpu • u/No-Citron-3963 • Sep 28 '26
Rust + WebGPU: A Multi-Platform Physics-Based Paint Engine
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 Sep 28 '26
Yo you did what I was too lazy to finish and abandoned.
Looking awesome.
1
u/No-Citron-3963 Sep 28 '26
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 Sep 29 '26
Curious, what's the added benefit of Rust versus just webgpu?
1
u/No-Citron-3963 Sep 29 '26
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 Sep 29 '26
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 Sep 29 '26
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 Sep 29 '26
can you add spraypaint paint patterns
1
u/No-Citron-3963 Sep 30 '26
Tap the third brush icon from the left, then pick one from the AirBrush category.
2
u/thecragmire Oct 01 '26
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 Oct 01 '26
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/babymastodon Oct 07 '26
Super cool. Do you have any source code?
I'm also building a wgpu-powered drawing app (capycanvas), and I'm at the point where I want to try adding some physical media simluations.
I'm specifically wondering how to go about representing the data (wetness? height?), while keeping it fast enough to run at 120hz.
1
u/No-Citron-3963 Oct 08 '26
Thanks! Ah, sorry, it's not open source.
The solver is pretty self-contained, so it could probably be reused more or less as is. But how you store the canvas and layer data, and what you keep around mid-stroke, should really be designed around how capycanvas works right now, so I can't give you a quick answer there.
How about opening an issue on capycanvas? I'd like to read through the code a bit first, and then we could talk it over in a PR.
2
u/babymastodon Oct 08 '26
Thanks! That would be super helpful. I want to give this a shot this weekend, if I have enough credits.
I've created a github issue here and would love your guidance on the direction: https://github.com/capyatelier/capycanvas/issues/7
The stroke engine is fairly flexible at the moment, and the data model is something I'm trying to figure out. Even if you have suggestions on algorithms that work well from an artistic perspective, that would be super helpful.
2
2
u/Lucataine Sep 28 '26
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?