Painting · real-time post-process
Kuwahara filter
Drag the line: left of it, the shader's render; right of it, the same frame after the filter.
Kuwahara filter · Kuwahara et al. 1976
Each pixel takes the average of its calmest quarter
Move the pixel across the rim: the calmest quarter flips sides, so the filtered rim stays sharp.
// window radius r: four
// (r+1)^2 quarters sharing
// the middle row, column
for (int k = 0; k < 4; k++) {
// average
vec3 m = M[k] / n;
vec3 d = S[k] / n - m * m;
// spread
float v = d.r + d.g + d.b;
if (v < best) {
best = v;
col = m; // the pixel
}
} Box blur · Kuwahara filter
The box blur softens the rim; the Kuwahara filter keeps it sharp
Drag the line across the rim, then grow the window both filters share.
Window radius
A wider window paints bigger, flatter patches
Slide it up: the speckle merges into patches, and the colony outlines hold.
Generalised Kuwahara filter · Papari, Petkov, Campisi 2007
Eight soft sectors round off the square quarters' blocks
Flip the window shape and watch the teal rim's patches.
// each sector k: weighted average m,
// spread v; calm sectors weigh most
float w = 1. / (1. + pow(1000. * v,
.5 * q));
o += m * w; ws += w;
// ...
col = o / ws;
// q, the sharpness: low blends every
// sector, high keeps the calmest Layer added: sectors
The dish, painted with your radius and window shape
Drag the line to compare with the render; switch a layer off to see what it adds.
Anisotropic Kuwahara filter · Kyprianidis, Kang, Döllner 2009
Stretched along the edges, the strokes follow the form
Show the windows: long along rims and rings, round on flat agar.
// E, G, F: the structure tensor,
// blurred gx*gx, gy*gy, gx*gy
// l1, l2: its eigenvalues, l1 >= l2
vec2 t = vec2(l1 - E, -F); // along
float A = (l1 - l2) / (l1 + l2);
// A: 0 on flat agar, 1 on a rim
float a = r * (1. + A); // long
float b = r / (1. + A); // short Layer added: direction
The dish, painted with your radius, shape and direction
Drag the line to compare with the render; switch a layer off to see what it adds.
Recap