I'm trying to create a continuous output of light from an object (like the exhaust of a space ship), and I thought I'd use particles to achieve this. But I'm running into a problem with alpha blending.
I'd like to decrease the particle system's alpha over time, but because there's such a high density of particles, they end up evaluating to a solid color for most of the system's duration.
This blog post basically shows what I'm trying to achieve: https://mispy.me/unity-alpha-blending-overlap/
The idea is to use a stencil test to make sure pixels in a sprite/particle aren't gone if they're overlapping another sprite/particle.
Pass
{
Stencil
{
Ref 2
Comp NotEqual
Pass Replace
}
}
Then the author adds an alpha cutoff to make sure transparent pixels on an underlying sprite don't prevent new pixels from being written.
half4 frag (v2f i) : COLOR
{
half4 color = tex2D(_MainTex, i.uv);
if (color.a < 0.3)
discard;
return color;
}
But this solution requires you to eliminate soft edges, so I'm thinking it wouldn't look good in a particle system. The author also hinted at an alternate solution involving ZTest, but I can't visualize what that would be.