When we render a mesh we perform a draw call, we send a pack containing a mesh and other info to the GPU and tell it to draw, the first item sent get drawn first.

Untitled

It goes trough the scene hierarchy from top to bottom.

Then unity will check each object distance from the camera.

Painter’s algorithm

This algorithm is basically used to paint the polygons in the view plane by considering their distance from the viewer. The polygons which are at more distance from the viewer are painted first. After that the nearer polygons are started painted on or over more distant polygons according to the requirement.

Draws the meshes back to front.

Painter's Algorithm in Computer Graphics - GeeksforGeeks

Render order

0-5000

Queue tag Range start Default value Range end
Background 0 1000 1499
Geometry 1500 2000 2399
Alpha test 2400 2450 2699
Transparent 2700 3000 3599
Overlay 3600 4000 5000
//Unity tagging in shader
"Queue" = "Background" = 1000
"Queue" = "Background+1" = 1001
"Queue" = "Background-100" = 900

Sorting

Mode: Depth-sorting/Z-sorting

Untitled

The sorting solves the problem of mesh overlapping, before rendering the mesh the distance from the camera is stored and compared with the other meshes info, the closesest to the camera is rendered to the pixel and the rest is discarded (this is when we have opaque materials).

00_priority.jpg

Rendering order and Z-sorting

Blending