Have you tried enabling Write to Depth
and setting Depth Alpha Cutoff
to 0.0001
? This results in nice blended results with no jagged borders (because the cutoff is set to "only discard when alpha <= 0.0001") while still rendering the whole sprite to the depth buffer:
Magnified view of the Hero character. Enabled depth write provides the correct depth value for the camera blur effect.
[Edit:]
Note however that when you use a blur effect and have multiple sprites layered behind each other, then by design you will have problems in non-cut-off areaswhen setting the cutoff threshold to 0.0001
- then a nicely alpha-blended 95% transparent black pixel will receive 95% of the background color, and thus the background pixel will be perfectly sharp (non-blurred) when the character is in focus, where it should be blurry instead.
Some background pixels around the border wrote to character's depth since they were not discarded at 5% opacity - hence they are not blurry but as sharp as the character.
In this case you cannot handle this in a single render pass - that's where you need the two different alpha cutoff thresholds:
1) one that is low enough to not discard the transparent pixel in the first pass, and then
2) another one at e.g. 0.5 that blurs everything that is mostly transparent and therefore shall count as background.
This case is where the camera.RenderWithShader()
replacement shaders come in handy, since they can render another pass just to write different depth values.