Atlas Generator

During the first year at TGA everyone made three 2D games. These were made in the 2D game engine provided by the school - TGA2D. A big problem that quickly arose was reducing the amount of draw calls, which was eating a big portion of the frame time.  A natural solution was batching sprites, so efforts were made to create texture atlases. This took time from both the graphic students who had to create the atlases, and then the programmers who had to manually calculate the different areas of the atlas and the corresponding UV coordinates, and finally map that in code. Furthermore, it was very rigid and cumbersome to update existing atlases once they were made. 

Introduction and problem overview

Solution

I started working on a solution to this problem during the second game project, after seeing a lot of unnecessary time go to waste during the first. I wrote a program that recursively iterated over directories, finding images and calculating atlas positions, finally saving the data to a json file. I then wrote a script (in javascript, a language I never used before) which took this file and put together an atlas in photoshop. The only thing that the graphic students had to do once they created new  art was to run this script, and an updated atlas was created automatically.

exampleAtlasEntries.png

A part of the generated json file

atlasExempel.png

Finished atlas

Integrating it in to our game

Finally, to make everything completely automatic and save time for the programmers as well,  I wrote a wrapper for the sprite class in TGA2D, which made the user completely unaware of the fact that sprites were being batched and put on an atlas. The programmer no longer had to manually enter texture coordinates for the sprites on the atlas, which were transformed to the original UV-space of (0,1). Furthermore, the interface was made in such a way that if a sprite was to be used that was not on the atlas, the user didn't need to change anything, the interface was the same. Most importantly, everything was updated automatically once a new atlas was created. 

Normal maps

During the last project of the first year, I extended this system to also create a corresponding atlas for normal maps for sprites who had a normal map. It then added that normal map automatically (but could of course be turned off) to the sprites who had one.

normalMapAtlas.png

Atlas for normal maps