How to change Voronoie OSL code to make it more linework

Any idea maybe what can be changed of the code so that instead of the voronoie effect we know with blurred filled cells we can get more a sharp crisp cell outline with rounded edges like this:

Please excuse my low level question, I hardly understand the code, and tried play with it but I mainly break the code ;(

http://datumdezign.com/itp/wp-content/uploads/2011/04/voronoi_marble_bookcase_decorative_shelving.jpg

#include “stdosl.h”
#include “node_texture.h”

/* Voronoi */

shader node_voronoi_texture(
int use_mapping = 0,
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
string Coloring = “Intensity”,
float Scale = 5.0,
point Vector = P,
output float Fac = 0.0,
output color Color = color(0.0, 0.0, 0.0))
{
point p = Vector;

if (use_mapping)
p = transform(mapping, p);

/* compute distance and point coordinate of 4 nearest neighbours */
float da[4];
point pa[4];

voronoi(p * Scale, “Distance Squared”, 1.0, da, pa);

/* Colored output */
if (Coloring == “Intensity”) {
Fac = fabs(da[0]);
Color = color(Fac);
}
else {
Color = cellnoise_color(pa[0]);
Fac = (Color[0] + Color[1] + Color[2]) * (1.0 / 3.0);

}
}

I dug a bit deeper and here is what I got:


#include "node_texture.h"

/* B&W Voronoi */

shader node_voronoi_texture(
    int use_mapping = 0,
    matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
    float Scale = 5.0,
    float Limit = 0.0,
    point Vector = P,
    output float Fac = 0.0,
    output color Color = color(0.0, 0.0, 0.0))
{
    point p = Vector;

    if (use_mapping)
        p = transform(mapping, p);

    Fac = 1.0 - voronoi_F1F2(p* Scale); // Inverted
        
    if (Fac < Limit)
    {
        Fac = 0.0;
    }
    else
    {
        Fac = 1.0;
    }
    Color = color(Fac);
}

Set the “Limit” just a little above 0.9 and we’re getting some B&W line art. Some more work is needed to smooth out the cells border. Any way, you’re stuck here for now, waiting for Cycles to get volumetric materials.


This can also be achieved by running the voronoi through an rub curve. Even more control. No screenshot as I’m not on my pc.

A better function is than if then is …
float step(float a, float x)
{return x >= a;}
this function will be easier to antialias down the road.

or smoothstep(edge0,edge1,x)…e.g. smoothstep(0.8,0.9,x)