Is DistanceToNearestSurface bug?

Hi everyone!

So I was trying to create a mask that when the material touches something else in my world, it will be transparent the zone where they are touching and I thought that the DistanceToNearestSurface would be the best option.

It turns out it isn’t. For some reason it doesn’t render correctly the material and the final result it’s not the best.

Did I do something wrong? Or there is another method to do this?