So the idea is to use the Light Path node's Ray Length to form the basis for ambient occlusion but the Camera position relative to the object is a part of the Ray Length info and this makes such a calculation difficult since this alter the results based on how far a specific position is to the camera.
Here is a demonstration of what I mean.
Here's a node setup that shows this effect.
For AO to work, this effect has to be cancelled out since the dirt and grime which tends to accumulate in crevices will not be affected by how far the viewer is from the object.
So my question is this. Does anyone have some ideas on how to remove the camera influence from the Ray Length result?