[Media] Kuwahara Filter Running with Rust + WGSL

95 points rumil23 2 comments
[Media] Kuwahara Filter Running with Rust + WGSL

I wanted to share a compute shader implementation of the Kuwahara filter for videos/images with Rust + WGSL. However, I created this example primarily to demonstrate how you can write a complex multi-pass shader :-) . I built using cuneus (a shader engine, built with wgpu).

The interesting part is the builder API that handles all the complex GPU binding boilerplate. Instead of manually tracking bind groups and layouts, you just chain what you need:

```rust
ComputeShader::builder()
    .with_multi_pass(&passes) // struct tensor calc, tensor field, smoothing, anisotropic filt and main entries in the wgsl side. we can ping pong them also! 
    .with_custom_uniforms::<KuwaharaParams>() //egui thingies
    .with_channels(1) // for video/image input
    .build()
```

cuneus automatically sets up the correct binding layout following WebGPU's 4-group convention.  I've been designing the architecture of this in my head for quite some time, and I think it's now in its final form for multi pass complex shaders. video/webcam supports based on the gstreamer. I pass the video/audio/webcam to the GPU in the back. Each feature you add gets its predictable slot, so the WGSL side always knows where to find things. Hot reload works out of the box so you can tweak shaders live.

code:
https://github.com/altunenes/cuneus/blob/main/examples/kuwahara.rs

Note, you can also download  the app directly here: (search as kuwahara, but I do not guarantee stability releated with the gstreamer: but should work on windows + macs correctly)

https://github.com/altunenes/cuneus/releases/tag/v0.4.1

See usage if you want to try more:

https://github.com/altunenes/cuneus/blob/main/usage.md

I'm constantly improving it because I use it regularly as a hobby myself. :-) hope you enjoy