9

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

Kevin Kostlan
  • 227
  • 2
  • 6

2 Answers2

14

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

Robin Betts
  • 76,260
  • 8
  • 77
  • 190
  • 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? – Abu Hurairah Oct 23 '21 at 16:35
  • Hi @anonymous ! You mean d2e of regular hexagons, or d2e of this Voronoi? – Robin Betts Oct 23 '21 at 17:05
  • of this voronoi – Abu Hurairah Oct 23 '21 at 17:45
  • @anonymous this crossed my mind, too ... I wonder if this could be implemented without everything grinding to a halt? Worth a look, I think... – Robin Betts Oct 23 '21 at 18:45
  • i know that article but i dont understand it at all, id like to do that with nodes – Abu Hurairah Oct 24 '21 at 05:39
  • @anonymous I'll give it a shot.. it involves a second round of neighbour-searches, looking around the cell containing the feature-point found, the first time round, to be closest to the shading point. Can't promise rapid progress :) – Robin Betts Oct 24 '21 at 09:58
  • ok bro, thnku so mch – Abu Hurairah Oct 25 '21 at 07:40
5

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:

Abu Hurairah
  • 402
  • 3
  • 7