Tháng Mười 20, 2020

Simple Vision Area (Простая область видимости)

Good afternoon Today I would like to talk about how to make a simple vision area You can see an example of such an area on the screen We have the ability to change the viewing angle range or outer radius inner radius color and transparency We can also switch between two types of materials We are now using “Decal Material” and now ordinary translucent material As an example of the use of such material we can look at the rabbit simulation So.

Let's hide the table The yellow area is responsible for the hearing zone, green for visibility our rabbits Let's turn off the yellow zone For clarity, highlight water and food and hide all unnecessary Yes Now we can quite easily understand what objects rabbits see Let's create a new project Launch Unreal Engine Games ThirdPerson Blueprint and StarContent I will name the project VisionArea Let's create a working dad right away In it, we create a master material called “VisionArea” Set “Blend Mode” to “translucent” Create a parameter called “BaseColor” I'm used to without a space May it be green and transparency unit The first node we need is the “RadialGradientExponential” By default it looks like this We want to be able to adjust the radius and blur of borders To do this, create the parameter “ExternalRadius” Outer radius which set to 0.

5 And create the “Density” parameter, which is responsible for blurring the borders We need clear boundaries, so put a thousand As you can see, we have a circle inscribed in a square This is exactly what we need Let's copy these nodes and replace the outer radius with the inner Set value 10 times less Add the “one minus” node so that we get a black circle Now we multiply our expressions, and in the end we get here is such a ring The next node we will need is “VectorToRadialValue” By default, it gives this result We will use the “if” node with you Create a parameter called “HalfAngle” Let him start with 0.

25 If “a” is greater than “b”, then set 0 If “a” is less than “b”, then set 1 We see that with the “HalfAngle” equal to 0.

25, we have a bright quarter circle It will be more convenient for us to work in degrees, so let's immediately divide by 180 And set the value, for example, 45 degrees Then the full angle should be 90 Indeed, it goes We would also like the light region to be located symmetrically with respect to the horizontal axis For this we need the “CustomRotator” node And also “TextureCoordinate” from which we subtract 0.

5 Create the “Rotation Center” parameter And rotate at a “HalfAngle” In order to turn exactly half the angle, we need to divide by 360, not 180 Everything worked out Multiply our expressions And in order to be able to set transparency, we do another multiplication Disable “PreView” We look at the final result He suits us Therefore save and go to the daddy “ThirdPersonBP” Next “Blueprints”, “ThirdPersonCharacter” Here we create a plane Set it along the z axis to “-90” For convenience, let's scale it 10 times And immediately install “NoCollision” So that she does not interact with other objects Next we need to create variables that allow us to customize the vision area Let's first apply the material to our plane As you can see, visually it’s already what we would like Now create the variable “HalfaAngle” Type float Do not forget to set “InstanceEditable” so that it is possible to change variables in the editor And set the category to “VisionArea” Next we need “ExternalRadius” Internal – internal radius Colour The type of variable will be “LinearColor” And a logical variable that allows you to switch between two types of materials So.

Let's set a default value Let us have a half angle of 45 degrees Outside Radius 1500 Inside radius 50 Color will be blue Transparency 0.

5 In “UseDecal” we’ll set the default a tick Go to “ConstructionScript” First thing we do Create a “DynamicMaterialInstance” As a parent, we use our material – “VisionArea” We write it to the variable Next, install this material on our plane Visually nothing has changed It should be so In order to set the value half angle, use the node “SetScalarParameterValue” In the parameter “Name” we must write the name, which is set for our parameter in the material In this case, the name of the variable and the parameter are the same Let's set the outer radius To do this, we need to scale the plane The outer radius must be divided by 50 and set the resulting value for “x” and “y” On the axis “z” we leave in unit Define the inner radius To do this, again use the node “SetScalarParameter” The name of the parameter is “InternalRadius” Now we divide “InternalRadius” into “External” and multiply by 0.

5 A little later, we will verify that we have set the radii correctly So.

We also need to set the color To do this, use the node “SetVectorParameterValue” The name of this parameter is “BaseColor” It seems that all we need is set.

Let's check Yes.

Color has changed The radius also changes Half angle is changing Fine.

Now check that radii are set correctly To do this, we will add a sphere Set it to the height of the plane Let's make smaller for convenience x=50 set Yes.

We have an internal radius of 50 And the border coincides with the sphere Now let's set the value of one and a half thousand, corresponding to the outer radius And make sure that our sphere is on the outer border It's like that We look how it looks in the editor Angle changes Range is changing Color changes Everything is as it should be In addition, “UseDecal” does not affect anything yet Let's duplicate our material Let's call it “DecalVisionArea” and change the “Material Domain” from “Surface” to “DeferredDecal” Save changes So.

Let's make the plane invisible now Add a component called “decal” “DecalMaterial” It projects material along the x axis on those surfaces that are inside the green area To make it clear, let's add an auxiliary plane Let it also be located at a height of “-90” Scale it And try to rotate our “DecalMaterial” See what happens We rotated it 90 degrees and we see a tile pattern, which was projected onto our character and onto the plane Let's set our material And associate the material parameters with our variables It will be almost all the same as for the plane with a slight difference In this node, we change the parent material to “DecalVisionArea” This node will have to be replaced because “DecalMaterial” does not have a “SetMaterial” node There is a node “SetDecalMaterial” This node remains the same Here we make some changes Since the axes in our “DecalMaterial” are different, then we change the connection And here you need to specify 256 place 50 Inner radius and color remain unchanged Let's check that everything is so The outer radius works correctly with us Internal let's check Yes.

Everything is okay with the inside Now we remove all the help plane and sphere and go to the editor Everything seems to work It remains to configure switching Let's do it To do this, add the “if” node And set the visibility for the plane and “DecalMaterial” If we go here, we want to show “DecalMaterial” Here we want to show the plane Save Check Yes, indeed Now switching works for us That's all Thank you for the attention.

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *