• Register
Post tutorial Report RSS Optimize your games reducing draw calls

What Draw Calls are? A Draw Call is nothing but a call given by the CPU to the GPU, to render a mesh. After the call, the GPU takes all the information about materials, textures, shaders, etc. and converts them to (hopefully) beautiful pixel on your screen. Each mesh with a different material requires a separate Draw Call.

Posted by on - Basic Client Side Coding

How Draw Calls affect my game?
I’m goingo to try to give you an example: Let’s create a simple UI with different sprites inside.

Like this:

Draw calls 1

As you can see, it’s simple set of icons.
These are the sprites I have used:

Draw calls 2

Let’s check the Draw Calls. Play and click on "Stats" in the upper right of the Game window.
We have to take into account “Batches” value. In this case we have 15, let's keep that in mind. The lower this value is, the lower the Draw Calls.

Draw calls 3

Now, what 's the right number of Draw Calls for my game?

This is heavily dependent on our target hardware. Imagine a scenario where the Draw Calls have to deal with hundreds of meshes. Obviously, reduce the number of Draw Calls will reduce the overhead of the GPU.

A modern PC can handle, approximately, 500-5000 Draw Calls for frame. A smartphone, on the other hand, can handle 40-60 Draw Calls. You can push the limit to 120-160 with the latest smartphones models in mind.

If the framerate is stable, there is no need to worry of Draw Calls. However, reduce the number of them will improve the uploads and will stabilize your game.

What 's the solution?
Fortunately, Unity provides a handy tool to help us, the Sprite Packer

The Unity official document reports:
“For optimal performance, it is best to pack graphics from several sprite textures tightly together within a single texture known as an atlas. Unity provides a Sprite Packer utility to automate the process of generating atlases from the individual sprite textures."

Ok, now let’s join the sprites used in the example in one Atlas.

Select all the sprites that we want to join - ideally we have to all the sprites of the same screen in a single Atlas.
Assign the "Packing Tag" in the assets importer.

draw calls 4

Now, open the Sprite Packer (Window -> Sprite Packer) and click on Pack. The tool will now unite all the sprites of our project in a single Atlas, dividing them Packing Tag.

draw calls 5

Play!
Can you tell the difference?
The number of Batches is considerably reduced!

draw calls 6

In this case they have been reduced from 15 to 3 Batches!

This means less weight on the GPU and that CPU is available for other operations. It’s more important when we are working for a smartphone game. For example, reduce Draw Calls from 800 to 300 could be a great boost!

When we work on 3D models, we can optimize the Draw Calls using the less materials and shaders is possible and join the meshes in individual models. There are many external tool to help us in this, one of these is Mesh Baker.

I hope this guide will be of help to optimize your games. For any questions or info please leave a comment below, we'll answer as soon as possible!

See you soon Devs!

Riccardo

Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Tutorial
Tags
Coding, Unity 5
Browse
Tutorials
Report
Report
Share
Related Groups
LEAF games & software
LEAF games & software Developer with 2 members
Unity Games
Unity Games Hobbies & Interests with 1,807 members