Wednesday, August 15, 2012

How I Doubled the FPS of my Game

The past few days, I've been working on getting the frame rate of my game up since when there are lots of zombies spawned, the frames per second dropped so low on mobile devices that it was unplayable.

So I set out to create some dramatic changes in my game. First thing, I created a backup of my game in case anything went wrong. Then I did what I should have done from the very start but I did not because I was fairly unexperienced in how to edit UV meshes. Previously for all my FBX files imported from 3DS max, I applied a different texture, each with a different material, to the planes. This results in one draw call for each material. This means there is at least 4 draw calls for each zombie (arms, legs, body, and head) and many more for each floor tile type.

I solved this by recreating all the FBX files and redoing all the UVW maps. I did this three times over for the three groups of FBX files I had: scene prop meshes, zombie and player meshes, and ground meshes. Each of the objects from the groups had to be organized into their own little area from the UVW map: The bottom-left 1/8th is given to one type of ground, the middle-bottom 1/8th is given to another type of ground, and so on and so on. Each UVW template is rendered out and then using Photoshop, the templates are combined into one large 1024 x 1024 and then I can add my textures into each place. This was the hardest part for me to understand when I was learning.

Then the new meshes from 3DS Max now have to be reexported with their new UVW mapping information. So yes, this means there will be more meshes in your project folder but there will be only one material that is shared between the meshes and so the objects will be batched, significantly improving FPS and decreasing draw calls.

As you can see from the first image, I compared the FPS and draw calls from the very first backup that I performed before redoing all the UVW mapping on most of my meshes and I was able to cut the draw calls in half and double the FPS, not bad for a few days of work.

Now I still have to redo the meshes for the houses, I'm thinking about repainting the texture for the brick building, not sure yet though.


Post a Comment