Hi everyone,
I’m working on a game where I have ‘shadows’ made of semi transparent sprites. The game has a day/night cycle and as such the sprites rotate and scale constantly based on the time of day. Their alpha is also calculated against the time of day and changes constantly too. This is all working really well except if shadows overlap, as you’d expect, both semi transparent sprites are visible. I do not want them to blend like that.
The problem:
The desired result:
(I simply turned the sprite renderers off to demonstrate)
The general idea, which does not work on my shadows, seems to be:
-all shadows need to use the same material and shader.
-said shader is a copy of sprites/default but uses stencil to do something like:
Stencil {
Ref 2
Comp NotEqual
Pass Replace
}
I, however, can make this shader work fine on other objects, just not my shadows.
Eventually, I came to the realisation that it doesn’t work because the shadows also use sprite masks. I have two different types of shadows, one for the general time of day and one for reacting to close light sources, and I use masks to make them visible and invisible respectively (i.e. in close proximity to a light source, you cannot see the ‘time of day’ shadow but can instead see the shadow rotated inversely from the light source, such as a camp fire). It unfortunately means I can’t not use sprite masks and mask interaction.
I assume, therefore, that the sprite mask is making use of the stencil buffer, and I’m essentially trying to do two things at once. If I change the mask interaction on the shadows, I essentially turn the shadows into sprite masks. Not what I want.
TL;DR
Is there any way I can use the Stencil buffer and sprite mask interaction of a sprite renderer on the same sprite?
OTHERWISE:
I have seen it suggested I could make a separate camera that only renders the shadows, put them into a render texture, run a shader or some sort on that (I guess test if alpha > x and then if so lower to x?) and re-render that, so they are all one blob? This might even run faster, but I have no idea how to do it and can’t find any documentation that explains any of it.
If anyone can shine some light on this (because, you know, shadows…) I’d be more than grateful