is it possible to change a material depending on whether it is intersecting with another object? Let's say I have a sphere, halfway intersecting with a cube(which is invisible to the camera). I want to change the material of the part of the sphere that is intersecting with the box, similar to this image:
An update, thanks to moonboots comments:

It is possible using Cycles:



The shader simply tests if the transparent depth is at least 1 as the cube is transparent but also we don't want more than one (as if not the cube shape may appear in non ortho views):