Last week we talked about how Level of Detail (LOD) is being updated to allow content creators to get the most efficiency out of the engine. While adding LODs will reduce the polygon count of your scene, and there are other factors that impact performance. So this week we’ll review how to optimise your content to avoid excessive Draw Calls.
What’s a Draw Call? Basically a Draw Call sends all the information about the textures, materials and shaders to the graphics engine. There is an overhead associated with each call, so the lower the number, the better.
Each time a new material is used in your mesh, it potentially costs another draw call (unless it is a shared material but we will get to that later). The more draw calls the engine has to perform, the more likely you will reach a “bottleneck” and performance will suffer.
It is also worth noting that the benefits of reducing draw calls decreases as polygon count increases. In fact, you can’t have a 100k mesh with a single draw call – the game won’t allow it.
Materials define what is rendered onto the mesh. Each material consists of a material type, textures, and other configuration settings. If you change any of these settings you need to use a new material.
We have many material types in Trainz right now, and we’re expanding that set with the new “PBR” materials for the next Trainz product:
For the example below we will use a new PBR material – m.pbrmetal.
Here you can see that our material is made up of 3 textures. (See this link on Material Typesfor more detailed information)
We applied this material to our mesh (in this case a cube) and now, if we render that in-game it will have a single draw call as we have exactly one material being rendered.
Now we’ll go ahead and add another material on one side of the cube:
You can see in-game it is now costing us 2 draw calls as we have now applied 2 materials to the mesh:
NOTE: Trainz utilizes a system called “Mesh-stitching” which allows certain meshes in a scene that use the same material to be stitched together. There are certain conditions to determine whether assets will be included in the stitching process. You can read more about mesh-stitching here.
When multiple mesh files in a single asset use the same material names, these materials are “shared” between the meshes. This increases efficiency by allowing mesh-stitching between the various meshes and reducing the number of draw calls. Without shared materials, each mesh could stitch individually but not against other meshes. Even where mesh-stitching isn’t applicable, there are some efficiency gains by using multiple instances of the same material rather than using multiple separate materials.
In the next example I’ve taken a cube mesh and a sphere mesh and applied the same material to both meshes. As you can see when rendered in Trainz, there is still only 1 draw call because both assets (or meshes) are sharing the 1 material.
With “Performance Stats” enable in Surveyor (Settings -> General Settings -> Show Performance Statistics in Surveyor) we can see that Stitched Materials = 1, meaning only one draw call. Remember, this only works if the meshes pass a set of conditions outlined in the mesh-stitching Suitability section.