voronoi constant width cell borders

   6733   6   0
User Avatar
Member
47 posts
Joined: May 2009
Offline
ive been trying to do a shader that would draw voronoi cell borders with constant width ( constant world space width).
my best result so far is by getting two closest point from point cloud(PC1 and PC2) getting the mid point between them(M). then doing a dot product between vector M-P and normalized PC1-PC2 and then thresholding that distance value to get the line. it works allmost beatifully. i get problems on the cell border crossings.
maybe my approach is completely off, any better thoughts?

cheers
Kustaa

Attachments:
voro.jpg (44.5 KB)

User Avatar
Member
519 posts
Joined:
Offline
Hey Kustaa,

I am hacking my way through Advanced Renderman and there is a paragraph describing the voronoi-noise including normalizing the veins. Have a look at this code (it's all in proper vex). You compile it to an otl with the command vcc -l MyVoronoi.otl voronoi.vfl

Cheers,
Hans

Attachments:
voronoi.vfl.tar.gz (1.2 KB)

User Avatar
Member
401 posts
Joined:
Offline
Haven't look at pagefan's file, yet.

There's also Stupid Renderman Trick for constant width noise lines:
Constant Width Shaders! by Mach Kobayashi from Pixar Animation Studios

A compiled Houdini version:
http://forums.odforce.net/index.php?/topic/6967-a-shader-each-day/page__view__findpost__p__46797 [forums.odforce.net]


http://renderman.org…mach2006.ppt.gz [renderman.org]
this is not a science fair.
User Avatar
Member
47 posts
Joined: May 2009
Offline
thanks for your replies Pagefan and rgd!

@Pagefan
i had a quick try with your constant width voronoi but i seem to get the same crossing problems as with my dot based solution. its more obvious with thicker lines.

@rgd
that derivative based “normalization” looks really intresting, i have to take a closer look at it. im afraid that it might have the same problems as the other two approaches. since the crossing problems appear where the pointcloud pair changes. maybe i need to read my points differently

i made again a picture that tries to explain what i think the problem is.
black lines are the cell borders, grey lines show where the pointcloud pairs change and white is the constant width border.

cheers!

Attachments:
voro2.gif (5.9 KB)

User Avatar
Member
401 posts
Joined:
Offline
Maybe trace the Voronoi, render it as lines with a width attribute and fix it in comp?
this is not a science fair.
User Avatar
Member
47 posts
Joined: May 2009
Offline
i think i got closer to the solution!

instead of considering just a pair of points from pointcloud i need to compare more of them. also it helped alot to write this in vex instead of trying to navigate in vop-wire-jungle.

this is my first shader written in vex an theres some issues that i need to clean up, especially with looping through the points, right now its “hardcoded” to go through 4 points. but i couldnt wait to show it.


surface
voro()
{
int loop;
int handle;
int success;
float data;
vector pc;
vector oP;
int iter;


oP = ptransform(“space:current”, “spacebject”, P);

handle = pcopen(“/home/vuoriku/Desktop/pc.pc”, “P”, oP, 9999, 4);

loop = 1;
iter = 0;
while( loop != 0 )
{

vector pc1;
vector pc2;
vector pc3;

success = pciterate(handle);

pcimport(handle, “P”, pc);

//gather first three points
if(iter == 0)
{
pc1 = pc;
}
if(iter == 1)
{
pc2 = pc;
}
if(iter == 2)
{
pc3 = pc;
}

//main loop
if(iter == 3)
{
vector m1 = (pc1+pc2)*0.5;
vector pm = oP-m1;
float dist1 = abs(dot(normalize(pc1-pc2), pm));

m1 = (pc1+pc3)*0.5;
pm = oP-m1;
float dist2 = abs(dot(normalize(pc1-pc3), pm));

m1 = (pc1+pc)*0.5;
pm = oP-m1;
float dist3 = abs(dot(normalize(pc1-pc), pm));

data = dist1;
if(dist2 < dist1 && dist2 < dist3){ data = dist2;}
if(dist3 < dist1 && dist3 < dist2){ data = dist3;}
}
loop = success;
iter += 1;
}
Cf = filterstep(0.03, data, “width”, 0.01);
}

Attachments:
voro3.gif (40.6 KB)

User Avatar
Member
401 posts
Joined:
Offline
nice!
this is not a science fair.
  • Quick Links