Creating a self-illuminated material

Self-illuminated materials can be used to simulate a variety of objects, from LED mobile displays to futuristic Tron suits. In this recipe, we will learn how to configure this kind of material and its texture maps.

Getting ready

As we will create an LCD display in this example, please make sure you have a font in that style installed on your computer. If not, you can find several free LCD fonts on specialized websites, such as www.dafont.com.

How to do it...

To create a self-illuminated material, follow these steps:

  1. Create a new material named LCDMaterial.

    Note

    The easiest way to do that is to access the Project view, click the Create drop-down menu and choose Material.

  2. Select your material. In the Inspector view, under the material's name, use the drop-down menu to change its Shader parameter to Self-Illumin/Diffuse:
    How to do it...
  3. Open your image editor (we'll use Adobe Photoshop to illustrate the next steps).
  4. Create a new image. Let's make it 256 pixel both wide and tall, at 72 dpi (RGB mode).
  5. Create a new layer and fill it with a dark blue color (for instance, R:8, G:16, B:99). Name it blueBg.
  6. Create a type layer and write your LCD text in light blue (R:8, G:90, B:231). Name it blueText.
  7. Duplicate the blueBg and blueText layers. Rename them to selfBg and selfText respectively.
  8. Change the color of the selfText type to white. Then, fill the selfBg layer in black.
  9. Merge the selfText and selfBg layers. Then, merge the blueText and blueBg layers:
    How to do it...
  10. Make a selection of the entire black and white layer (Ctrl + A on Windows, Command + A on Mac OS). Then, copy it (using Ctrl + C or Command + C):
    How to do it...
  11. Open the Channels window (in Photoshop this can be done by navigating to Window | Channels).
  12. There should be three channels: Red, Green, and Blue. Create a new channel. That will be the Alpha channel that controls the level of self-illumination and gloss.
  13. Paste (Ctrl + V or Command + V) your black and white layer into the Alpha channel:
    How to do it...
  14. In the Layers window, hide or delete the merged black and white layer.
  15. Save your file (.psd or .tga formats are good options, as they keep the alpha channel).
  16. Inside the Unity Editor, import your image file access through the Assets menu, clicking on Import New Asset....
  17. In the Project view, choose LCDMaterial. Then, select your image file as both Base and Illumin maps (by clicking on the Select button or dragging them from the Project view to the material slots). Your self-illuminated material is ready, as shown in the following screenshot:
    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). Self-illuminated shaders use RGB channels as the base texture (often referred to as the diffuse texture), while using the Alpha to illuminate the material according to each pixel's brightness level.

There's more...

Here is some more information on self-illuminated materials.

Using independent maps

Please note that you can use two different image files as the Base and Illumination maps. In this case, the Base texture's alpha channel will be controlling the material's gloss.

Emitting light over other objects

The Emission (Lightmapper) field in the Material options can be used to simulate the material's light projection over other objects when baking a lightmap.

See also

  • The Creating specular texture maps recipe.
  • 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.16.75.165