Runtime Virtual Texture (RVT) in Unreal Engine 4

Implementing Snow Surface Deformation System

Thuvarahan Sivaneswaran
Arimac
6 min readJan 5, 2021

--

Runtime Virtual Texture (RVT) is a new feature available in Unreal Engine from its version 4.23, which generates and caches its texel data in memory on demand using the GPU at runtime. With this feature, material could directly draw to a Runtime Virtual Texture (RVT) within the material editor, as well as sample a RVT texture.

Past Solution

Before the introduction of Runtime Virtual Texture in Unreal Engine, Render Target has been commonly used for implementing terrain blending and landscape deformation systems. Render Targets are textures that can be drawn onto at runtime. Shapes and materials can be drawn to a specific texture by using blueprint code. Render Target requires all materials to be of type additive, so that they can be drawn on top of one another in the same texture. Once everything was drawn to the texture, it needs to be cleared manually by calling Clear Render Target 2D node in the blueprint code, in order to reset and start the process again. This process sometimes causes flickering issues.

Drawbacks of Render Target

  • Limited size of texture
  • Large number of steps to draw to the render target
  • Inability to translate the size and location from a hit point into the size of the render target
  • Limited number of channels to set as different masks (RGB, and alpha required the material to set as AlphaComposite)
  • Unsupported lighting
  • World Position node returning unexpected values at times

Benefits of Runtime Virtual Texture

  • Support large texture resolutions (Landscape shading)
  • No need for blueprints to handle the drawings of materials onto a texture
  • Suitable for procedural patterns and composite layered materials
  • Foliage instances (for decal scattering)
  • Useful to create spline decal-type effect
  • Gives natural look when blending grass, rocks and water with landscapes

Snow Trails Implementation

Let us see how we can use Runtime Virtual Texture to create snow trails for a character. For this demonstration, a drawer material and a receiver material are used.

Getting Started

At first, go to Project Settings. Under the Engine > Rendering > Virtual Textures category, set Enable virtual texture support to true.

Setting up Runtime Virtual Texture (RVT)

Create a Runtime Virtual Texture asset named as “RVT” in the project directory.

Go to Add New > Blueprint Class, search for RuntimeVirtualTextureVolume under All Classes section, and select it to create a new blueprint class named as “RVT_Volume”.

Open the “RVT_Volume” blueprint class, go to the details tab of VirtualTextureComponent, and under the Virtual Texture category, assign the “RVT” asset to Virtual Texture.

Place the “RVT_Volume” in a level, and scale and rotate it to encompass the landscape. This scaling is done because the Drawer will stop rendering to the RVT if the landscape moves out of the volume bounds.

Creating the Footprint Material

Now, create a footprint material named as “M_Footprint” which will act as the Drawer in Runtime Virtual Texture. The Drawer will output a circle using the RadialGradientExponential function into a RVT BaseColor output.

Make sure to connect the RadialGradientExponential function to RVT Opacity output to achieve smooth deformation where multiple trails can overlap each other. “Radius” and “Density” of the footprint can also be adjusted by creating two scalar parameters and connecting them to respective input pins in the RadialGradientExponential function.

Creating the Landscape Material

Create a landscape material named as “M_Snow” which will act as the Receiver in Runtime Virtual Texture. The Receiver will sample the “RVT” asset, use its BaseColor to linearly interpolate between ‘Snow Color’ and ‘Ground Color’, and connect it to the material’s Base Color output.

In the details tab of the landscape material, under the Tessellation category, set the Tessellation Mode to ‘PN Triangles’, Maximum Displacement to any positive value (ex: 256), and Crack Free Displacement to true, to get World Displacement and Tessellation Multiplier outputs enabled in the material.

The BaseColor from the RVT sample is used with a scalar parameter named “Height” along vertex normal in order to achieve a height for the deformable snow surface. Here, a positive value should be applied for Tessellation Multiplier to enable the visibility of World Displacement in gameplay.

Apply the material “M_Snow” to the landscape.

Deforming the Landscape

Now, let us look at how we can obtain snow deformation while character is walking.

Open the character blueprint, place two nodes of Add Static Mesh Component, and connect their Relative Transform to the socket locations of both feet of the character. This could be called every frame by connecting with Event Tick.

Set the Static Mesh and Material of both Add Static Mesh Component nodes to a Plane and “M_Footprint” respectively.

Further, set Collision Presets to ‘NoCollision’. Uncheck Cast Shadow and add the “RVT” asset to the Render to Virtual Textures array. Set the Virtual Texture Pass Type to ‘Virtual Texture Only’ so that those planes will not be visible while playing.

The RVT should now appear being rendered to the landscape which has the Receiver material applied to it.

In order to avoid creating footprint while the character is jumping, a Branch node can be connected to check whether the character is walking or not, before adding the footprint plane mesh.

Snow deforms while character is jumping

A condition to check whether the velocity of the character is greater than zero can be joined with the previous condition using AND node, to avoid continuous creation of footprint while the character is in idle state.

Snow deforms while character is in idle state

Height Intensity can be controlled from the Drawer material as well. In the “M_Footprint” material, a scalar parameter named as “Intensity” with a positive value (ex: 10) is multiplied with RadialGradientExponential to obtain required depth of deformation. Note that the Intensity of the Drawer will be limited to the height set in the Receiver material. Assume that the Receiver is a maximum height multiplier that the Drawer can reach.

Once all these processes are made, snow trails of the character will be visible while player is walking along the snow surface.

Final result of snow surface deformation system

This demonstration of implementing basic deformable snow trails of a character was made using Unreal Engine 4.25. This process can also be applied to deform different types of surfaces like sand, mud, water, grass, etc.

Note that skinned and animated primitives cannot be used to render to RVT. However, Runtime Virtual Texture allows many possibilities to be performed that may have been previously limited to Render Targets. Since Runtime Virtual Texture has been still under development, let us hope that many features will be available in future updates of Unreal Engine.

References

  1. https://docs.unrealengine.com/en-US/RenderingAndGraphics/VirtualTexturing/Runtime/index.html
  2. https://docs.unrealengine.com/en-US/RenderingAndGraphics/VirtualTexturing/Runtime/QuickStart/index.html
  3. https://docs.unrealengine.com/en-US/RenderingAndGraphics/RenderTargets/BlueprintRenderTargets/HowTo/CreatingTextures/index.html
  4. https://docs.unrealengine.com/en-US/Resources/ContentExamples/MaterialNodes/1_12/index.html
  5. https://www.youtube.com/watch?v=4T0bAx2dXMw

--

--

Thuvarahan Sivaneswaran
Arimac

Former Game Developer Intern @Arimac, Undergraduate — CSE @University of Moratuwa.