📜 ⬆️ ⬇️

Creating PostProcess Material for a Cure Effect in the Unreal Engine 4

When developing the game, we are faced with the need to display information so that the user noticed it. For example, picking up a first-aid kit, players do not always notice that health begins to increase in the corner of the screen in the HUD. Thus, the task of adding a visual effect on top of the gameplay appeared.

image


Task . It is necessary to show the effect of treatment. From the bottom of the screen fly plus signs, each of them rocking left-right, changes brightness and smoothly disappears in the center. All this is done through PostProcess.

First of all, prepare the texture with the pluses that you need for the effect. Each channel contains specific information:
')
Red - the minimum brightness of the plus sign.
image


Green - the initial shift of the plus movement horizontally.
image


Blue - an area in which the plus signs will be visible (in the center they will disappear almost immediately, fly along the edges above).
image


Transparency - the amplitude of swinging a plus sign.
image


As a result, we get the following texture:

image


To avoid artifacts above and below the plus signs, you need to adjust the texture when importing into the Unreal Engine as follows:

image


When the texture is ready and imported, create a new material. In the material settings, set the Material Domain property in PostProcess.

image


The writing of the material itself can be divided into several stages.

First , you need to add the movement of the plus signs up. To do this, call Panner from Screen Position and specify in the parameters the speed for Y = 0.2. Thus, our texture will gradually move up.

To ensure that the plus signs are evenly distributed across the screen and not stretched, the texture coordinates along X are multiplied by the ratio of the screen width to the height. Add a half fractional shift. And we multiply the texture coordinates on the CoordsScale (in our case it is 2), so that there are more pluses and they are smaller (we didn’t have to spend a lot of time drawing a lot of pluses in the texture).

image


Secondly , add swinging plus signs. From the green component of the texture we take the value of the initial shift, multiply by the period of wiggle and add the current time to Time. All this is passed to the function LinearSine and the result is multiplied by the amplitude of wiggle. The resulting value is added to the texture coordinate for X.

image


Third , change the brightness of the plus signs. According to the new texture coordinates, we get the initial brightness value (red channel of the texture), which will change to 1 and back. The resulting brightness is: (1 - red) * RoundedLinearSin + red . Where RoundedLinearSin is the value from 0 to 1 from the LinearSine function, and red is the value from the red channel. The result is multiplied by the color of the plus sign (light green in our case).

Brightness is used to blend with the current image of the scene to impose our effect on top of the game process. To do this, multiply it by the rounded up (Ceil) value from the red channel (so that nothing outside the plus sign is blinking). Then, the value of the blue channel, which we take on screen coordinates. This will add the effect of fading plus signs closer to the center of the screen. In addition, we need the Scale parameter, which is useful for the gradual appearance of the effect of treatment. The resulting value is used for linear interpolation (Lepr) between the image of the scene and the color of the plus sign.

image


In order not to perform unnecessary calculations where it is not necessary, we add a condition that checks where there is definitely no plus sign. As a result, we got such material (the image is clickable):

image


It remains only to cause a smooth appearance and disappearance of the effect when picking up the first-aid kit and at the end of its action. Add a timeline in which we change the Scale parameter and events to start and end the effect.

image


And of course the video with the result:

Source: https://habr.com/ru/post/315356/


All Articles