Cover overlay sprites with geometry
I am making a game with sprites in a 3d environment. I'm using a perspective camera at an angle similar to something like animal crossing.
Some sprites need to render in front of anything they are clipping with, such as a wall or the floor, but also properly draw behind 3d environment like a wall.
Here is an example where the sword sprite shows the issue.
The sword is clipping through the wall here but drawing as an overlay to prevent the sprite from visually clipping through the wall.
The sword still drawing over the wall even when behind the wall.
(The sword needs to behave like the player sprite when actually behind the wall, otherwise render above the wall to stop the sword from clipping through like a default sprite)
I have tried manually changing the sorting order of the wall material which somewhat works but is expensive and only works for the one sprite it is referencing. Other problems come from changing the sorting order, breaking projectors and other sprites so I am trying to find a solution which ignores sorting order.
I need a shader or some sort of mask which can cover an overlay sprite only while the sprites z position is behind the material. I'm open to other solutions as well.
Anyone who can help is super cool , thanks.