Using a sprite as a mask in a shader

Godot Version

Godot 4

Question

`Hi, I am trying to solve a problem I have with shaders but I am unable to do it. Here is what I want:

Two Sprite2D nodes. I want one of them to only draw pixels that are in contact with the other sprite. For example: If the nodes are not in contact, that it is not drawn, and if half of the sprite is touching the other one, that only that half is drawn.

I don’t want to do it with collision boxes because I want it to be pixel perfect and to catch the alpha of the other sprite.

That is, to use the sprite of another node as a mask.

I have tried in the shader to access the sprite of the other object to multiply the COLOR by the alpha, but I have not succeeded.

Any idea how I can do it?