Transparent sprites have incorrect depth sorting from one direction

Hey everyone, I’m working on a 2.5D game that uses 2D sprites for characters and small objects, and 3D meshes for geometry. I have a perspective camera that rotates around the map at a locked downward angle.

In the process of setting up my scenes, I’ve noticed that transparent sprites in Unity have their backfaces drawn (Cull Off) and seem to sort depth correctly from the front, but when viewed from behind their sorting is reversed, drawing the furthest sprite from the camera on top.

You can test this out yourself simply by dropping a few Sprite objects in a scene and assigning them a texture with transparency, then lining them up front to back and rotating the camera around. Here’s an example using the default sprite shader and some sprites from Disgaea:

Is there something I can set in my custom shaders to correct this behaviour? I’ve tried switching to a cutout shader, ZTest options, disabling and enabling batching, and of course using other shaders - but so far no dice.

I can’t assume the sprites will always face the camera even with a billboarding shader, because they’ll still invert when I flip them with the animator toggle to face different directions. Is there some way I can simply set all instances of this shader to render in order of their distance from the camera at all times?

This sounds like something is setting the camera to use a custom axis transparency sorting order.

Make sure that’s set either to default or maybe orthographic. Also make sure the sorting order isn’t being set on the sprites.

Ah, you’re absolutely right! For some reason my scene was set to use custom axis transparency and I never noticed. Using default the sprites sort by distance to the camera, and everything behaves as expected.

Thanks so much for your help on this and the billboarding shader - my project’s looking a thousand times simpler to develop for because of it!