Symmetric Nearest Neighbor Filter (Post Process)

Hey there, I’m wanting to recreate the sort of painting-stroke/nearest neighbor material seen in this video:

but I truthfully have no idea where to begin. I don’t need help with the sobel edge stuff, mainly the color smearing/averaging effect. My first thought was to extract the base color information and sort of average out the values on screen, but I have no idea what kind of math to use to do so. Anyone have any ideas?

Cheers!

@hippowombat
SNN is pretty straightforward. You take a kernel of desired size, and sample an opposite(pixel with offset of 1,1 has its opposite at -1,1) pair of pixels. You compare their colors to the center pixel, and select the one, which is better matching the central pixel. You add up the sampled values divide the result by number of pairs. If you have no problems making sobel filter, you won’t have any troubles making SNN.

You have a bit of leeway in interpretation here.
For example, you can experiment with different kernel shapes and sizes, you can decide if you want to include central pixel into calculation or not.
And of course, the decision how to compare colors is up to you. Originally, the filter is meant to be run independently per each color channel, but you can compare luminance for example, or determine color difference as simple distance or even develop your own fancy formula.
Applicable to UE4 post process, you can further improve the filter by adding depth-based sample rejection(determine difference between depth of central pixel, and sampled pixel, and if the depth is greater than set threshold, use the value of central pixel as a result), though it is somewhat expensive.
Few links for you:
Link1
Link2
Link3
Good luck!

I thought this was a Kuhawara style filter.
Great comment there Deathrey, had some good read with coffee this morning thanks to you.

Man I would pay good money for something like this! If anyone has any luck pulling this off I hope they will share their shader graph here! :slight_smile:

This definitely looks more like a Kuhawara filter with a wide pixel offset. You can easily find code/scripts with some quick googling. From there, as long as you understand basic code, you can create an equivalent in UE. Oh and the outline effect is a whole nother beast in it’s own, but there are dozens of guides out there on making outlines.

TL: Original, TR: 5, BL: 9, BR: 15 window widths
Kuwahara_varying_window_sizes.jpg