Stretchable gradient effect


I would like to apply stretchable gradient effect over all the rocks in my scene. I managed to get somewhat similar result i am looking for but unfortunately texture there is tiled and cuts off at one point. Is there a way to have highest rock as white and lowest as black and when moved other rocks in between would change gradient values as well ( So no matter the height, gradient would not be tiled ). Any help would be much appreciated.