Here’s the screenshot:
and this is the code in the node:
// but little note most of this was written by a youtube video im just trying to make it so the kuwahara filter passes through a brush alpha in the texture sample that influences the shape it takes. This may not be possible but if anyone understands and has a possible solution pls let me know
float3 mean[4] = {
{0,0,0},
{0,0,0},
{0,0,0},
{0,0,0}
};
float3 sigma[4] = {
{0,0,0},
{0,0,0},
{0,0,0},
{0,0,0}
};
float2 offsets[4] = { {-RADIUS, -RADIUS}, {-RADIUS, 0}, {0, -RADIUS}, {0, 0} };
float2 pos;
float3 col;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j <= RADIUS; j++)
{
for (int k = 0; k <= RADIUS; k++)
{
pos = float2(j, k) + offsets[i];
float2 uvpos = UV + pos / VIEWSIZE;
float4 brushCol = BRUSHTEXTURE.SampleGrad(BRUSHSAMPLER, uvpos,ddx(uvpos),ddy(uvpos));
float alpha = brushCol.a;
if (alpha > 0.0)
{
col = SceneTextureLookup(uvpos, 14, false);
mean[i] += col * alpha;
sigma[i] += col * col * alpha;
}
}
}
}
float n = pow(RADIUS + 1, 2);
float sigma_f;
float min = 1;
for(int i = 0; i < 4; i++)
{
mean[i] /= n;
sigma[i] = abs(sigma[i] / n - mean[i] * mean[i]);
sigma_f = sigma[i].r + sigma[i].g + sigma[i].b;
if(sigma_f < min)
{
min = sigma_f;
col = mean[i];
}
}
return col;