Search Unity

Need More discreet stencils (or other solution)

Discussion in 'Shaders' started by Captaingerbear, Oct 22, 2021.

  1. Captaingerbear

    Captaingerbear

    Joined:
    Mar 6, 2013
    Posts:
    57
    I'm working on trying to get some special effects animations merged into my sprites individually. I've never really messed with the stencil buffer before so it's entirely possible I'm missing something obvious, or that the stencil buffer isn't the proper solution for this, but it's the closest I've managed to get so far.

    You'll be able to see from the attached sample that I've managed to get the particle effect to mask to the sprites. If the particle emitter is further back, it will correctly apply to only the more distant sprite, but I need an option for having the effect limited to only the frontmost sprite as well. Ideally, I would like to be able to limit the masking so that only an extremely short distance between the sprite and the particle emitter would be visible, but other solutions are certainly welcome.

    The hope is that I can have a dozen or more sprites on screen, which may or may not be overlapping, and apply various special effects to them individually and simultaneously to represent things like status effects.

    Thanks in advance StencilBufferExample.jpg
     
  2. Captaingerbear

    Captaingerbear

    Joined:
    Mar 6, 2013
    Posts:
    57


    And naturally, just taking a break and looking at something else for a while made a big difference. I'd just delete this out of embarrassment but maybe someone else can benefit from this. I disabled the stencil buffer in my shader altogether, and added a sprite mask component to my particle system.

    SpriteMaskInstead.jpg

    This will require a little bit of extra work to make sure that my sprite mask updates along with my animations, but the effect is now limited to one and exactly one sprite.