3
\$\begingroup\$

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/

non-blended overlapping sprites

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.

\$\endgroup\$
  • \$\begingroup\$ Please add the relevant part of what's on the linked page here, as if the link becomes 404, your post will not be understandable at all. \$\endgroup\$ – Vaillancourt Jan 4 '17 at 14:34
  • \$\begingroup\$ You might want to consider using a TrailRenderer or a volumetric effect here, rather than stacking many many particles. Not only does this give you more control over the final colour in the highest intensity region, it also reduces the amount of overdraw, improving rendering performance. As-is, this question might be an XY problem. I'd recommend editing the question to something like "How can I control the brightness of my engine trail effect" and include screenshots of your current result (and optionally, mock images of your target result) \$\endgroup\$ – DMGregory Jan 4 '17 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.