I have a weird thing happening in my project. Certain gameojbects are not being rendering correctly (sometimes).
Certain gameobjects are appearing in front of other gameobjects even though they are actually ‘behind’ them.
It only seems to happen when the objects closer to the camera are alpha shaded. When I change then to a non-alpha shader, the further away gameobjects are no longer visible.
It’s like the alpha channel isn’t working. As if the entire object is transparent. But it isn’t… this problem only occurs when I stand at certain places.
This is a classic problem with transparent objects, and to this day no plausible solutions exist. Most people avoid transparent objects; or make sure they are of not-too-different sizes, or not-too-different colors so that the sorting problem is minimized.
Most of the sorting problems in your case could be solved by using an alpha-tested shader instead of transparent one (for example VegetationTwoPass on unify wiki). Then the opaque parts would be always correct.
As for performance: the VegetationTwoPass is a two pass shader, so all objects are drawn twice. You can try removing the second pass (but then you’ll only get fully opaque or fully transparent objects, no fading-out outlines).
The thing with transparency: in order for transparency to work correctly, surfaces that are further away need to be drawn before surfaces that are closer. In Unity we sort transparent objects back-to-front, so if the objects are of similar size and not intersecting with each other, then everything’s ok.
In your case, however, there’s no way to sort the objects as they are intersecting each other. Unless you’d split the objects into many small ones (which would kill performance).
Alpha-testing does not do transparency, it simply discards pixels that are below certain level of alpha. Thus it can be written to depth buffer and drawn in any order, the result will be correct. The downside is that there’s no semi-transparency - the rendered pixels are fully opaque, and the discarded ones are not rendered at all.