Gamasutra: The Art & Business of Making Gamesspacer
View All     RSS
September 16, 2014
arrowPress Releases
September 16, 2014
PR Newswire
View All





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

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

Raven Software / Activision
Raven Software / Activision — Madison, Wisconsin, United States
[09.16.14]

Sr. Gameplay Engineer - Raven
Raven Software / Activision
Raven Software / Activision — Madison, Wisconsin, United States
[09.16.14]

Lead Engineer - Raven
Square Enix Co., Ltd.
Square Enix Co., Ltd. — Tokyo, Japan
[09.15.14]

Programmers
Playtika Santa Monica
Playtika Santa Monica — Santa Monica, California, United States
[09.15.14]

Sr. BI Developer






Comments


Mike Weldon
profile image
So you can "tile" within a confined space on the atlas by mirroring. That's clever. With multiple tiled layers you probably wouldn't notice the mirroring artifacts, and you can still get it all in one draw call. I wish there was a like button for articles.

Jonathan Curiel
profile image
Thanks for sharing! Great problem solving.


none
 
Comment: