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

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. 

主站蜘蛛池模板: 宜宾市| 二手房| 西和县| 九龙城区| 志丹县| 高安市| 迁安市| 舞阳县| 富平县| 新绛县| 毕节市| 外汇| 阳江市| 互助| 东乌珠穆沁旗| 桦南县| 清水河县| 神农架林区| 花莲县| 耿马| 柯坪县| 本溪| 吕梁市| 泰顺县| 东辽县| 平邑县| 枞阳县| 枞阳县| 临泉县| 枣庄市| 萨嘎县| 镇远县| 南宁市| 新密市| 永吉县| 旬阳县| 新泰市| 扎兰屯市| 商洛市| 伊金霍洛旗| 广水市|