Gamasutra: The Art & Business of Making Gamesspacer
View All     RSS
February 24, 2017
arrowPress Releases

If you enjoy reading this site, you might also want to check out these UBM Tech sites:

Unity Optimizing For Mobile Using SubTile Meshes
by Mark Hogan on 07/21/14 08:23:00 am   Featured Blogs

2 comments Share on Twitter Share on Facebook    RSS

The following blog post, unless otherwise noted, was written by a member of Gamasutra’s community.
The thoughts and opinions expressed are those of the writer and not Gamasutra or its parent company.


I'm currently working on an update for Look Out Below!, focusing on performance and user experience.

One of the places that suffered performance issue the most was over the cities, which I suspect is due to the high number of draw calls in this area. In this page on the Unity manual they describe about the CPU cost or drawing an object on screen and how reducing the number of draw calls can increase performance.

In Look Out Below! we use a lot of tiled textures which are great because they take up very little memory but still provide plenty of texture resolution, normally a building with have the same texture tiled across it 20 times or so, quick example below.

But a big part or reducing draw calls is atlasing, as each tiled texture requires a different material and therefore a different draw call, even if its applied to the same mesh (on a submesh), where as with atlasing many textures are combined together into one big texture, and the meshes UVs are moved to the correct part of the texture (this is what Unity's lightmaps are, large texture atlases that contain and combine many small textures generated for each mesh), for example our trees use a single texture.

Unfortunately, tiled textures and texture atlases don't mix well, tiling relies on continuous UVs that go beyond the normal 0,1 UV range, and atlasing relies on each mesh having its UVs confined to a small area of the UV range and texture. My solution was to tile and mirror within a smaller UV range using a shader which uses vertex colors to specify a range to tile in.

For the texture I simply placed all the tiled textures in a row (this can lead to non square texture sizes but I'm just letting Unity upscale them for now). This texture was previously 4 different textures requiring 4 different materials.

Then in my 3D package I have multiple materials assigned to a mesh that have a name like "WindowMat_4_4" or "CobbledRoadMat_1_4", here the first number indicates which section of the texture the tile we want to use is and the second number indicated the total number of tiles. I also have a custom attriubute called "Unity" with the value "subtile", this is how I tag objects in Unity to edit them during the import phase with a custom AssetPostProcessor and the OnPostprocessGameObjectWithUserProperties method.

On import this tells the importer that faces with this material applied need to have vertex colors applied. In this example faces with "WindowMat_4_4" applied will get the color (0.75, 0, 0.25, 1) as the vertex colors, which in the shader will equate to the last quater of the texture (i.e. texture 4 of 4 assuming the textures are laid out horizontally).

Here it it in action;

Now the building which was previously 4 tiled textures and 4 draw calls can be rendered in one draw call, providing a performance boost without actually sacrificing any quality. One small different between this new mesh and the old one is that while we still use tiling on the Y axis on the X axis it's not tiling anymore its mirroring, this is so that the difference in UV sample position isn't so large as to cause extreme mip-mapping, for us this isn't an issue as our textures are mostly symmetrical on the x axis anyway but it does limit it's usefulness in other situations.

And thats about the jist of it, if you want more info or to try it out in your project you can download the SubTileImporter script and the SubTileX shader that we're using. The code is also written in full on the Popup Asylum blog if you don't want to download but still want to read it.

Related Jobs

YAGER Development GmbH
YAGER Development GmbH — Berlin, Germany

Server/Backend Programmer
YAGER Development GmbH
YAGER Development GmbH — Berlin, Germany

UI Programmer (f/m) - C++ and Actionscript
Intel — Santa Clara, California, United States

Research Scientist
Cat Daddy Games
Cat Daddy Games — Kirkland, Washington, United States


Loading Comments

loader image