Quick backstory: I'm attempting to create a character similar to those in Paper Mario: Thousand Year Door which are essentially individual sprites that overlap and are animated in a 3D world. My issue is that when using SpriteRenderers in 3D, sorting issues occur (due to Unity using the sprite's origin for depth checking, rather than the whole sprite using the Z buffer, from what I can tell). I attempted to solve this by modifying the Sprites-Diffuse shader to ZWrite On, but that resulted in transparency bugs as illustrated here: https://gfycat.com/ThatSlushyDwarfrabbit I'm a relative newbie when it comes to shader writing and as such I can't figure out what I need to do to get both correct sorting and no transparency issues at the same time. Any help would be appreciated.
Have you tried setting the transparency sort mode of the camera to TransparencySortMode.Orthographic? https://docs.unity3d.com/ScriptReference/TransparencySortMode.html
That's odd - we're positioning 2d sprites in 3d space and don't have any sorting or transparency issues (although we're not using the default sprite shader), and I've never heard of your hypothesis that Unity sorts the entire quad mesh based on only the position of the origin. Are you using forward or deferred rendering?
Currently using forward rendering, though theoretically deferred should work as well. I won't be able to test it for a while unfortunately, but I'll report back if it has any effect once I do. Also, the origin sorting theory I got from doing a few Google searches; it may be incorrect, but it supported my observations so it seemed likely.
Unfortunately it appears the results are identical in both forward and deferred rendering (at least, it's consistent). If it helps any, here's a slowed-down recording of the current behavior in the editor (which matches what's seen in-game): https://gfycat.com/CoolAdvancedDonkey
@GuitarBro Sorry for the 4 year later ping, just wondering if you found a good solution to this? Currently I'm planning on converting the sprite renderers in my project to mesh renderers, with uvs indexing a texture atlas on a shared material. Would be cool if there were a simpler solution though if you've found one.
Yes, actually. Use the Sorting Group component on the root gameobject, then specify the sorting layer and order in layer for each sprite which will now be relative to the sorting group.
As in you put it on a root game object for the whole scene? And that fixes Unity using the sprite origin depth checking?
Oh ok, yeah the issue I'm experiencing is specifically sorting 2d sprites in a 3d scene (that also has 3d objects), and making sure transparency works between those two types of elements. So I guess it's not quite the same issue. Thanks for the quick responses though!