Change Material based on Meshes Location

Hey there

So, for a University Project in Enviroments, we were tasked with using a technique most useful to our scene and since im creating a library i thought the idea of moving books around the editor and them changing materials as they move would be really interesting. I came up with this idea after looking at the material created by Maxim Dorokhov’s Wile West Challenge enviroment. I tried and tested this but just cant seem to figure out how to get this to work. Any help will be awsome and will credit all assitance in my report. Thanks a bunch :).

Examples:

Bottle Changes:

Book Changes:

The material node is called World Position:

Image from Gyazo

You will need some clamps and a bit of math to make it look right.