Unity 2018 Cookbook(Third Edition)
上QQ阅读APP看书,第一时间看更新

How to do it...

To add transparency and color emission maps to materials, follow these steps:

  1. Import the provided files.
  2. Duplicate the card_diffuse_start Texture, naming the copy card_diffuse.
  3. From the Project panel, drag the FBX model package into the Hierarchy to create a GameObject in the Scene.
  4. Create a new Material named m_card. Choose Project menu: Create | Material. Drag the card_diffuse Texture into the Albedo property of m_card.
  5. In the Hierarchy, select PackageCard (child of package), and assign it your new m_card Material.
  6. Create a new Material named m_plastic. Choose Project menu: Create | Material. Change its Rendering Mode to Transparent. Use the Diffuse color picker to change the color's RGB values to 56/56/56, and Alpha to 25. Change the Smoothness level to 0.9:
  1. In the Hierarchy, select PackagePlastic (child of package), and assign it your new m_plastic Material. The plastic portion of the 3D model should now appear partially transparent, as if made of plastic.
  1. To create the cutouts around the package and hang hole, we need to first prepare the diffuse image in an image editor (such as Photoshop). Open the card_diffuse Texture in your image editor.
  2. We will add transparency to the image by deleting the white areas around the package (and the hang hole). Make a selection of those areas (in Photoshop, this can be done with the Magic Wand Tool).
  3. Make sure you unlock the Background layer by clicking on the lock icon, to the left of the layer's name:
  1. Delete the previously-made selection (this can be done in Photoshop by pressing the Delete key). The background of the image should be transparent:
  1. Save your file in your image editor, and return to Unity.
  2. Select the m_card Material in the Project panel. In the Inspector, change its Rendering Mode to Cutout, and adjust its Alpha Cutoff to 0.9:
Choosing Cutout means that your material can be either invisible or fully visible, not allowing for semi-transparency. The Alpha Cutoff is used to get rid of unwanted pixels around the transparent borders.
  1. Let's work on the Emission map for the bright lettering. From the Assets folder, duplicate the card_diffuse.png Texture, rename it card_emission.png, and open it in your image editor.
  2. Select all the characters from the Ms. Laser inscription and the green star (in Photoshop, this can be done with the Magic Wand tool, keeping the Shift key pressed while selecting multiple areas).
  3. Copy and paste your selection into a new layer. Then, select it and apply a Noise filter to it (in Photoshop, this can be done by navigating to Filter | Noise | Add Noise...). Use 50% as the value.
  4. Create a new layer and, using a tool such as the Paint Bucket, fill it with black (R: 0, G: 0, B: 0). Place this black layer beneath the one with the colored elements.
  1. Flatten your image (in Photoshop this can be done by navigating to Layer | Flatten Image):
  1. Save your file in your image editor, and return to Unity.
  2. Select the m_card Material in the Project panel. Check the Emission property – three new properties should appear:
    • A Texture slot: Set this to Texture card_emission (drag asset file from the Project panel)
    • A Color slot: Set this to white (R: 255; G: 255; B: 255)
    • A Global Illumination drop-down menu: Ensure this is set to Baked (so that its glow won't be added to the Lightmaps or influence the illumination in Real-Time):