- Unreal Engine 4 Shaders and Effects Cookbook
- Brais Brenlla Ramos John P. Doran
- 803字
- 2021-06-24 14:12:18
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:
- 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!
- 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:

- 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:

- 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!
- 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.
- Connect each of the Constant3 vectors to the A and B pins of the Lerp node.
- 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.
- 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.
- 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:

- 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:

- C++面向?qū)ο蟪绦蛟O(shè)計(jì)(第三版)
- Mastering Entity Framework Core 2.0
- Machine Learning with R Cookbook(Second Edition)
- PowerCLI Cookbook
- 征服RIA
- C語(yǔ)言程序設(shè)計(jì)
- Bootstrap 4:Responsive Web Design
- Linux命令行與shell腳本編程大全(第4版)
- Hands-On Natural Language Processing with Python
- Android系統(tǒng)級(jí)深入開(kāi)發(fā)
- RealSenseTM互動(dòng)開(kāi)發(fā)實(shí)戰(zhàn)
- OpenCV with Python By Example
- R語(yǔ)言:邁向大數(shù)據(jù)之路(加強(qiáng)版)
- Clojure Polymorphism
- 30天學(xué)通C#項(xiàng)目案例開(kāi)發(fā)