Ways to reduce draw call in unity game
Hello and welcome, You are probably facing the high draw call issue in your game and want to reduce them, yeh you are on right place here we will explain the ways to reduce draw call in your unity game.
Well it happens whenever we create a game and we often don’t think about the performance of the game while developing it but later when we start testing it on devices then we face the performance issue in our game.
There are several reasons for the lag and when we go for Optimization then we see the different aspects of Optimization and one of the aspects is to reduce drop all so it’s very good practice to reduce the draw call in your game.
Here are a number of tips and tricks that can help to reduce the call in your game. We have given ways to reduce the draw call in your game.
What is draw call exactly?
In computer graphics, a draw call is a command sent from the CPU to the GPU to render a graphical object or scene.
The CPU sends a series of draw calls to the GPU, which is responsible for rendering the objects and creating the final image that is displayed on the screen.
A draw call specifies the necessary parameters to render an object, such as its geometry, material properties, and texture coordinates.
Why draw calls increases in games
Draw calls can increase in game development due to several factors:
- Complex Scenes: As you add more objects, characters, and details to your game scene, the number of draw calls can increase. Each object or character typically requires its own draw call.
- High-Quality Assets: Using high-quality assets with detailed textures and complex geometry can increase draw calls. Each unique material or shader applied to these assets contributes to additional draw calls.
- Dynamic Objects: Games with a lot of dynamic or interactive elements may generate more draw calls. Dynamic objects, such as destructible environments or moving characters, often require separate draw calls.
- Unoptimized Rendering Pipeline: Inefficient rendering pipelines can lead to unnecessary draw calls. Poorly optimized shaders, improper use of rendering techniques, or redundant calculations can all contribute to increased draw calls.
- Shader Variants: Each combination of shader features and properties can generate a separate shader variant, which in turn increases draw calls. Using a large number of shader variants or complex shaders can significantly impact draw call performance.
- UI Elements: Games with complex user interfaces (UIs) can generate additional draw calls, especially if UI elements are not efficiently batched or optimized.
- Lighting and Effects: Real-time lighting, shadows, and post-processing effects can increase draw calls. Each light source, shadow-casting object, or effect may require additional rendering passes and contribute to more draw calls.
- Inefficient Batching: Failure to properly batch objects with the same materials or properties can lead to increased draw calls. Objects that could be batched together are rendered separately, resulting in inefficient performance.
To address increased draw calls, developers need to optimize their game’s assets, rendering pipeline, and overall scene complexity. This often involves techniques such as mesh combining, texture atlasing, batching, LOD optimization, shader simplification, and efficient UI management. Profiling tools can help identify areas of concern and guide optimization efforts. These kind of mistake increase draw calls in unity game. Always try to reduce draw calls by using tricks mentioned below.
Steps to reduce draw call in games
Here are some steps to reduce draw calls in your games:
- Combine Meshes: Combining multiple smaller meshes into one larger mesh can reduce the number of draw calls by reducing the number of times the CPU has to send commands to the GPU.
- Use LOD (Level of Detail): LOD techniques allow for lower-resolution models to be used when objects are far away, reducing the number of vertices that need to be rendered and reducing the number of draw calls.
- Use Occlusion Culling: Occlusion culling is a technique that prevents objects from being rendered if they are not visible. This can reduce the number of draw calls by only rendering objects that are visible in the camera’s view.
- Use Texture Atlases: Texture atlases combine multiple textures into one large texture, reducing the number of texture switches and draw calls required.
- Use Instancing: Instancing allows multiple instances of the same object to be rendered with a single draw call. This can significantly reduce the number of draw calls required for a scene.
- Minimize State Changes: State changes, such as changes to the shader or texture, can be expensive in terms of performance. Minimizing state changes by batching objects with similar properties can reduce the number of draw calls required.
- Use Static Lighting: Dynamic lighting can be expensive in terms of draw calls. Using static lighting techniques can reduce the number of draw calls required for a scene.
So if we implement these steps in our game, than we can reduce the number of draw calls required to render a scene, that leads in improved performance and a better user experience for players.
Best practice to reduce draw calls in unity game
Reducing draw calls is crucial for optimizing the performance of your Unity game. Draw calls occur when Unity renders a mesh or object, and minimizing them can improve frame rates and overall gameplay experience. Here are some best practices to help you reduce draw calls in Unity:
- Combine Meshes:
- Merge static and dynamic objects that share the same materials into a single mesh. Unity provides a Mesh.CombineMeshes function that allows you to combine multiple meshes into one.
- Use Texture Atlases:
- Combine multiple textures into a single texture atlas. This reduces the number of materials and draw calls associated with different textures. Unity’s Sprite Packer can help with 2D games.
- Batching:
- Unity automatically batches static and dynamic objects with the same material into a single draw call. Ensure that your GameObjects use the same materials and meet the batching requirements. Static objects should be marked as static in the Inspector window.
- GPU Instancing:
- Use GPU instancing for materials that support it. This allows the GPU to render multiple instances of the same mesh with a single draw call, reducing CPU overhead.
- Culling:
- Implement frustum culling to avoid rendering objects that are not in the camera’s view. Unity automatically performs some culling, but you can optimize it further by setting appropriate culling masks and using Occlusion Culling for large scenes.
- Level of Detail (LOD):
- Implement LOD for distant objects by providing lower-poly versions of meshes. Unity has a built-in LOD Group component that handles LOD for you.
- Dynamic Batching:
- For mobile platforms, take advantage of Unity’s dynamic batching feature. Objects that share the same material and have a low vertex count may be dynamically batched at runtime.
- Avoid Excessive Material Changes:
- Minimize the number of materials and shader changes in your scene. Using a limited set of materials helps reduce draw calls.
- Use GPU Skinning:
- For animated characters, consider using GPU skinning instead of CPU skinning. This offloads some of the processing to the GPU, reducing CPU overhead.
- Optimize UI:
- If you have a lot of UI elements, consider using the Unity UI system efficiently. Use canvas groups and combine UI elements where possible.
- Shader Variants:
- Be mindful of the number of shader variants you have in your project, as each variant can lead to additional draw calls. Simplify and consolidate shaders when feasible.
Always remember to profile your game using Unity’s Profiler to identify performance bottlenecks and validate the impact of your optimizations. Experiment with different techniques and measure their effects on performance to find the best balance for your specific game. These are some best practices to reduce draw calls in unity game.