Render Order
Rendering is the process of converting the 3D world into the 2D image that is displayed on your monitor. The 3D world is made up of triangles which are drawn to this image one after the other—the order in which they are drawn is the render order.
Triangles are drawn in batches called "draw calls" where all the triangles have the same material—each material in a mesh file is drawn in order, triangles with the same material remain in the same order as in the mesh file. Each mesh file is rendered in the order that it is defined within an asset's config file. The assets are then rendered in creation order (the first vehicle to be spawned is rendered first, and so on) within the following groups:
- Skybox, sun, moon, stars, etc.
- Objects with
rendertypepresurface - Terrain
- Objects with
rendertypesurface - Splines
- Objects with
rendertypeon_surface - Wet road effects (both puddles and moisture)
- Objects with
rendertype1 - Objects with
rendertype2(normal objects) - Objects with
rendertype3 - AI vehicles, and the user vehicle when it is viewed from outside
- Objects with
rendertype4 - User vehicle from the driver or passenger view
You can choose which rendertype an object uses with the [rendertype] keyword.
As each triangle is drawn to the screen one after the other, the game also keeps track of how far away from the camera each screen pixel is, such that triangles that are further away from the camera don't overwrite and appear on top of surfaces that are closer. This works great for opaque surfaces, but not as well for translucent surfaces which prevent the drawing of further-away triangles that are rendered after them even if the triangles should be visible through the translucent surface. For this reason it is important to consider the order that triangles are rendered, and is why this wiki page exists.
Triangles are translucent when their material is rendered with "blend" alpha (see [matl_alpha]), regardless of the opacity of the texture at any given location.
When to use which rendertype
presurfaceis useful for objects that have some part that is underground but not accessible to the player (for example the subway entrances in the default Berlin-Spandau map)—a transparent-textured translucent surface just above the terrain prevents the terrain from rendering without actually cutting a hole in the terrain geometry.surfaceshould be used for all road surface objects (junctions).on_surfaceshould be used for all objects that sit on the road surface, like road markings.1is not used by any default object.2is the default value, there's no point setting it manually.3should be used for objects with translucent surfaces through which other objects need to be seen, but not vehicles.4should be used for objects with translucent surfaces through which AI vehicles need to be seen—the object will not be visible through the windows of AI vehicles.