9
$\begingroup$

The Voronoi texture uses a square grid, which is apparent at lower values of randomness. However, is it possible to use a hexagonal grid instead? Adding the right linear transformation could make the points' locations align with a hexagonal grid, but the circles around each point would distort into ellipses in doing so. More precisely, I would like to reproduce the below image (not made in Blender). the distance to the closest point on a hexagonal grid with a small-ish randomness setting

$\endgroup$
12
  • 2
    $\begingroup$ Related: How To Do UV Indexing in hexagonal pattern? $\endgroup$ Oct 12, 2021 at 7:59
  • 1
    $\begingroup$ @JachymMichal The remaining problem: random-point-in-hexagon. Or triangle. Which boils down, one way or another, to random-point-in-parallelogram (Sheared cartesian Voronoi x 3 ?). Even then, you have to check against 6 neighbours, AFAIK $\endgroup$
    – Robin Betts
    Oct 12, 2021 at 8:45
  • 2
    $\begingroup$ @Kifayat Sorry for delay .. done the basics, results like this.. will write up as answer when I can.. still unsure how best to get back from distance-to-feature-point to color per Voronoi cell, etc. $\endgroup$
    – Robin Betts
    Oct 14, 2021 at 20:50
  • 1
    $\begingroup$ Wow! This is amazing! $\endgroup$ Oct 15, 2021 at 6:13
  • 1
    $\begingroup$ @RobinBetts: Chapeau!!!!!!👍 $\endgroup$
    – Chris
    Oct 15, 2021 at 6:23

2 Answers 2

14
$\begingroup$

Hexagonal Voronoi

A Voronoi texture works by dividing the texture-space into cells, defining a pseudo-random 'feature point' in each cell, which is a function of the cell's location. Then each shading-point looks up the the feature-point in its own and neighbouring cells, returning the distance to the closest feature-point.

Blender's Voronoi works on the basis of rectangular cells. The ask, here, is to base a Voronoi on hexagonal cells.

1. Create a hexagonal grid

That's dealt with at the bottom of this answer. One of the outputs is '2D Index' which is the coordinate in the current texture-space of the centre of each cell.

2. Create a feature-point in each cell

To obtain random points, evenly distributed in a hexagon, the hexagon is divided into 3 rhombuses as shown below. One of those is randomly selected using the X of 3D White Noise. Then random 0-1 multiples,(using Y and Z of the noise) of the U and V vectors for that rhombus yield evenly distributed points inside it. The result is shown on the right:

enter image description here

The nodes for this:

enter image description here

A driven 'Randomness' mix is included to blend between cell-centers and random offsets of them. This should be wired in, but none of this tree is optimized.

3. For each cell, return the coordinates of its own, and its neighbour's centers

enter image description here

(above). '0' is the cell itself, '1' is the cell to the right, and the others are obtained by rotating '1' through multiples of 60 degrees. Again, to optimise, the rotations should be avoided: the resulting vectors should be hard-coded. In this version, I'm avoiding spaghetti at the cost of efficiency.

4. For each shading-point, find the nearest feature point

A small helper-group returns the closer of the points A and B to P:

enter image description here

which is daisy-chained to ...

5. Yield the coordinate of the closest feature-point to the shading point

enter image description here

... when used with the combinations already described.

None of this is optimised for speed. Rotations are used instead of hard-coding, distances are repeatedly calculated instead of being passed on.. and so on. The White Noise is very sensitive to floating-point errors in input values around -1, it seems? So a large number has been added to the input vectors, when it's used, here.

This .gif shows 'Distance', 'Position', and 'Color' outputs of the whole kaboodle, with 'Randomness' being swiped from 0-1:

enter image description here

Settings for your ref: about .7 'Randomness', and a color-ramp:

enter image description here

$\endgroup$
7
  • $\begingroup$ Hi there! Hope u are doing great! I was able to create distance to edge of the hexagons (using ur file) but the problem is that subtracting doesn't really give the distance and it doesn't work nicely (causes some artifacts) at higher randomness. Is there any way we can achieve precise borders? $\endgroup$ Oct 23, 2021 at 16:35
  • $\begingroup$ Hi @anonymous ! You mean d2e of regular hexagons, or d2e of this Voronoi? $\endgroup$
    – Robin Betts
    Oct 23, 2021 at 17:05
  • $\begingroup$ of this voronoi $\endgroup$ Oct 23, 2021 at 17:45
  • $\begingroup$ @anonymous this crossed my mind, too ... I wonder if this could be implemented without everything grinding to a halt? Worth a look, I think... $\endgroup$
    – Robin Betts
    Oct 23, 2021 at 18:45
  • $\begingroup$ i know that article but i dont understand it at all, id like to do that with nodes $\endgroup$ Oct 24, 2021 at 5:39
5
$\begingroup$

Voronoi noise is made by tiling circles in a square fashion and randomising the positions of all circles. Since the circles are limited to their tile's size, when you randomly change the position, they exceed their tile size and start to form seams. To eliminate that, we check the neighboring tiles i.e left, right, up, down, etc. This is how the usual voronoi is made. In the case of hexagonal voronoi, we only need to change one thing. We need to tile circles using hexagonal tiles / hexagonal coordinates. You can see how to make them here How To Do UV Indexing in hexagonal pattern? OR you can use the "hextiles" nodegroup in the blend file below. I have made a video how I made this : https://www.youtube.com/watch?v=RbH3_d9j7ro

enter image description here

Here is the blend:

$\endgroup$
5
  • $\begingroup$ To make the circles expand like in the original picture in the question, add a map range node and set it to smoother step. $\endgroup$ Oct 15, 2021 at 8:25
  • $\begingroup$ Also a very good answer and much work put in! Too bad they don't let you accept two answers at once. $\endgroup$ Oct 15, 2021 at 21:54
  • $\begingroup$ Thank you so much! $\endgroup$ Oct 16, 2021 at 6:17
  • $\begingroup$ @anonymous Hmm, just spotted I should strictly be searching another ring of neighbours .. very unusual, but the closest feature point could just be 2 cells away :( it would be a hell of a coincidence.... $\endgroup$
    – Robin Betts
    Oct 25, 2021 at 10:52
  • $\begingroup$ what do u mean bro? $\endgroup$ Oct 27, 2021 at 9:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .