Can I detect location of other mesh or surface from Material?

Hello everyone!

I placed square shaped roof like below image.
But when camera is at the below of roof, I can see edge of roof block in the red circle at the below image.

And I wanna hide those pixels where other roof mesh is placed above that pixel by using opacity mask.

So can I detect other mesh or surface above some absolute world position in material?

Any comments will be helpful!

Thanks and have a nice day!