Search Unity

2D stencil light without alpha clip

Discussion in 'Shaders' started by Glaswyll, Dec 12, 2018.

  1. Glaswyll

    Glaswyll

    Joined:
    Feb 13, 2014
    Posts:
    103
    I have a custom shader that is mostly working well, but one feature eludes me. I'm trying to figure out how to add 2D "lights" using radial gradients as a kind of point light. The blending looks how I want it to look with the exception of covering the nearly transparent parts of the sprites behind the "light" sprite.

    Here's what it looks like right now:
    2d-sprite-light-test-01.jpg

    I'm using a stencil to clip the radial gradient sprite within the bounds of the ground sprite behind it. I'd like it to blend smoothly with the transparency of the sprite behind it. I don't want to use alpha clip + discard in the fragment function because some of the sprites being "lit" have soft transparency falloffs that I need to keep.

    I'm fairly new at shader writing, so rather than solve it for me, I'd prefer information about the technique if it's possible.

    Thanks in advance!