Creating snow tracks in Unreal Engine 4 (2023)

In this Unreal Engine 4 tutorial, you'll learn how to create deformable snow trails using scene capture and render targets

If you've been playing AAA games recently, you might have noticed a trend toward snowy landscapes. Some examples areHorizon Zero Dawn,Rise of Tomb RaidereGod of WarπŸ‡§πŸ‡· In all these games, one thing stands out in the snow: you can make tracks in the snow!

Allowing the player to interact with the environment in this way is a great way to increase immersion. It makes the environment more realistic and, let's be honest, it's a lot of fun. Why spend hours designing fun mechanics when you can just throw yourself on the ground and build snow angels?

In this tutorial you will learn how to:

  • Create tracks using scene capture to mask objects close to the ground
  • Use a mask on landscape material to create deformable snow
  • Show only tracks around the player for optimization

Monitoring:This tutorial assumes you already know the basics of using Unreal Engine. If you're new to Unreal Engine, check out our 10-part guideUnreal Engine for beginnersseries of tutorials.

Monitoring:This tutorial is part of a three-part tutorial series on using render targets in the Unreal Engine:

starting

First, download the materials for this tutorial (you'll find a link at the top or bottom of this tutorial). Unzip it and navigate toSnowDeformationStarterand openSnowDeformation.uprojectπŸ‡§πŸ‡· In this tutorial you will create tracks with a character and some boxes.

Creating snow tracks in Unreal Engine 4 (1)

Before we start, you should know that this tutorial's method only saves tracks in a defined area and not in the whole world. This is because performance depends on the resolution of the render target.

For example, if you want to save tracks for a large area, you need to increase the resolution. However, this also increases the performance impact of scene capture and the memory size of the render target. To optimize this, you need to limit the effective area and resolution.

Now that we've got that out of the way, let's look at what you need to create snow tracks.

Implementation of snow trails

The first thing you need to create tracks is arender targetπŸ‡§πŸ‡· The render target is a grayscale mask where white indicates a trace and black is no trace. You can then project the render target onto the ground and use it to blend textures and offset vertices.

Creating snow tracks in Unreal Engine 4 (2)

The second thing you need is a way to mask only the objects affecting the snow. You can do this by first rendering the objectscustom depthπŸ‡§πŸ‡· So you can use oneScene Capturecommonpost-processing materialto mask all objects rendered with custom depth. You can then send the mask to a render target.

Monitoring:A scene capture is basically a camera with the ability to send to a render target.

The important part of scene capture isWoyou put. Below is an example of the render target captured by abaldVision. Here the third-person character and the boxes have been masked.

Creating snow tracks in Unreal Engine 4 (3)

At first glance, a top-down approach seems to be the way to go. The shapes seem to be accurate for the stitches so it shouldn't be a problem right?

Not exactly. The problem with a top-down shot is that nothing is captured below the widest point. Here is an example:

Creating snow tracks in Unreal Engine 4 (4)

Imagine the yellow arrows stretching to the ground. With the cube and cone, the arrowhead is always inside the object. However, in the case of the bullet, the arrowhead leaves the bullet as it nears the ground. But as far as the camera can tell, the arrowhead is always inside the sphere. This is what the sphere would look like to the camera:

Creating snow tracks in Unreal Engine 4 (5)

This makes the bullet's mask larger than it should be, even though the area of ​​contact with the ground is small.

An extension of this problem is that it is difficult to determine if an object is touching the ground.

Creating snow tracks in Unreal Engine 4 (6)

One way to fix both of these problems is to capturebackgroundInstead of.

Shot from below

The bottom shot looks like this:

Creating snow tracks in Unreal Engine 4 (7)

As you can see, the camera now captures the bottom touching the ground. This solves the "further range" problem of top-down detection.

(Video) Unreal Engine Basic Dynamic Snow Tutorial - with Runtime Virtual Textures - UE4.25

To determine if the object is touching the ground, you can use a post-processing material to do a depth check. This would check if the depth of the object is greater than the depth of the groundeless than a specified offset. If both conditions are true, you can mask that pixel.

Creating snow tracks in Unreal Engine 4 (8)

Below is an example of the engine with a detection zone of 20 units above the ground. Note that the mask only appears when the object passes a certain point. Also notice that the mask gets whiter the closer the object is to the ground.

Creating snow tracks in Unreal Engine 4 (9)

First, let's create a post-process footage to do the depth check.

Creating the depth test material

To perform a depth check, you must use two depth buffers. One for the ground and one for objects that affect snow. Since the scene shot will only see the ground,scene depthwill create the depth of the bottom. To preserve the depth of the objects, simply post-render themcustom depth.

Monitoring:To save time I already rendered the character and boxes at custom depth. If you want to add objects that affect snow, make sure you check this optionRenderizar CustomDepth Passon them.

First you need to calculate the distance of each pixel to the ground. OpenMaterials\PP_DepthCheckand then create the following:

Creating snow tracks in Unreal Engine 4 (10)

Next you need to create the capture zone. To do this, add the marked nodes:

Creating snow tracks in Unreal Engine 4 (11)

Well, if the pixel is indoors25Ground units, it will appear in the mask. The masking intensity depends on how close the pixel is to the ground. clickApplyand then back to the main editor.

Next you need to create the scene capture.

Creating the Scene Capture

First, you need a render target to record the scene capture. Navigate toRendering Goalsfolder and create a new onerender targetcalledRT_Capture.

Now let's create the scene capture. For this tutorial, you'll add a scene capture to a blueprint because you'll need to create some scripts later. OpenProjects\BP_Captureand then add a2D-Dinner-Capture-KomponenteπŸ‡§πŸ‡· SayScene Capture.

Creating snow tracks in Unreal Engine 4 (12)

First you need to set the recording rotation to face the ground. Go to details section and setrotationto the(0, 90, 90).

Creating snow tracks in Unreal Engine 4 (13)

Next comes the projection type. Because the mask is a 2D representation of the scene, you need to remove any perspective distortion. Set to do thisProjection\Projection typeto thespelling, orthography.

Creating snow tracks in Unreal Engine 4 (14)

Next you need to tell Scene Capture which render target to write to. Set to do thisScene Capture\Texture Targetto theRT_Capture.

Creating snow tracks in Unreal Engine 4 (15)

Finally, you need to use the depth test material. Add toPP_DepthCheckto theRendering Assets\Post-Processing MaterialsπŸ‡§πŸ‡· For post-processing to work, you need to change tooScene Recording\Recording Sourceto theCor Final (LDR) in RGB.

Creating snow tracks in Unreal Engine 4 (16)

After scene recording is set up, you need to specify the size of the recording area.

Set the size of the detection area

Since it's best to use low resolutions for your rendering goal, you need to make sure you're using space efficiently. That means deciding how much area a pixel covers. For example, if the capture area and the resolution of the render target are the same, you get a 1:1 ratio. Each pixel covers an area of ​​1 Γ— 1 (in world units).

A 1:1 ratio isn't necessary for snow trails since you probably don't need as much detail. I recommend using higher aspect ratios as they allow you to increase the capture area while still using a low resolution. Be careful not to increase the aspect ratio too much or details will be lost. For this tutorial, you'll use an 8:1 aspect ratio, which means each pixel is 8 Γ— 8 world units.

You can adjust the size of the detection area by changing theScene Capture\Ortho LatitudeProperty. For example, if you want to capture an area of ​​1024 Γ— 1024, set it to 1024. Since you are using an 8:1 aspect ratio, set it to2048(The default resolution of the render target is 256Γ—256).

Creating snow tracks in Unreal Engine 4 (17)

(Video) UE4: Free Assets In Action - Surface Trails (useful for snow and mud displacement)

This means that the scene capture captures a2048Γ—2048Area. That's about 20 Γ— 20 meters.

The ground material also needs access to the capture size in order to correctly project the render target. A simple way to do this is to store the capture size in aCollection of material parametersπŸ‡§πŸ‡· This is basically a collection of variables thatanymaterial can access.

Saving the recording size

Go back to the main editor and navigate tomaterialsfolder. Then create oneCollection of material parameterswhich is listed thereinmaterials and texturesπŸ‡§πŸ‡· rename toMPC_Captureand then open.

Next, create a new oneScalars Parameterand name itCaptureSizeπŸ‡§πŸ‡· Don't worry about defining your worth - you do it in Blueprints.

Creating snow tracks in Unreal Engine 4 (18)

times paraBP_Captureand add the marked nodesEvent at BeginPlayπŸ‡§πŸ‡· definitely setcollectionto theMPC_CaptureeParameternameto theCaptureSize.

Creating snow tracks in Unreal Engine 4 (19)

Now any material can get the valueOrtho-Breiteread offCaptureSizeParameter. That was all for the scene recording. clickCompileand then back to the main editor. The next step is to project the render target onto the ground and use it to deform the landscape.

deform landscape

OpenM_landscapeand then go to the details section. Then set the following properties:

  • Two sidesdefined asactivatedπŸ‡§πŸ‡· Since the scene shot is seen from below, it only sees the backs of the floor. By default, the engine does not render back faces. This means that the bottom depth is not stored in the depth buffer. To fix this you need to tell the engine to render both sides of the mesh.
  • D3D11 Tessellationdefined aslevel tessellation(You can also use PN triangles). Tessellation splits the triangles in a mesh into smaller triangles. This effectively increases the resolution of the mesh and allows you to get finer detail when moving vertices. Without this, the apex density would be too low to create a convincing trail.

Creating snow tracks in Unreal Engine 4 (20)

After you enable tessellation,world shifteMosaic Multiplieris activated.

Creating snow tracks in Unreal Engine 4 (21)

Multiples of tessellationcontrols the amount of the mosaic. For this tutorial, leave the connection disconnected, which means the default value of will be used1.

world shifttakes a vector value that describes which direction to move the vertex and by how much. To calculate the value of this pin, you must first project the render target onto the ground.

Designing the render target

To design the render target, you need to calculate its UV coordinates. To do this, create the following configuration:

Creating snow tracks in Unreal Engine 4 (22)

Summary:

  1. First you need to find the XY position of the current vertex. Since you're shooting from below, the X coordinate will be mirrored, so you'll need to flip it back (if you were shooting from above, you wouldn't need to).
  2. This section will actually do two things. First, the render target is centered so that it is in the middle(0, 0)in space. It is then converted from space to UV space.

Then create the highlighted nodes and connect the previous calculation as shown below. Make sure you have theTexturprobetexture forRT_Capture.

Creating snow tracks in Unreal Engine 4 (23)

This will project the render target onto the ground. However, any vertices outside of the capture region will sample the edges of the render target. This is a problem because the render target should only be used on vertices within the capture area. This is how it would look in game:

Creating snow tracks in Unreal Engine 4 (24)

To fix this, you need to mask out any UVs that fall outside of the 0 to 1 range (the capture area). OMF_MaskUV0-1function is a function I built for it. will return0if the UV provided is outside the range 0 to 1, and vice versa1when it's within reach. Masking is performed by multiplying the result by the render target.

After designing the render target, you can use it to mix colors and move vertices.

Using the render target

Let's start mixing colors. To do this, simply connect the1xfor thelerpequals:

Creating snow tracks in Unreal Engine 4 (25)

Monitoring:If you're wondering why I use a1x, it's just to reverse the rendering objective and make the calculations a little easier.

If there is now a trace, the base color is brown. If there is no trace, it is white.

The next step is to move the vertices. To do this, add the highlighted nodes and connect everything like this:

Creating snow tracks in Unreal Engine 4 (26)

(Video) Unreal Engine Winter Map Tutorial

As a result, all snow surfaces rise25Units. Areas without snow have no displacement, which creates the path.

Monitoring:you can changeshiftheightto decrease or increase snow depth. Also note that DisplacementHeight is the same value as the capture offset. Setting them to the same value will give you an accurate deformation. But there are cases where you might want to change them individually, which is why I left them as separate parameters.

CliqueApplyand then back to the main editor. Create an instance ofBP_Captureon the level and set your location(0, 0, -2000)to put it underground. PressToqueand walk around withC,ONE,SeDto deform the snow.

Creating snow tracks in Unreal Engine 4 (27)

Warping works, but there are no traces! This is because the capture replaces the render target with each capture. What you need here is a way to create the pathsstubborn.

Create permanent tracks

To create persistence, you need another render target (thepersistenter Puffer) to save the contents of the recording before overwriting it. Then add the persistent buffer back to capture (after it's replaced). What you get is a loop with each render target writing to the other. That creates consistency.

Creating snow tracks in Unreal Engine 4 (28)

First you need to create the persistent buffer.

Creating the persistent buffer

I go toRendering Goalsfolder and create a new onerender targetcalledRT_ResistantπŸ‡§πŸ‡· You don't need to change texture settings for this tutorial, but for your own project, make sure both render targets use the same resolution.

Next you need a material that will copy the capture to the persistent buffer. OpenMaterials\M_DrawToPersistentand then add aTexturprobeIn the. Set your texture toRT_Captureand connect it like this:

Creating snow tracks in Unreal Engine 4 (29)

Now you need to use the drawing material. clickApplyand then openBP_CaptureπŸ‡§πŸ‡· First, let's create a dynamic instance of the material (you'll need to pass the values ​​later). Add the marked nodesEvent at BeginPlay:

Creating snow tracks in Unreal Engine 4 (30)

Γ–Delete 2D render targetNodes ensure that each render target is on a blank slate before use.

Next, open theDrawToPersistentfunction and add the highlighted nodes:

Creating snow tracks in Unreal Engine 4 (31)

Next, you need to make sure you're drawing to the persistent buffer frame by frame, since the ingestion is frame by frame. Add to thisDrawToPersistentto theevent ticket.

Creating snow tracks in Unreal Engine 4 (32)

Finally, you need to add the persistent buffer back to the capture render target.

Write back to capture

CliqueCompileand then openPP_DepthCheckπŸ‡§πŸ‡· Then add the marked nodes. Make sure you have theTexturprobeto theRT_Resistant:

Creating snow tracks in Unreal Engine 4 (33)

Now that the render targets are writing to each other, you get persistent tracks. clickApplyand then close the material. PressToqueand start hiking!

Creating snow tracks in Unreal Engine 4 (34)

The result looks great, but the current setup only works for one area of ​​the map. If you leave the detection area, the tracks will no longer be displayed.

Creating snow tracks in Unreal Engine 4 (35)

One way to get around this is to move the capture areacomthe player. This means that tracks will always appear in the player's area.

Monitoring:While the capture is in motion, all information outside the capture area is discarded. This means if you return to an area where hiking trails already existed, they no longer exist. Stay tuned for the next tutorial where I show you how to create semi-persistence.

Move the recording

You might think that all you have to do is set the XY position of the recording to the XY position of the player. But when you do that, the render target starts to blur. This is because you are moving the render target in increments smaller than one pixel. When this happens, the new position of a pixel is revealedin betweenPixel. This results in multiple pixels being interpolated into a single pixel. It looks like this:

Creating snow tracks in Unreal Engine 4 (36)

(Video) Path and tracks in the snow / Unreal Engine 4 ///

To fix this, you need to move the recording in discrete increments. What you do is calculate theworld sizeone pixel, and then move the shot in increments equal to that size. Now no pixel will end up between other pixels and therefore no blurring will occur.

First, let's create a parameter to store the capture location. The floor material needs this for the projection math. OpenMPC_Captureand add aVector parametercalledcapture location.

Creating snow tracks in Unreal Engine 4 (37)

Then you need to update the base material to use the new parameter. VicinityMPC_Captureand then openM_landscapeπŸ‡§πŸ‡· Change the first section of the projection math as follows:

Creating snow tracks in Unreal Engine 4 (38)

Now the render target is always projected onto the capture location. clickApplyand then close the material.

Then move the recording in discrete steps.

Motion capture in discrete steps

To calculate the pixel world size you can use the following equation:

(1 / RenderTargetResolution) * CaptureSize

To calculate the new position, use the following equation for each component of the position (in this case, the X and Y positions).

(floor(Position / PixelWorldSize) + 0,5) * PixelWorldSize

Now let's use them in the Capture Blueprint. To save time I created oneSnapToPixelWorldSizeMacro for the second equation. OpenBP_Captureand then open theMoveCaptureOccupation. Then create the following configuration:

Creating snow tracks in Unreal Engine 4 (39)

This calculates the new location and saves the difference between the new location and the current locationMoveOffsetπŸ‡§πŸ‡· If you are using a resolution other than 256x256, make sure to change the highlighted value.

Then add the marked nodes:

Creating snow tracks in Unreal Engine 4 (40)

This will move the recording with the calculated offset. It then saves the new capture location inMPC_Captureso that the soil material can utilize it.

Finally, you need to do a position update for each frame. Close the function and addMoveCapturebeforeDrawToPersistentInsideevent ticket.

Creating snow tracks in Unreal Engine 4 (41)

Moving the shutter is only half the solution. You also need to change the persistent buffer as the capture moves. Otherwise the capture and the persistent buffer will be out of sync and lead to strange results.

Creating snow tracks in Unreal Engine 4 (42)

Moving the persistent buffer

To move the persistent buffer, you must pass the calculated move offset. OpenM_DrawToPersistentand add the highlighted nodes:

Creating snow tracks in Unreal Engine 4 (43)

This moves the persistent buffer with the provided offset. And just like with the base material, you also need to invert the X coordinate and do the mask. clickApplyand then close the material.

Next you need to pass the motion offset. OpenBP_Captureand then open theDrawToPersistentOccupation. Then add the marked nodes:

Creating snow tracks in Unreal Engine 4 (44)

that will convertMoveOffsetin the UV space and then pass it on to the drawing material.

CliqueCompileand then close Blueprint. PressToqueand then run to your heart's content! No matter how far you run, there will always be snow tracks around you.

Creating snow tracks in Unreal Engine 4 (45)

Where to from here?

You can download the finished project from the link at the top or bottom of this tutorial.

You don't have to use the trails in this tutorial just for snow. You can even use it for things like trampled grass (I'll show you how to make an advanced version in the next tutorial).

(Video) Track in the snow | Unreal Engine 4

If you want to do more with landscapes and render targets, I recommend checking it outCreate innovative gameplay effects with Blueprintby Chris Murphy. In this tutorial you will learn how to create a giant laser that will burn the ground and grass!

If there are any effects you'd like to cover, let me know in the comments below!

Videos

1. UE4 - Tutorial - Snow Ground Gather
(Dean Ashford)
2. How to DEFORM LANDSCAPES in Unreal Engine
(UnrealMatter)
3. Sparkling Snow Shader - Advanced Materials - Episode 2
(Ben Cloward)
4. Snow Trails in UE4
(Roman Smirnov)
5. Landscape Deformation in Unreal Engine II - Snow Deformation
(CodeLikeMe)
6. Creating a Winter Road Scene | Unreal Engine
(Cinematography Database)

References

Top Articles
Latest Posts
Article information

Author: Edmund Hettinger DC

Last Updated: 26/09/2023

Views: 6192

Rating: 4.8 / 5 (58 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Edmund Hettinger DC

Birthday: 1994-08-17

Address: 2033 Gerhold Pine, Port Jocelyn, VA 12101-5654

Phone: +8524399971620

Job: Central Manufacturing Supervisor

Hobby: Jogging, Metalworking, Tai chi, Shopping, Puzzles, Rock climbing, Crocheting

Introduction: My name is Edmund Hettinger DC, I am a adventurous, colorful, gifted, determined, precious, open, colorful person who loves writing and wants to share my knowledge and understanding with you.