Passing information about another object into OSL shader

Hello,

I am trying to create a shader that darkens an object based on its distance to one and only one other object (closer = darker).

I suppose this is sort of like Ambient Occlusion where a trace is used to detect presence of other objects, but I want to do this specifically for one ‘reference’ object and not other ones.

The end-goal is to create a weathering look for a cube that is inserted into a plane. The grunge on the cube gets darker as you get lower, closer to the ground.

Any idea how to do this? Not sure if OSL can do this.

Thanks

I would like the same info. But I would like to have the lightvector. There is a function called getattribute(<obj>,“object:location”,<out vector>) that supposedly would get the vector to any object (?) but I don’t know how this works, because I get nothing out of this function. It seem to give me the 0-vector all the time.