How can I get the portion of a texture that overlaps a sprite?

I’m trying to get the part of that grey area that overlaps with the red sprite. I’m doing this in shader graph.
What I’m trying to do is have these sprites be masked in by the render texture which captures a layer dedicated to masks.

It’s for a blood effect, so if a guy dies they’ll leave a mask behind and the render texture will capture that. The sprites using the material will use that render texture to reveal overlapping parts of itself.

I know there’s sprite mask components, but they either reveal or don’t, they don’t have alpha.

I have already done the masking thing with render textures but it was for a texture that completely overlapped the render texture.

The reason I’m trying to have it work with sprites now is because my game is top down and I want blood to be able to splat onto walls and props. For that I need the blood to obey sorting order rules.

(the texture mentioned before was for the ground, so things are always on top of it)

So basically I thought I’d have these objects have a duplicate version of their sprite but only blood. This would be masked in by the render texture. This is only for unmoving objects.

Im not sure if this is possible, in my brain it seems like it should be but I’m a bit of a shader noob.

I think I’ve got a solution now, I’ve made a script that creates a runtime material that inputs a bunch of the sprite information into some maths involving it and the render texture, then that information is fed into some parameters of the material. In the shader those parameters are used to control the tiling and offset of the render texture. I’ve not tested it yet, but I think I know what I’m doing now.


Edit

199223-camera.png

That’s the maths i used, pretty sure i have it working now.
If anyone else is looking at this you should be aware that in my game I’m abusing the fact the camera doesn’t move to make this work. Not that it’s impossible to do otherwise.