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

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. 

主站蜘蛛池模板: 金寨县| 桐柏县| 衢州市| 尚志市| 台湾省| 建瓯市| 大庆市| 凤庆县| 怀来县| 阿拉善盟| 湾仔区| 宁都县| 遂宁市| 阳原县| 调兵山市| 北流市| 莎车县| 依兰县| 漳平市| 靖宇县| 石首市| 平乐县| 永寿县| 莎车县| 集贤县| 道真| 滦南县| 丰县| 邳州市| 涡阳县| 武强县| 铁岭市| 巴里| 平武县| 阿瓦提县| 贞丰县| 平远县| 大冶市| 嫩江县| 新安县| 霍州市|