1
$\begingroup$

Is there a way to access the (possibly interpolated) vertex attribute of the closest vertices in a shader node, given a 3D position? In a CPU-based program, I'd use a k-d tree and search for the nearest neighbors, but how do I do this in a shader node graph?

Context: I have a texture node (Voronoi) from which I use the "Position" output to segment my material into Voronoi cells: enter image description here I would like to use a vertex attribute (stored in a vertex color) to determine whether a whole cell should be "on" or "off", i.e. the vertex attribute acts as a "threshold" of sorts. Is there a way to sample the (closest) vertex color at a specific 3D position?

The only idea I had so far was to interpolate the vertex color into a volume and then sample from that volume at the position given by the Voronoi texture... is that possible?

(For reference, I have a related question that gave rise to this one. I have created this new one because the other one is much more general: Blending two procedural "reptile-scale" textures - at scale edges)

$\endgroup$
3
  • $\begingroup$ Could you bake it to a UV texture, then sample that texture based on your voronoi thing? $\endgroup$ Commented Aug 16, 2021 at 7:53
  • $\begingroup$ @ReinisMazeiks I'm not sure I understand. I jut tried baking the vertex colors into a texture (after UV-unwrapping), that works. But now that image can be sampled using UV coordinates, while the voronoi coordinates are 3D vectors. How would I use these 3D vectors to sample the image? $\endgroup$ Commented Aug 22, 2021 at 21:08
  • $\begingroup$ they don't need to be 3d vectors, you can also voronoi the 2d coordinates. this is what i meant imgur.com/bboSJTp $\endgroup$ Commented Aug 24, 2021 at 16:07

0

You must log in to answer this question.

Browse other questions tagged .