Creating specular texture maps

Some surfaces can have both glossy and matte areas. In order to achieve that effect, we can use specular maps.

Getting ready

For illustration purposes, we will create a rusted metal material to demonstrate how the specular property can be used to enhance realism. If you don't have a base texture to develop into a specular material, please use the one included in the book's 0423_03_03 content folder.

How to do it...

To create a specular material, follow these steps:

  1. Create a new material called rustyMetalMaterial.
  2. Select your material. In the Inspector view, under the material's name, use the drop-down menu to change its Shader value to Specular:
    How to do it...
  3. Open the base texture in your image editor (we'll use Adobe Photoshop to illustrate the next steps).
  4. Open the Channels window (in Photoshop this can be done by navigating to Window | Channels).
  5. There should be three channels: Red, Green, and Blue. Create a new channel. This will be the Alpha channel that controls the gloss level of our specular material:
    How to do it...
  6. We want our Alpha channel to emphasize the contrast between rust and metal. Since Blue is the channel with higher level of contrast, we will select it on the Channels window and make all the other channels invisible. The resulting image will be displayed in grayscale, as shown in the following screenshot:
    How to do it...
  7. Select and copy all the image pixels (using Ctrl + A/Ctrl + C on Windows, or Command + A/Command + C on Mac OS).
  8. In the Channels window, select the Alpha channel and paste the image you have copied.
  9. Now, intensify the contrast by going to Image | Adjustments | Brightness/Contrast:
    How to do it...
  10. Still in the Channels window, bring the colors back by enabling all RGB channels.
  11. In addition to the rusty metal plate, let's simulate a paint layer on the wall: create a type layer in yellow. You can type whatever you want.
  12. Change the type layer's blending mode to Overlay and set its Opacity to 80%:
    How to do it...
  13. Flatten your image (this is necessary, or Unity might discard the alpha channel you created and use the image layer transparent pixels as the alpha channel instead).
  14. Save your work as a new image file (.psd or .tga formats are good options, as they keep the alpha channel).
  15. Inside the Unity Editor, import your image file access through the Assets menu, clicking on Import New Asset....
  16. In the Project view, choose the rustyMetalMaterial asset. Then, apply the texture you've made as a Base map (by either clicking on the Select button or dragging it from the Project view to the material slots). Your specular mapped material is ready:
    How to do it...

How it works...

Unity is able to read four channels of a texture map: R (red), G (green), B (blue), and A (alpha). Specular shaders use RGB channels as the base texture (often called diffuse texture), while using the Alpha to set the specular brightness of the material according to each pixel's brightness level.

There's more...

The specular shader features some other parameters that are worth looking into: Specular Color and Shininess.

Changing the specular color of our material

If you ever get tired of that white shining spot, you can add some variety by changing the specular color.

Adjusting shininess to focus the highlight

Shining spots don't look the same on bowling balls (where they are highly concentrated) as they do on brushed metal surfaces (where they spread a bit more). This concentration level is controlled by the Shininess parameter.

See also

  • The Creating transparency texture maps recipe.
..................Content has been hidden....................

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