- Home /
What's the order of events in Unity's rendering pipeline?
So lately, I've been getting into shader writing, and have been beginning to use CommandBuffers. But I would like to know: what things happen and in exactly what order when Unity is rendering using Forward Rendering and Deferred Rendering?
For example, I can make a CommandBuffer execute right after my camera renders the skybox. But I'm not sure if the skybox is rendered before the geometry, or before/after lighting, (or like when does shadow stuff happen?) etc. It would be helpful to have a visual/diagram of the order of these things -- I looked a lot in the Unity manual but couldn't find a concrete order of it for each rendering path, or maybe I just missed it though :p.
Found this page I assume? Good pic showing the pipline order of the various CameraEvents used by CommandBuffers. https://docs.unity3d.com/$$anonymous$$anual/GraphicsCommandBuffers.html
Ah yes! Thank you, this was actually one of the pictures I've been looking at xD but it does help.
Answer by Bunny83 · Dec 18, 2017 at 04:41 AM
The whole rendering process is very complex and not well documented. However the usual skybox is actually rendered after the opaque geometry to avoid overdraw and to keep the fillrate low. The skybox is usually drawn where the z buffer still has it's "cleared" value. Well, at least that's what seems to be the case in almost all of my tests.
In general the materials are rendered depending on the render queue value which is a value between 0 - 5000. Some predefined values are defined in the RenderQueue enum.
public enum RenderQueue
{
/// <summary>
/// <para>This render queue is rendered before any others.</para>
/// </summary>
Background = 1000,
/// <summary>
/// <para>Opaque geometry uses this queue.</para>
/// </summary>
Geometry = 2000,
/// <summary>
/// <para>Alpha tested geometry uses this queue.</para>
/// </summary>
AlphaTest = 2450,
/// <summary>
/// <para>Last render queue that is considered "opaque".</para>
/// </summary>
GeometryLast = 2500,
/// <summary>
/// <para>This render queue is rendered after Geometry and AlphaTest, in back-to-front order.</para>
/// </summary>
Transparent = 3000,
/// <summary>
/// <para>This render queue is meant for overlay effects.</para>
/// </summary>
Overlay = 4000
}
Lower values are rendered before larger values. The Skybox seems to be drawn at 2500. So if you draw something at 2500 it seems to be "behind" the skybox while 2501 is drawn "infront" of the skybox (so it's drawn after the skybox).
Though certain named / tagged shader passes might be run explicitly by Unity
Ah I see, thank you! :D
By the way, do you happen to know where the shadow pass fits with all of that too? (I apologize for all the questioning, I'm trying to understand the order of events based on this page on the CameraEvent enum in the reference: https://docs.unity3d.com/ScriptReference/Rendering.CameraEvent.html)