[source lang="vb"]sub vor_gradient cdecl(px as f32_t, pz as f32_t, weights as integer, vret as vor_return ptr) dim as integer x = int(px), z = int(pz) dim as vvalue pmin(WEIGHTS-1) dim as vpoint ptr p2 dim as f32_t dist, mindist(WEIGHTS-1) for i as integer = 0 to WEIGHTS-1 mindist(i) = 10 '' set to out of bounds distance next for dx as Integer = x-2 to x+2 for dz as integer = z-2 to z+2 p2 = @vor_points( dx and (VORONOI_TABLESIZE-1), dz and (VORONOI_TABLESIZE-1) ) dist = VOR_EUCLIDIAN( px, pz, dx + 0.5, dz + 0.5 ) for i as integer = 0 to WEIGHTS-1 if dist <= mindist(i) then for j as integer = WEIGHTS-1 to i+1 step -1 '' set N-closest pmin(j) = pmin(j-1) mindist(j) = mindist(j-1) next '' set closest pmin(i).value = p2->value mindist(i) = dist exit for endif next next next '' find max distance #define length mindist(WEIGHTS-1) #define weight(i) mindist(i) '' inverse distance and recount weights dist = 0.0 for i as integer = 0 to WEIGHTS-1 weight(i) = 1.0 - mindist(i) / length dist += weight(i) next dim as uinteger cl = 0 '' finalize weights and create final color using N-vector for i as integer = 0 to WEIGHTS-1 weight(i) /= dist cl = adduint32(cl, pmin(i).value, weight(i)) next '' return final composite vret->v = cl end sub[/source]
I am trying to blend the nearby weights of voronoi cells
in this example all cell centers are at 0.5, 0.5 for simplicity's sake, and to show the error more clearly
I have tried for a day now to figure out what mistake I'm making, but i just dont understand what I'm doing wrong here
First: I find the N closest points (determined by WEIGHTS)
then I use the longest distance as the "normalizing value" all the way to the end
finally i divide by the total length of the inverted distances (so that the closest point has the strongest weight)
by listening to my brain, this should be working, but it doesn't seem like it's working alright.. :S
Note: if you want me to recreate the function in C, that can be arranged since it's not an issue for me..
Here are some example images for 3,4 and 9 weights, first with center at (0.5, 0.5) then with centers at the respective cells for a total of 6 images:http://art.fwsnet.net/vor/w3c.pnghttp://art.fwsnet.net/vor/w4c.pnghttp://art.fwsnet.net/vor/w9c.pnghttp://art.fwsnet.net/vor/w3.pnghttp://art.fwsnet.net/vor/w4.pnghttp://art.fwsnet.net/vor/w9.png
Edited by Kaptein, 02 November 2012 - 09:29 PM.