SceneKit shader modifier: accessing coordinate and colouring the geometry

Source: ios – Accessing z-coordinate in world space in shader modifier SceneKit – Stack Overflow