Godot Post-Processing Kuwahara Filter

Godot Post-Processing Kuwahara Filter

The Kuwahara filter is a well-known filter for adding a bit of stylized painterly effects to your renders. The latest version of Blender even includes a Kuwahara filter in its compositor.

I'll leave more detailed descriptions of the Kuwahara filter to others (just search the internet for "Kuwahara filter" or "Kuwahara anisotropic filter"), but here are the basics. For each pixel, you divide a small window surrounding the pixel into sectors (such as rectangular quadrants or pieces of a pie). Then, you find the sector that has the least amount of variation in its colors, and you use the average color of that sector for the current pixel.

I've provided a sample implementation in my shader example project on GitHub that uses four rectangular quadrants that are rotated to align with the brightness gradient at each pixel.