Home > Articles > Programming > Games

  • Print
  • + Share This
This chapter is from the book

Textures, Shaders, and Materials

Applying graphical assets to 3D models can be daunting if you are not familiar with it. Unity uses a simple and specific workflow that gives you a lot of power when determining exactly how you want things to look. Graphical assets are broken down into textures, shaders, and materials. Each of these is covered individually in its own section, but Figure 3.5 shows you how they fit together. Notice that textures are not applied directly to models. Instead, textures and shaders are applied to materials. Those materials are in turn applied to the models. This way, the look of a model can be swapped or modified quickly and cleanly without a lot of work.

FIGURE 3.5

FIGURE 3.5 The model asset workflow.

Textures

Textures are flat images that get applied to 3D objects. They are responsible for models being colorful and interesting instead of blank and boring. It can be strange to think that a 2D image can be applied to a 3D model, but it is a fairly straightforward process once you are familiar with it. Think about a soup can for a moment. If you were to take the label off of the can, you would see that it is a flat piece of paper. That label is like a texture. After the label was printed, it was then wrapped around the 3D can to provide a more pleasing look.

Just like all other assets, adding textures to a Unity project is easy. Start by creating a folder for your textures; a good name would be Textures. Then drag any textures you want in your project into the Textures folder you just created. That’s it!

Shaders

If the texture of a model determines what is drawn on its surface, the shader is what determines how it is drawn. Here’s another way to look at this: A material contains properties and textures, and shaders dictate what properties and textures a material can have. This might seem nonsensical right now, but later when we create materials you will begin to understand how they work. Much of the information about shaders is covered later this hour, because you cannot create a shader without a material. In fact, much of the information to be learned about materials is actually about the material’s shader.

Materials

As mentioned earlier, materials are not much more than containers for shaders and textures that can be applied to models. Most of the customization of materials depends on which shader is chosen for it, although all shaders have some common functionality.

To create a new material, start by making a Materials folder. Then right-click the folder and select Create > Material. Give your material some descriptive name and you are done. Figure 3.6 shows two materials with different shaders selected. Notice how they each have a base texture, main color, tilling and offsets, and a preview of the material (blank now because there is no texture). The Shiny material, however, uses a specular shader and comes with properties for specular color and shininess. All these properties are covered later in this hour.

FIGURE 3.6

FIGURE 3.6 Two materials with different shaders.

Shaders Revisited

Now that you understand textures, models, and shaders, it is time to look at how it all comes together. Unity has a lot of built-in shaders, but this book is concerned with only a few of the Normal family of shaders. These shaders are the most basic and should be useful for everyone. Table 3.1 lists some of the basic shaders and describes them.

TABLE 3.1 Basic Normal Family of Shaders

Shader

Description

Diffuse

Diffuse is the default shader for materials and is also the most basic.Light is evenly distributed across the diffuse object's surface.

Specular

Specular textures make an object look shiny. If you want to make an object seem to reflect a lot of light, this is the shader to use.

Bumped

Bumped shaders are generally used in conjunction with other shaders (as in bumped-diffuse or bumped-specular). These shaders use a normal map to give the flat texture a 3D, or bumpy, look. These are a great way to give your models a lot of physical detail without requiring complex modeling.

Now that you are familiar with a few of the built-in shaders, it is time to look at some of the common shader properties that you will be working with. Table 3.2 describes the common shader properties.

TABLE 3.2 Common Shader Properties

Property

Description

Main Color

The Main Color property defines what color of ambient light shines on the object.This does not change the color of the object itself; it just makes the object appear different. For example, an object with a blue texture and a yellow main color will not turn yellow but green (because blue with yellow light looks green). If you want your model's color to remain unchanged, select white.

Specular Color

The Specular Color property determines what color the "shiny" parts of a specular model are. Generally speaking, this will be white unless you intend for it to appear as if another color of light is shining on the object.

Shininess

The Shininess property determines how shiny a specular object is.

Texture

The Texture block contains the texture you want to apply to your model.

Normal Map

The Normal Map block contains the normal map that will be applied to your model. A normal map can be used to apply bumpiness to a model. This is useful when calculating lighting to give the model more detail than it would otherwise have.

Tiling

The Tiling property defines how often a texture can repeat on a model. It can repeat in both the x and y axes.

Offset

The Offset property defines whether a gap will exist between edges of the object and the texture.

This might seem like a lot of information to take in, but once you become more familiar with the few basics of textures, shaders, and materials, you’ll find this a smooth process.

  • + Share This
  • 🔖 Save To Your Account