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

How to do it...

We are going to create our first complex material in Unreal Engine 4! Complex is a word used lightly in this context, as it doesn't have anything to do with the difficulty of creating the asset itself. It's more of a statement: what we are going to be creating from now on are examples that could just as well be real assets in a game studio. 

With that said, the first stop in this journey is going to be the laying down of the foundations of the material. We are going to operate on the material graph by organizing and thinking about how things should be put together. Make sure you have the 03_01_ComplexShader_Start scene open, or any other of your own that you choose, and let's start taking a look at that:

  1. Let's start by creating a new material, so that we can change the appearance of the main model to something more exciting. I've created a new asset, named M_ToyTank, which will be in the following folder: Content / UE4ShadersAndEffects / Assets / Chapter03. You could use that or also create your own!
  2. As the tank has different small parts (the tracks, the barrel, the main body, and so on), chances are that we are going to want to treat those areas differently. To do so, we will need to create masks that fit the selected parts that we want to shade— but before that happens, we need to take a look at how the UVs are laid out. Select SM_ToyTank in the content browser, open the asset editor, and click on the UV button | UV Channel 0. This is what it should look like:
You can export the model from the game engine and alter the UVs in your DCC until you are happy with them. To do this, right-click on the asset within the content browser and select Asset Actions | Export.
  1. There's a small mask that you can use for this example, named T_TankMasks, which you'll be able to find in the same folder as the tank. It's basically an RGB image, which you can see in the following screenshot. Drag that resource into the newly created material, as we'll be using it soon:
  1. Also within the material graph, create two Constant3 nodes, and select whichever color you want under their color selection wheel. Make sure they are different from one another, though!
  2. Next, create a Lerp node. That strange word is short for linear interpolation, and it lets us blend between different assets according to the masks that we connect to the Alpha pin. Connect the red channel of the T_TankMasks asset to that pin of the new node. 
  3. Connect each of the Constant3 vectors to the A and B pins of the Lerp node. 
  1. Create another Lerp node and a different Constant3 vector. Connect the blue channel of our mask into the Alpha of the new Lerp and the new Constant3 vector into the B pin. Finally, connect the output of the previous Lerp into the A slot. Also, make sure to apply the material to the tank in the main scene! The resulting material graph should look something like this:

At this stage, we've managed to differentiate certain areas of the model in our material thanks to using masks. We now need to expand this concept to the Metallic and the Roughness attributes of the material, just so we can also control those independently.

  1. Copy all of the previously created nodes and paste them twice—we'll need one copy to connect to the roughness slot and a different one that will drive the Metallic attribute. 
  1. Replace the Constant3 nodes of the new copies for simple Constant nodes. We don't need an RGB value to specify the Metalness and Roughness properties, so let's tidy that up! The graph should now look something like this:
  1. Assign custom values for the new constant nodes you have created on the Metallic and the Roughness attributes. Remember what we saw in the first chapter: a value of 0 for the roughness slot means that the material has very clear reflections, while a value of 1 means the exact opposite. Similarly, a value of 1 connected to the metallic node means that the material is a metal, while 0 determines that it is not. Let's take a look at the final results!

Finally, think about tidying things up by grouping the different sections of the material graph together. This is done by selecting all the nodes that you want to group and pressing the C key on your keyboard. It keeps things organized, which is very important—especially when working with others or whenever you revisit your own work:

主站蜘蛛池模板: 嘉义县| 敦煌市| 潢川县| 榆林市| 山阳县| 曲阜市| 盘锦市| 吉木萨尔县| 通榆县| 左权县| 阳新县| 塘沽区| 桓台县| 洛扎县| 商河县| 乐都县| 恩平市| 阿克陶县| 江陵县| 若尔盖县| 靖宇县| 香格里拉县| 勐海县| 长武县| 玛曲县| 正安县| 宣威市| 长沙市| 洛阳市| 湖南省| 鸡东县| 四平市| 盐池县| 芦山县| 沙坪坝区| 镇康县| 衡东县| 万山特区| 天柱县| 拜泉县| 吉木萨尔县|