Hexagonal Mapping
Many patterns in nature are arranged in hexagons instead of grids: turtle shells, thorns, flower buds, and the most obvious, honeycombs. To create surface shaders for these materials, it is convenient to be able to convert from cartesian coordinates to a hexagonal space.
Thomas Jahn provides an excellent discussion of this method here. I'll just give a quick overview. First, a grid is laid out. Then, alternating rows are used to determine which type of tyle we are currently in. Then, based on the tile type, we use trig to determine which hex cell we are in specifically. The types of cells are laid out as follows:

Then, I created three other coordinates besides cell identity. These include the distance from the closest edge, distance from the center, and radial coordinate around the center axis. These coordinates were computed with a system I developed which creates the six points of the hexagon and then translates them based on what cell type we're in. These can then be used to derive the rest of the data. Following are shot showing the mapping of the new coordinate system:
Cell ID. |
Distance from center. |
Angle around radius. |
Distance from nearest edge. |