Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.

    Read our full announcement for more information and let us know if you have any questions.

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


    Nov 11, 2020
    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:

    And yes, I have seen this and other related posts:

    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!