- Unreal Engine 4 Shaders and Effects Cookbook
- Brais Brenlla Ramos John P. Doran
- 1207字
- 2021-06-24 14:12:15
How to do it...
As we said before, this is the exact same scene we worked on the Color Grading recipe, and with this as our base, we will continue to expand upon the mood that we had previously created. Make sure to select the Camera01 actor and look through its lens as we've been doing lately, as that will ensure that the effects we see are the same. With that out of the way, let's start the recipe:
- Select the PostProcessVolume and scroll down to the Rendering Features section. The first category we can see should be called Post Process Materials be sure to expand that as we'll be using it later on to set up the effects we will be creating. Do also expand the Array section and click on the + button, as we will need that at a later stage as well:

- In order to use any post process materials we first need to actually create one. Head over to the Content Browser and create a new material wherever you want; in my case, and following the structure we've been using through the previous pages, I'm creating it in the following directory: Content Browser / UE4ShadersAndEffects / Assets / Chapter02. The name I've given it is M_PostProcessSample.
The first thing we need to do to our material is to specify that it is a Post Process type of shader. To do so, select the main material node and head over to the details panel—the first category inside the Material section is called Material Domain, and we need to set that to Post Process:

We can start creating the actual functionality after that. The first node we are going to be operating upon is the SceneTexture, so let's create it:
- Right-click in the main Material Graph and look for the SceneTexture option. Once created, head over to the Details panel and change the default value from SceneColor to PostProcessInput0. Doing that will let us access the unadulterated color of the scene, which is what we want at this stage, as we'll be modifying it:

- Create a ComponentMask by right clicking again and typing that same name. Make sure that the R, G and B values are ticked in the Details panel for that mask, and connect the Color output pin from the SceneTexture node to the input pin of our new mask:

The reason we are masking the color of the scene is because we want to play with its RGB values and nothing else. With those two nodes in place we have secured ourselves access to the image that is being rendered, and what we are now about to do is to overlay information on top of that.
Create a TextureSample node (right-click | TextureSample) and assign it the T_PanningDistortion asset to it. This image contains a reddish gradient that we will overlay with the base rendered image of the scene:

- Overlay the previous texture with the color of the scene by creating a Lerp node. You can do this if you hold the T key on your keyboard and click within the boundaries of the main graph or by any other method, such as right-clicking and typing Lerp or looking for that node in the palette. Connect to the A input pin the output of Mask, and the Texture Sample into the pin labeled B. Finally, Connect the alpha channel of our texture to the Alpha input pin for the Lerp:

With that done, connect the output of the Lerp pin to the Emissive Color node on the main material node. Apply and save the material. What we now want to do is to apply the material we have just created as a post processing effect for our scene. Let's get back to the main viewport in order to do so.
- With the PostProcessVolume selected, scroll back to the Post Process Materials section we were previously in and select our newly created material as the asset on the Array, like in the following screenshot:

We should be able to see the effect across the screen one that's done. Even though we've technically just created a new material and we are looking at it, I think we can make it a bit more interesting. Let's get back to the material editor and perform a few more tweaks.
The next bit of functionality that we are going to be creating for our material is a time function. What we basically want to do is to animate our texture, just so that the effect we are creating is not static. Let's make it pulsate over time, making our already creepy scene a little bit more eerie.
- Right-click anywhere within the Material Graph and start typing Time. This will allow us to create a new node that will be used to animate the pulsating effect, as the node introduces the concept of time in our material. Pair it with a constant node, which we'll use to affect how fast the effect pulsates, and combine both of the previous nodes in a Multiply node. Finally, drag from the output pin of the Multiply node and create another one called Sine. The graph should look something like this:

That expression will be driving our future animated material, and we will be able to control how fast it is animated thanks to that constant node we've introduced. The last step in this pipeline is to actually combine the effect we've created with the raw scene color based on this time function:
- Copy the SceneTexture and the Mask nodes and past the above the previously created ones.
- Create a second Lerp node, and connect the output of what we created in the previous step to the A pin.
- Connect the output of the initial nodes we had created, the result of the Lerp between the scene color and out reddish texture to the B pin.
- Finally, connect the time function to the Alpha value of the latest Lerp node. The graph should look something like this:

With all of those changes made, we should now be looking at a much more disturbing scene one which blends between the default "greenish" look and a new reddish gradient, which makes things more creepy.

Any other effects would have been possible; the possibilities are almost endless. Be sure to check out further chapters when we'll start to deal with more advanced effects. Until then, see you in the next section!
- Microsoft Dynamics 365 Extensions Cookbook
- Apache Spark 2 for Beginners
- Visual Basic程序設計(第3版):學習指導與練習
- NativeScript for Angular Mobile Development
- The DevOps 2.5 Toolkit
- R語言與網絡輿情處理
- Visual FoxPro程序設計習題集及實驗指導(第四版)
- Java程序設計入門
- Clean Code in C#
- C++ Application Development with Code:Blocks
- 一步一步跟我學Scratch3.0案例
- 原型設計:打造成功產品的實用方法及實踐
- FusionCharts Beginner’s Guide:The Official Guide for FusionCharts Suite
- Azure for Architects
- Python實戰指南:手把手教你掌握300個精彩案例