0
\$\begingroup\$

I know how to use SpriteRendere's Sorting Layer and Order in Layer. But how do they actually work under the hood? How the render pipeline gets this information? Is there a "sprite sorter" to sort all the sprites before rendering every frame? Or are the mesh's Z changes? Or the sorting layer info is written to z-buffer for alpha blend?

\$\endgroup\$
1
  • \$\begingroup\$ You can confirm it's not Z because sorting layers and Z sorting interact. You can confirm it's not the depth buffer because it works with partial translucency. So, doesn't that just leave the option listed right in the name: they're sorted for rendering order? \$\endgroup\$
    – DMGregory
    Nov 17, 2022 at 13:04

1 Answer 1

1
\$\begingroup\$

Answered from Unity staff:

Before rendering, all the renderers are sorted in order before they are rendered. For renderers in the Transparent Queue, they are sorted using the Sorting Layer and Order first before the other criteria (See https://docs.unity3d.com/Manual/2DSorting.html). The sorted renderer list is then passed to the render pipeline for batching and rendering. The sorted renderer order is not written to the Z-buffer.

All renderers do have a Sorting Layer and Order in Layer, even if you may not see it in their respective Inspectors (See https://docs.unity3d.com/ScriptReference/Renderer-sortingOrder.html). You could use that to order your Renderer if you are not using a SpriteRenderer.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .