Textures are nothing more than images applied to the surface of a model in a game. They are one of the fundamental building blocks of any game and so it’s important to know how to create a texture that is game-ready.
Because a texture is just a picture it can be created using any image creation software you like, however the industry standard package for creating textures is Adobe Photoshop. The techniques I will discuss can be achieved with all sorts of software packages, but in the examples below I have just used Photoshop.
This post is broken up into the following sections:
- Texture Dimensions
- Colour Channels
A texture that is to be used in a game renderer needs to be created at a specific size in order for it to work correctly. Due to the way binary data is stored, textures need to be created with what is known as “power of 2” dimensions. This basically means that each dimension of the texture (width and height) needs to be a value which is a power of 2:
22 = 4
23 = 8
24 = 16
25 = 32
26 = 64
27 = 128
28 = 256
29 = 512
210 = 1024
211 = 2048
212 = 4096
So for example you can create a texture with width = 512 and height = 512. You’ll often see this written as 512 x 512 to represent width and height dimensions. Textures which do not use power of 2 dimensions may still work, but this depends very much on the game engine you are using. The safest thing to do is to always work in power of 2 dimensions whenever possible.
One other thing to bear in mind is that the size of the texture has knock-on-effects for memory and performance. The larger the texture the more memory it will use and also the longer it will take to draw in game. The size you choose for your texture should therefore be based on the platform you are working with. For example you would not use the same size textures on a PlayStation 4 as you would an iPhone as these two platforms have very different performance capabilities. Also the type of model your texture is going to be used on should be taken into account. For example a texture for the game’s main character should be much larger than a texture for some unimportant piece of the environment such as a plug socket or something similar.
Textures normally have 3 colour channels. These are:
By combining different levels of these three colour channels, we are able to represent a very broad range of possible colours.
Each colour channel is made up of a set of pixels. If we look at our 512 x 512 texture from above we can see that we end up with 512 x 512 = 262,144 pixels in total. That’s a whole lot of pixels!
Each one of those pixels is given a value that must lie within a particular range of possible values. This range is called the texture’s colour-depth (or bit-depth). I am not going to cover very much about colour-depth because it is a large and rather complex subject, however it is worth knowing that the standard colour-depth used in most images is called 8bit-colour because each pixel is given 8bits of binary data to represent it. If you look back at the power of 2 list above you will see that 28 = 256, and so this basically means that each pixel in our 8bit-colour channel is given a value that lies in the range from 0 – 255 (programmers always start counting from 0 instead of 1).
Still with me? Lets recap…
What we’ve learned is that a colour channel is made up of a list of pixels (The size depends on the dimensions). Each pixel holds a single value that can be anything from 0 – 255.
The next step is to combine the 3 colour channels together. When we do this, each pixel is now represented not by just one channel, but by 3 separate channels, each of which can be any value between 0 – 255. That means that every pixel has a range of 256 x 256 x 256 = 16.7 million possible colour values! Now thats a lot of colours. Incidentally the human eye can distinguish about 10million different colours, and so our 8bit-colour texture actually provides us with more colour than we can actually see.
In order to add transparency into out textures, we need to introduce an extra channel:
The alpha channel works in exactly the same way as all of the other channels, the only difference is that it defines the transparency of the image instead of the colour.
Not all image formats are able to support transparency and it is important to decide what your texture format is going to be before you create your textures. Two commonly used texture formats for games are Targa and PNG. Both support transparency but they work in slightly different ways.
The Targa or TGA format supports the addition of an alpha channel as a separate channel in Photoshop. This can be useful because it means modifying the alpha channel is straight forward simply by selecting the channel directly as seen below:
However, one problem with this is that the transparency is not very easy to visualise in Photoshop:
Often the easiest way to see the transparency is to get the texture into a game and see it applied to the model.
One other thing to note when working with TGAs that have alpha is that you must tell Photoshop that you want to save the alpha channel when you save the texture. Often you will see this dialog box appear when saving a TGA:
This dialog box ties very closely with the discussion about colour channels above. Because TGAs are stored as 8bit colour-depth the dialog box is actually asking how many channels you want to store:
- 16 bits/pixel – Low quality colour depth – this option should never be used for modern game textures.
- 24 bits/pixel – This option is for RGB textures (3 channels of 8bit colour-depth, 8 + 8 + 8 = 24)
- 32 bits/pixel – This option is for RGBA textures (4 channels of 8bit colour-depth, 8 + 8 + 8 + 8 = 32)
The PNG format supports transparency, but instead of dealing with it as an actual editable channel, instead it is handled as actual visible transparency:
This makes visualising the transparency much easier because you can see it in the Photoshop window. However it does sometimes make editing the transparency much more difficult because the transparency is embedded into the actual texture and not as easy to modify.