How to make a proper hex grid subgraph?

I’ve been trying to make a shader graph subgraph to overlay hexagonal grids on top of my shaders, and to use that grid for other purposes. However, after many attempts I cannot get the UVs to line up right, ever. Below is the simplest implementation I started with.

Unfortunately, that leads to the below (obvious) problem, where the up-down points of the the hex that would fall outside the offset band aren’t respected and cut off.

Any method I’ve tried to employ to finagle the UVs correctly based on sine waves, circles and triangles have led to mostly hilarious (but very wrong) results.

How can I fix this issue, or, more importantly, how can I attain such an effect properly?


I used your approach and refined it somewhat: I generate two different hexes via subshaders, one of which is offset by 0.5/0.5


main shader

I had to add X and Y stretching to the subshader because it is stretched weird, I assume it’s because polygons are calculated with outset circle. The values for stretching are also only approximated because I was too lazy to do the math. With a little bit of brains you could probably calculate those and have them pixel perfect