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

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:

主站蜘蛛池模板: 大丰市| 包头市| 阳江市| 呈贡县| 兴安盟| 留坝县| 陕西省| 磐石市| 大宁县| 绿春县| 郧西县| 遵化市| 凤冈县| 汶川县| 韶关市| 常山县| 龙陵县| 泽州县| 清远市| 阿拉善左旗| 贺兰县| 克东县| 通江县| 石河子市| 天门市| 灵寿县| 庐江县| 灵山县| 和静县| 深州市| 虎林市| 朝阳市| 策勒县| 肃南| 藁城市| 泸水县| 乐平市| 余江县| 土默特右旗| 古丈县| 公安县|