Is it possible to fix the Transparency + Depth sorting issue?

Order Independent Transparency (OIT) is the search term you’re looking for.

To do accurate per pixel transparency sorting is extremely expensive to do on modern graphics cards, though it is possible. To do it in Unity would require essentially not using any of Unity’s built in shaders, and possible not use any of Unity’s built in renderer components. Pretty much no one does this outside of some tech demos and specific applications, these days it’s probably cheaper to “just” do GPU based raytracing … but that’s even more work to implement.

There are approximated OIT techniques that have gained a lot of popularity. They aren’t perfectly accurate, but they’re usually good enough that with out knowing they weren’t accurate you wouldn’t be able to tell the difference. Weighted Blended Transparency is one that a few people have released free basic implementations of, like here:

Another option is to abuse alpha to coverage / alpha to mask and MSAA, but it requires more than just turning it on (which is fairly easy, just make a new shader and add AlphaToMask On) as you need to manually control the mask bits so overlaps show. It also make transparency aliasing worse as it works by abusing MSAA samples.

The “Pre-Z” option @jvo3dc is suggesting can solve the issue, but it’ll also make your objects not look transparent as you won’t be able to see them through each other.

The easiest solution would be just use a blend mode that does’t require sorting, like additive.

5 Likes