官术网_书友最值得收藏!

How to do it...

Adding a texture to your model using the Standard Shader is incredibly simple, as follows:

  1. In the Sample Code for this chapter that's provided with this book, you can find the basicCharacter model which, by default, has UV information embedded into it, making it so that when we attach a material, it will draw the texture using that information.
  2. Create a new Standard Surface Shader called TexturedShader by going to the Project tab and then selecting Create | Shaders | Standard Surface Shader. Once created, you can type in a new name for the shader and then press Enter
  3. For organization's sake, open the shader and change the first line to the following:
Shader "CookbookShaders/Chapter03/TexturedShader" {
  1.  This will allow us to find the shader inside of the organization we have been using so far for this book.
  2. Create a new material called TexturedMaterial by going to the Project tab and then selecting Create | Material. Once created, you can type in a new name for the material and then press Enter to confirm the change. 
  1. Assign the shader to the material by going to the Inspector tab and then clicking on the Shader dropdown before selecting CookbookShaders/Chapter 03/TexturedShader:

You may also do this by first selecting the material and then dragging the shader file over it in the Project tab.

  1. After selecting the material, drag your texture to the empty rectangle called Albedo (RGB). If you are missing some, there are textures located in this chapter's example code that can be used. If you have followed all of these steps correctly, your material Inspector tab should look like this:

The Standard Shader knows how to map a 2D image to a 3D model using its UV models and textures used in this example were created by Kenney Vleugels and Casper Jorissen. You can find these and many other public domain game assets at Kenney.nl.

  1. To see the UV data in action, in the example code's Models folder, drag and drop the model into the Hierarchy tab. Once there, double-click on the newly created object to zoom in so that you can see the object:
  1. Once there, you may go to the Project tab and open up the Chapter 3 Materials folder and drag and drop our Textured Material onto the character. Note that the model consists of different objects, each of which provides direction to draw in a particular place. This means that you will need to drop the material on each part of the model (ArmLeft1, ArmRight1, Body1, and so on); trying to apply this to the top level of the hierarchy only (basicCharacter) will not work:
  1. It is also possible to change what the object looks like by changing the texture that's being used. For instance, if we use the other texture provided (skin_womanAlternative), we have a very different looking character:

This is often used in games to provide different kinds of characters with minimal cost. 

主站蜘蛛池模板: 东丽区| 兰坪| 宝丰县| 新龙县| 靖宇县| 玛纳斯县| 镇原县| 华蓥市| 灌南县| 达日县| 沂南县| 克拉玛依市| 贡觉县| 永修县| 潼南县| 格尔木市| 武清区| 台安县| 新建县| 湖北省| 花莲市| 嵩明县| 太仆寺旗| 海兴县| 汶川县| 淮阳县| 肇庆市| 霍邱县| 库伦旗| 平阴县| 枣阳市| 大石桥市| 镇江市| 丰镇市| 奇台县| 沧源| 尼木县| 商水县| 育儿| 江孜县| 舟山市|