Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Using stencil buffer to hide sections of transparent sprites based on sorting order

Discussion in '2D' started by Bjornthefire, Oct 17, 2023.

  1. Bjornthefire

    Bjornthefire

    Joined:
    Nov 11, 2020
    Posts:
    1
    I've been trying to crack this all day, spent a lot of time experimenting with the stencil buffer and while I was getting some interesting behavior, I was not getting what I intended.

    I would like to be able to hide the sections of the sprites that are behind the other transparent sprites in their sorting order.

    I tried a bunch of stuff, and ended up with a similar issue as seen here: https://www.reddit.com/r/Unity3D/comments/he8g81/transparency_on_a_sprite_rig/

    And yes, I have seen this and other related posts: https://gamedev.stackexchange.com/q...for-a-sprite-that-ignores-transparent-sprites

    The shader basically works...but in reverse, so it happily draws the lower layers on top and hides the upper layers where there is overlap.


    Figure this would be a common problem for people using a sprite rig--anyone have any ideas? Ideally would be able to use one material for all the sprites!