Creating Interactive Grass in Unreal Engine 4

In this Unreal Engine 4 tutorial, you will learn how to create interactive grass by using a scene capture and particles to create a vector field. By Tommy Tran.

Leave a rating/review
Download materials
Save for later
Share
You are currently viewing page 2 of 3 of this article. Click here to view the first page.

Creating the Direction Material

There are two ways to create a direction brush:

  1. Mathematically: This is where you define the directions and shape within the material. The advantage of this is that it doesn’t require external software and is easy for simple shapes.
  2. Converting Normal Map: This is where you create a normal map of your desired directions and shape. To convert to a usable vector field, you just need to remove the blue channel. The advantage to this method is that you can easily create complex shapes. Below is an example of a brush that would be difficult to replicate mathematically.

unreal engine grass

For this tutorial, you will create one mathematically. Navigate to the Materials folder and open M_Direction. Note that this material’s shading model is Unlit. This is important because this will allow the scene capture to capture the particles without light affecting them.

To keep things simple, you will create a material that will cause grass to move away from the center of the particle. To do this, create the following:

unreal engine grass

Now you need to do the remapping. To do this, add the highlighted nodes and connect everything like so:

unreal engine grass

Next, let’s give it a circular shape. To do this, add the highlighted nodes:

unreal engine grass

RadialGradientExponential is what controls the circle’s size and hardness. Multiplying it with Particle Color will allow you to control the particle’s opacity from the particle system. I’ll go into more detail about this in the next section.

Here is what the brush looks like:

unreal engine grass

Click Apply and then close the material. Now that you have the material created, it’s time to create the trail particle system.

Creating the Trail Particle System

Navigate to the ParticleSystems folder and open PS_GrassTrail. To save time, I have already created all the modules you’ll need.

unreal engine grass

Here’s how each module affects the grass trail:

  • Spawn: The spawn rate affects how smooth your trail will be. If your trail looks "choppy", you should increase the spawn rate. For this tutorial, we’ll leave it at the default value of 20.
  • Lifetime: Duration of the trail before the grass goes back to its default state
  • Initial Size: Size of the trail
  • Color Over Life: Since you are using Particle Color in the material, you can control the opacity here. You can also adjust the alpha curve to control how the trail fades. For example, you could do linear fading, easing in and/or easing out. For this tutorial, we’ll leave this at the default which is a linear fade.
  • Lock Axis: Used to make sure the particles face towards the scene capture
  • Initial Rotation: Used to make sure the particles are oriented towards the correct axes (more on this soon)

First, you need to set the material. Select the Required module and then set Material to M_Direction. While you’re here, also set Sort Mode to PSORTMODE Age Newest First.

unreal engine grass

This sort mode will ensure that newer particles will render on top of older particles. If you don’t do this, older particles could affect the grass instead of a newer particle.

Up next is the duration of the trail. Select the Lifetime module and set Constant to 5. This will cause the trail to fade over five seconds.

unreal engine grass

Next is the trail size. Select the Initial Size module and set Constant to (150, 150, 0). This will make each particle cover a 150×150 area.

unreal engine grass

Now you need to make sure the particles face towards the scene capture. Since the scene capture is capturing from above in this tutorial, particles will need to face the positive Z axis. To do this, select the Lock Axis module and set Lock Axis Flags to Z.

unreal engine grass

Finally, you need to set the particle’s rotation. Currently, the colors in the brush are not aligned with the direction they represent. This is because by default, the particle system will apply a 90 degree rotation. To fix this, select the Initial Rotation module and set Constant to -0.25. This will rotate the particle back 90 degrees counterclockwise.

unreal engine grass

That’s all you need for the particle system so go ahead and close it.

Next, you need to attach the particle system to whatever you want to create trails. In this case, you’ll attach it to the player character.

Attaching the Particle System

Navigate to Characters\Mannequin and open BP_Mannequin. Afterwards, create a Partice System component and name it GrassParticles.

unreal engine grass

Next, you need to set the particle system. Go to the Details panel and set Particles\Template to PS_GrassTrail.

unreal engine grass

It would be strange if the player could see the trail in-game so it’s a good idea to hide it from the player. To do this, enable Rendering\Owner No See.

unreal engine grass

Since the particle system is attached to the player (the owner), the player won’t see it but it will still be visible to everything else.

Click Compile and then press Play. Notice how the particles don’t appear for the player camera but still show up in the render target.

unreal engine grass

Right now, the scene capture is set up to capture everything. Obviously this is no good since the particles are the only thing that should affect the grass. In the next section, you will learn how to only capture the particles.

Capturing Particles

If you capture the particles right now, you would get undesired bending in areas without particles. This is because the render target’s background color would be black. The bending happens because black represents movement towards the negative XY axes (after remapping). To make sure empty areas have no movement, you need to make sure the render target’s background color is (0.5, 0.5, 0). An easy way to do this is to create a giant plane and attach it to the player.

First, let’s create the material for the background. Go back to the Content Browser and open Materials\M_Background. Afterwards, connect a constant of (0.5, 0.5, 0) to Emissive Color.

unreal engine grass

Note: Just like the particle material, any material you plan on capturing needs to be unlit.

Click Apply and then close the material. Go back to BP_Mannequin and then create a new Plane component. Name it Background.

unreal engine grass

Next, set the following properties:

  • Location: (0, 0, -5000). This will place it low enough so that it doesn’t occlude any particles.
  • Scale: (100, 100, 1). This will scale it large enough so that it covers the capture area.
  • Material: M_Background

unreal engine grass

Just like the particles, it would be strange if the player could see a giant yellow plane below them. To hide it, enable Rendering\Owner No See.

unreal engine grass

Now that the background is all set up, it’s time to capture the particles. You can do this by adding the particle system to the scene capture’s show-only list. This is a list of components that the scene capture will capture exclusively.

Tommy Tran

Contributors

Tommy Tran

Author

Over 300 content creators. Join our team.