Voronoi pattern with toon lighting

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

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.



Related Questions



Zooming in on procedural generated 2D terrain? (LOD)

Updated October 05, 2017 13:13 PM