# Voronoi pattern with toon lighting

by MaT   Last Updated October 19, 2019 21:13 PM

I currently have a single step toon shader using this simple behaviour (no anti-aliasing for the moment). As expected the result is a single straight line.

``````float ndotl = dot(normal, lightDir);
float result = step(0, ndotl);
``````

But I would like to apply a Voronoi pattern on this straight line and break it to make it irregular using this pattern while keeping this hard separation. But I don't see any way to apply correctly the Voronoi pattern on the shading.

Here's how the Voronoi pattern is generated.

``````float2 g = floor(uv * density);
float2 f = frac(uv * density);
float result = 0.0;
float dist = 8.0;

for (int y = -1; y <= 1; y++)
{
for (int x = -1; x <= 1; x++)
{
float2 lattice = float2(x, y);
float2 uv2 = lattice + g;
float2x2 m = float2x2(15.27, 47.63, 99.41, 89.98);
uv2 = frac(sin(mul(uv2, m)) * 46839.32);
float offset = cos(uv2.x * angleOffset) * 0.5 + 0.5;

float d = distance(lattice + offset, f);
if (d < dist)
{
dist = d;
result = offset;
}
}
}
return result;
``````

Any idea how I could mix Voronoi and single step toon shading ? Thanks a lot.

Tags :

## Related Questions

Updated September 20, 2017 02:13 AM

Updated October 13, 2016 09:05 AM

Updated October 05, 2017 13:13 PM

Updated July 22, 2015 13:05 PM