- Home /
(Solved) Batching sprites in a randomly generated dungeon with Diffuse sprites
Hello,
I am making a 2d rpg dungeon crawler. I have made the content the way I like it and am happy with the way it it is generating the dungeons, applying lighting, placing object and all that jazz. However I am trying to make it run smoothly for webgl. Inside the dungeons in my game fps, according to the stats window, falls from 600 outside the dungeon to +-70 inside the dungeon.
The stats window also shows that I have 10000 batches and I am only saving about 1300 by batching. And so I am getting a ton of drawcalls which I believe is causing the issue. I have done the following to try and reduce this (numbers in brackets at the end indicate the reference where I got the information):
Given all my sprites the same Packing tag (1)
Given all my sprites the same Material (1)
Given all my sprites the same Compression format in the Import settings (1)
Labelled all of my Static objects as Static in the inspector (5)
Here is a picture of my stats window, however sometimes the batches can even reach 12k+
The Script that generates the dungeon creates a grid of sprites and then runs through using an algorithm and replaces the sprites with the correct sprite for floor etc, and places 3d objects for walls these are cubes with textures that make them look pixelated. Giving the dungeon a cool mixture of 2d and 3d elements. It should be noted that I have tried to alter the code so as not spawn walls, or not spawn floors, etc.
Im wondering if anyone can Point out some other things that I can try or places that I can look for information on this topic. Sadly I dont have unity Plus to use the profiler. May be getting it later today if I cannot solve this issue without the profiler.
references:
1. https://answers.unity.com/questions/847622/getting-dynamic-batching-to-work-with-2d-sprites.html
2. https://blogs.unity3d.com/2017/04/03/how-to-see-why-your-draw-calls-are-not-batched-in-5-6/
3. https://answers.unity.com/questions/898619/lower-draw-calls-for-sprites.html
4. https://docs.unity3d.com/Manual/DrawCallBatching.html
5. https://forum.unity.com/threads/draw-calls-for-sprites.249207/
Answer by SteenPetersen · Mar 28, 2018 at 10:11 AM
I managed to figure out what the problem was finally while make sure I wrote the question thoroughly. Turns out it was the fact that all my sprites where labelled as diffuse which is fine for batching but when lights are added to the mix every sprites gets a seperate draw call because the lighting influences the sprite and makes it unique.
So the solution is to get creative with how I manage lighting in the game and try to find another way of doing it. Any suggestions to that are appreciated.
References:
https://forum.unity.com/threads/using-sprites-diffuse-material-breaks-batching.254083/
Your answer
Follow this Question
Related Questions
Trying to have sprites affected by fog without having to use default/diffuse shader. 3 Answers
Sprite Diffuse shader not affected by point lights 1 Answer
Sprites/Diffuse shader overlap problem 0 Answers
Making shader's first pass light sensitive (2D) 0 Answers
Limit Amount of Light Applied to Sprite 0 Answers