Smooth 3d gradient pattern

Instead of calculating the distance to the boundary, you can get the distance to a surface above your pattern.