So now I have all our
models textured and unwrapped and ready to go. What I want to do first is make up the texture
atlas that will be applied to all models in game to allow for batching of draw
calls to occur. This will be explained in more detail in a later post. I have
elected to create the atlas manually as being a small game I am certain I can
include all textures needed onto the same map.
So what is a Texture Atlas?
Example taken from gamasutra, referenced below
Essentially it is a
large image containing many smaller images (2D or 3D textures) arranged in a
collage or regular indexing pattern. Instead of loading in many textures to a
game and applying each separately to your assets or models, a complete texture
atlas or a few atlases containing all of your textures are loaded in instead. These
atlases are shared between different models in your game. For example in a
larger game you might have one Texture atlas containing the textures for all
the environmental assets, one for character textures, etc. And atlas can usually
hold anywhere between 16 to 126 textures.
Why use a Texture Atlas?
For games a texture
atlas has performance benefits that cannot be ignored. Firstly they save on
physical memory. When you bring a texture into your game engine it will be
automatically re-sized and to a power of 2 number. For instance if I bring in a
texture that is 400 x 400 pixels, it will be automatically padded up with white
space to 512x512. This space is simply wasted memory. If you use a texture
atlas you can pack your textures together in such a way as to minimize any wasted
memory.
The other major
advantage to using a texture atlas is that it increases batching in your game.
When you are playing a game you are rendering scene after scene very quickly. Each
object or model in the scene needs to be drawn. A draw call goes to the GPU or
CPU to draw that object, the texture for the object is loaded into memory and
the object is drawn, then it moves on to the next draw call. It must load in
whatever texture that object is using, draw it and then move on again. However
if the GPU did not need to stop an load in a new texture for each object before
drawing could begin then the whole process would be a lot quicker. This is what
batching does. If all the objects in game are being drawn from the same texture
then the draw calls for those objects can be batched together. Calls to the GPU
are very expensive in game terms so lightening this load is great for your
games performance!
Making the Texture Atlas
I have opted to make
my texture atlas by hand in Photoshop. There are many programs out there that
can be used to do this for you, but has I said before, our game is small and I want
maximum control over the result. To make the atlas I made a 2048 x 2048, 300
dpi blank image in Photoshop to form the base. Our textures are mostly small
and simply colored so this size will be plenty big enough for our needs. I then
started adding and arranging the different textures to the sheet and it’s
slowly started filling out. I saved the image and this will form the material
for each model in game. We are developing our game in an agile iterative environment
so there atlas is still being added to as more models are made and textured.
Re-mapping UVs to Atlas
Again I have opted to
take the manual approach, this is also said to be the more reliable approach when
working in Unity. I could remap each models UV’s in unity to a section of the
texture atlas using some specialized piece of code or plugin but I have instead
opted to remap the UV’s by hand in 3DsMax.
The approach I took was to:
- Open a model in 3DsMax whose texture is contained in the atlas
- Apply the UVW unwrap modifier, the seams created earlier should be visible again
- Open the UV editor and view your wire frame unwrap
- Click the drop down menu on the right and select pick texture, find the atlas
- Select your entire unwrap wire-frame and uniform scale and move it until it is back over its section of the texture atlas.
- Save the model with these new UV coordinates and repeat for other models.
Now all of these
models will know exactly where their texture data is on the texture atlas when
it is applied to them.
References :
Books
- Bly, P. D., 2012. Holistic Game Development with Unity.
- Nvidia, 2004. SDK White Paper - Improve Batching using Texture Atlasing .
- McDermot, W., 2011. Creating 3D Game Art for the iPhone with Unity.
Online
- Ivanov, I.-A., 2015. Gamasutra. [Online] Available at: http://www.gamasutra.com/view/feature/2530/practical_texture_atlases.php?print=1
- Nividia, n.d. Texture Atlas Tools. [Online] Available at: http://www.nvidia.com/object/texture_atlas_tools.html
- Rayolsen, D., 2012. Texture Atlas Tutorial. [Online] Available at: http://forum.unity3d.com/threads/texture-atlas-tutorial.149939/
- Wolfire Blog Games, 2014. Using Texture Atlases [Online] Available at: http://blog.wolfire.com/2010/03/Using-texture-atlases
- Paladine Studios, 2012. 4 Ways To Increase Performance of your Unity Game [Online]Available at: http://www.paladinstudios.com/2012/07/30/4-ways-to-increase-performance-of-your-unity-game/
No comments:
Post a Comment