Changing the color at the intersection of the object

Hi everybody!

In my project, I am trying to make a material color change when an object intersects with another object with the same material.

As an example: current material and what I want to get

Do you have any ideas or ready-made solutions?