i'm trying to get some sprites to render over this shadow

Hey, i’m recording my 2D game on a rendertexture, i have a fake shadow that is rendered over this rendertexture, i’m trying to get some sprites to render over this shadow, but behind some other sprites that are behind this shadow, for example glowing eyes behind moving bushes, the bushes should be rendered behind the shadow texture, but in front of the glowing eyes, the glowing eyes should be rendered over the shadow texture.

I’ve used a copy of the sprite as an alpha mask to make holes in the shadow but it will also make holes in the shadow when they’re behind other sprites so it doesn’t look good.

Here’s a visual example, the right of the image is darkened by some shadows, the red dagger would be darkened by the shadow but i want it to appear like it is glowing, so it has a second sprite that acts as an alpha mask and cuts through the shadow, but when the dagger goes behind an object like in the image it also cuts through the shadow which i don’t want. This method doesn’t work, i want the dagger to be rendered over the shadow but behind the object in the image.

Some help would be really appreciated!

What if you render everything first. Keep a separate shadow mask channel.
Do your normal drawing of objects with the correct sorting. Knife behind bushes.
But you need to write to the other channel which pixels should be shadowed.

So if there is nothing in front of the dagger it’s shadow mask will be in the shadow mask as no shadow.
But If the bush in front it will write overwrite the daggers shadow mask with its bush mask of in shadow.

Then composite your shadow using this mask to control visible or not.

How you do this will depend on how you are drawing. If you are using depth or just draw orders etc
But basically every object would have a shadow mask. Either on or off. So if something is in front of an off it will become an on.

So basically just like you draw your normal colors you would keep the shadow mask the same way.

Tanks for answering, got my other post deleted by a mod so i decided to delete this one as well and move on to Unity Answers instead, but yeah, what you describe is the only solution i had in mind, i was hoping for a simpler alternative since i didn’t want every sprites to have a mask, this really complicates things but maybe it’s the only solution.

Really appreciate the suggestion!

They don’t have to explicitly have a mask. You can encode something in the alpha or other existing data.
Set a flag before drawing, shader etc. they just all need to write to the shadow mask. To keep the final state correct.

For opaque non glowing objects their shadow mask would be the same as any pixel that is drawn.
So no extra data is needed. The shader just would need to write to the shadow mask at the same pixel locations.

For glowing objects you might need an extra mask or embed it into the alpha.
For example maybe something like if 0 - .5 is normal transparency and .5 - 1 is glow.
You can reconstruct these values in the shader.

Or break it into multiple pieces depending on your level.
Dagger and dagger glow. And just change the shader for each one.

Good luck

Just to make sure that we understand each other, here’s how my setup works in detail:

Game rendered on main render texture, “Mask” layer sprites (black) rendered on other render texture against white background, a quad has a shader which blends between the main render texture and a black color using the mask render texture as the lerp’s alpha and that quad is recorded by final camera for output to monitor.

In my scene i can have any sprites use the layer tag “Mask” (only thing recorded by the masking camera) and make “holes” in that black color (shadow) to reveal the main render.

My solution was to have that dagger have a second identical sprite but completely black and set as a “mask”, so that it would make a hole of the shape of the dagger in the shadow layer allowing it to have a lower depth than the shadow layer but still cut through it, but once behind other sprites it would still cut through it so i thought about giving those other sprites a second identical sprite but completely white set as a “mask” and rendered over the dagger’s mask.

It works but every sprites would need to have a mask.

I had to undelete your original post so the thread would make sense. We don’t delete posts with replies, and that’s the rules moderators were given. Thanks for understanding.

I also locked this thread as you are clearly done with it.