colour objects based on distance from camera

Is it possible to colour objects based on their distance from the camera? Like when you render a depth pass out of a 3D app.

if you don't want to use a shader and depth buffer then you can check the z of your object or the distance from local position of the camera (view point) and set renderer.material.color to something relevent.