Sunday, May 20, 2012

Texture Atlas



This entry will cover a very important technique for providing improved texture detail on meshes for gaming purposes while minimizing the number of materials needed.  In gaming it is very important to have as few materials as possible, as every unique material in a mesh requires a separate 'Draw Call'.  So if possible you want to combine your materials into one single map (or Texture Atlas).  

In our example I've started with a sphere that has been UV unwrapped via a seam [CTRL+E] around the equator. 
I applied two different materials, one a brick image and one a rug image.  So to begin, we have a single mesh wit two materials, each with their own image texture UV mapped onto the sphere.  The goal is to combine these two materials into one.

To combine the two, we will essentially be baking the rendered textures onto a new UV map on the sphere. So on the mesh tab, press the [+] button on the UV Maps panel, and name the new map.  In this image I named it 'BakedUVs' but later I'll refer to it as just 'Baked'.

Note: For the baking to work be sure that the new UV map 'BakedUVs' is selected.

At this point, go to the UV Editor [CTRL+LEFT] view, you can view the UV unwrapping for this new UV map.  You can change it, but I've had the most success just leaving it the same as the original.  However, you do need to create a new image.  This should appear as a black square behind your map.

Also note that the mesh must be selected (highlighted orange) while in this view (as shown below).


Next is the baking, but before you move onto this step, in the case of a sphere, to make the texture looking cleaner and smoother, I applied a subsurf and smooth shading to it.  The baked textured will be based on the render, so any of these features will be applied by the bake.

Go to the Render Tab, and at the very bottom you'll find the Bake section.  You don't need to change any parameters just hit Bake.




If you return to the UV Editor window you should now be able to see your new texture baked onto the new image.  This now has both materials on one texture, and the lighting from the rendered scene can now be seen (most obviously on the brick side of the texture).  

Note: Make sure to save this new image.


The following steps will simply show how to reduce your materials down to one to be transferred into a gaming engine such as Unity.  You may want to save as a different filename to preserve the original two-materials in case you want to change it and re-bake.

The first step is to remove the other (original) UV map and just keep the new baked UV map.

The next step is to create a new single material, so the other two can now be removed.

Finally, on the new material, add a new texture and assign the new Texture Atlas which was created from the bake, and make sure the new UV Map is selected.

 Now when rendered, you have both textures/materials applied while using only one material.

The ultimate benefit now is if you export the file to an FBX and transfer the model with its texture into Unity, you can get the same texture detail, now with one UV map and one material.  Note in the stats window that the draw call is only 1.

No comments:

Post a Comment