- Home /
Sprite Decal Blending At Same Z Depth
I want to have some important objects in my game have an effect where a "sheen" flickers across the object to draw the player's attention. I need the effect to be as simple as possible; no second sprite, no animations. What I'd like is a shader that renders the sprite like normal with a decal texture on top. I modified the default sprite shader to add the decal in the frag method, but I couldn't get the tiling/offset to be applied as well and it didn't work with sprites on larger sprite sheets. I've instead added a second pass to the end of the default sprite shader that blends the decal onto the texture:
Blend SrcAlpha OneMinusSrcAlpha
Pass {
SetTexture[_MainTex] { Combine texture }
SetTexture[_DecalTex] { Combine texture, previous * texture}
}
This almost works how I want it, but it doesn't work properly if 2 sprites share the same depth. The additive decal texture is drawn on top of both sprites at that depth. It works fine if sprites are at different depths or have a different Order In Layer which shouldn't be too much of a problem, but I'd still like to see it fixed in case some sprites do overlap at the same depth for whatever reason.
It also applies the decal based on the sprite's position on the sprite sheet, instead of using it's own decal UV. This becomes a problem when the sprite is positioned lower on the sprite sheet. Not much of a problem, but still a problem.
Is there a way to get a sprite with a decal texture or otherwise restrict the blending to only blend on that sprite? I'd also like to keep the decal on it's own UV.