Gradient in world space

How do I create a gradient mask from lowest vertex to the highest vertex of my object that does not rotate with my object.

I was thinking of using one channel from world space position and somehow dividing it with my object space but I am not getting the result I need.

I searched the forums and found someone with the same question but the awnser was an image that sadly got deleted.