Chapter 4. Creating Maps and Materials

In this chapter, we will cover the following topics:

  • Creating a basic material with Standard Shader (Specular setup)
  • Adapting a basic material from Specular setup to Metallic
  • Applying Normal maps to a material
  • Adding Transparency and Emission maps to a material
  • Highlighting materials at mouse-over
  • Adding Detail maps to a material
  • Fading the transparency of a material
  • Playing videos inside a scene

Introduction

Unity 5 introduces in new Physically-Based Shaders. Physically-Based Rendering is a technique that simulates the appearance of materials based on how the light reacts with that material (more specifically, the matter from which that material is made) in the real world. Such a technique allows for more realistic and consistent materials. So, your creations in Unity should look better than ever. Creating materials in Unity has also become more efficient now. Once you have chosen between the available workflows (Metallic or Specular setup; we'll get back to that later), there is no longer the need to browse the drop-down menus in search of specific features, as Unity optimizes the shader for the created material, removing unnecessary code for unused properties once the material has been set up and the texture maps have been assigned.

For a deep understanding of Physically-Based Rendering, we recommend you to take a look at The Comprehensive PBR Guide, written by Wes McDermott from Allegorithmic, freely available in two volumes at http://www.allegorithmic.com/pbr-guide. Allegorithmic's guide contains invaluable information on PBR theory and techniques, having been a fundamental reference for this chapter. A great resource that we'd recommend you take a look at is Mastering Physically Based Shading in Unity 5 by Renaldas Zioma (Unity), Erland Körner (Unity), and Wes McDermott (Allegorithmic), available at http://www.slideshare.net/RenaldasZioma/unite2014-mastering-physically-based-shading-in-unity-5.

Another resource is Physically Based Shading in Unity by Aras Pranckevičius (Unity), available at http://aras-p.info/texts/files/201403-GDC_UnityPhysicallyBasedShading_notes.pdf.

Creating and saving texture maps

The visual aspects of a material can be modified through the use of textures. In order to create and edit image files, you will need an image editor such as Adobe Photoshop (the industry standard, and has its native format supported by Unity), GIMP, and so on. In order to follow the recipes in this chapter, it's strongly recommended that you have access to a few pieces of software like these.

When saving texture maps, especially the ones that have an Alpha Channel, you might want to choose an adequate file format. PSD, Photoshop's native format, is practical for preserving the original artwork in many layers. The PNG format is also a great option, but please note that Photoshop doesn't handle PNG's Alpha channel independently of the transparency, possibly compromising the material's appearance. Also, PNG files don't support layers. For this chapter, we will often use the TIF format for three main reasons: (a) it's open to those not using Photoshop; (b) it uses layers; (c) it preserves the Alpha Channel information. The file size is significantly greater than in PSDs and PNGs, so feel free to save your work as PSDs (if you have Photoshop) or PNGs (if you don't need layers and, if using Photoshop, Alpha Channels).

Finally, a word of advice - although it's possible to manually create texture maps for our materials by using the traditional image editing software, new tools such as Allegorthmic's Substance Painter and Bitmap2Material make this work much more efficient, complete, and intuitive, complementing the traditional texture-making process or replacing it altogether - in a similar way to what zBrush and Mudbox did for 3D modeling. For design professionals, we strongly recommend at least trying such tools. Note, however, that products from Allegorithmic won't make use of Unity's Standard Shader, relying on the substance files (which are natively supported by Unity).

The big picture

To understand the new Standard Shaders, it's a good idea to know the workflows, their properties, and how they affect the material's appearance. There are, however, many possible ways to work with materials - texture map requirements, for instance, might change from engine to engine, or from one tool to another. Presently, Unity supports two different workflows: one based on Specular, and another based on Metallic values. Although both workflows share similar properties (such as Normal, Height, Occlusion, and Emission), they differ in the way the diffuse color and reflectance properties are set up.

Specular workflow

Unity's Standard Shader (Specular setup) uses Albedo and Specular/Smoothness maps, combining them to create some of the material's aspect—mainly its color and reflectance qualities. The following shows the difference between Albedo and Smoothness maps:

  • Albedo: This is the material's diffused color. Plainly and simply, this is how you usually describe the appearance of the material (the British flag is red, white and blue; Ferrari's logo is a black horse in a yellow setting; some sunglasses' lenses are semi-transparent gradients, and more). This description, however, can be deceptive. Purely metallic objects (such as aluminum, chrome, gold, and others) should have black as their diffuse color. Their colors, as we perceive them, have originated from their specular channel. Non-metallic objects (plastic, wood, and even painted or rusted metal), on the other hand, do have very distinct diffuse colors. Texture maps for the Albedo property feature RGB channels for colors and (optionally) an Alpha Channel for transparency.
  • Specular/Smoothness: This refers to the shininess of the material. Texture maps make use of RGB channels for specular color (which informs hue and intensity), and Alpha Channel for smoothness/gloss (dark values for less shiny surfaces and blurred reflections; light/white values for shiny, mirror-like appearance). It is important to note that non-metallic objects feature neutral, very dark specular colors (with plastic, for instance, you should work with a grey value around 59). Metallic objects, on the other hand, feature very light values, and are also a bit yellowish in hue.

To illustrate such concepts, we have created a battery object (shown below), featuring brushed metal caps and a plastic body. Observe how each map contributes to the final result:

Specular workflow

The metallic workflow

Unity's default Standard Shader combines Albedo and Metallic/Glossiness maps to create the color and reflectance qualities of the material. The following are the differences:

  • Albedo: As in the Specular workflow, this is the material's diffuse color; how you would describe the material. However, Albedo maps for the Metallic workflow should be configured in a slightly different way than ones for Specular workflow. This time around, the perceived diffuse color of metallic materials (grey for iron, yellow/orange for golden, and so on) have to be present in the Albedo map. Again, Albedo maps feature RGB channels for the colors and (optionally) an Alpha channel for transparency.
  • Metallic/Smoothness: This refers to how metallic the material looks. Metallic texture maps make use of the Red channel for the Metallic value (black for non-metallic and white for metallic materials that are not painted or rusted) and the Alpha Channel for smoothness (in a similar way to the Specular workflow). Please note that Metallic maps do not include any information on hue, and in these cases the yellow-ish nature of the metallic gloss should be applied to the Albedo map.

To reproduce the battery that illustrated the Specular workflow by using the Metallic workflow, maps would have to be recreated as follows:

The metallic workflow

Note

You might have noticed that we've used white to convey a metallic object. Technically, since only the Red channel is relevant, we could have used red (R: 255, G: 0, B: 0), yellow (R: 255, G: 255, B: 0) or, for that matter, any color that has a red value of 255.

Other material properties

It's also worth mentioning that Unity's Standard Shaders support other maps such as:

  • Normal maps: The normal map adds detailed bumpiness into the material, simulating a more complex geometry. For instance, the internal ring on the positive (top) node of the battery that illustrated shader workflows is not modeled in the 3D object's geometry, but rather created through a simple normal map.
  • Occlusion maps: A greyscale map is used to simulate the dark sections of an object under ambient light. Usually, it is used to emphasize joints, creases, and other details of geometry.
  • Height maps: These add a displacement effect, giving the impression of depth without the need for complex geometry.
  • Emission maps: These add color emitted by the material, as if self-illuminated, such as fluorescent surfaces or LCDs. Texture maps for Emission feature RGB channels for color.

Unity samples and documentation

Before you start, it might be a good idea to read Unity's documentation on textures. It can be found online at http://unity3d.com/support/documentation/Manual/Textures.html.

Finally, Unity has put together a great resource for those looking for some pointers regarding how to set up maps for a variety of materials: the Shader Calibration Scene, which can be downloaded (for free) from the Unity Asset Store. It is a fantastic collection, featuring sample materials (both Metallic and Specular setup) for wood, metal, rubber, plastic, glass, skin, mud, and much more.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.232.152