• kamilblaszkiewicz

Runtime Virtual Texturing - how to make your project look more realistic

We are working on a next game in the Interregnum universe. As you may remember from our last post it is going to be a tactical, turn based strategy which takes place in an ice-covered landscape. We know that the environment we are creating has to be interesting and despite being covered in snow and ice, has to offer a varied and realistic looking landscape for the player. From the technical point of view we are using the Runtime Virtual Texturing feature in Unreal Engine 4 to achieve these goals. RVT generates and caches data in memory using the GPU at runtime. It can be used to blend objects with the terrain, so the landscape looks more natural. This short guide will help you set up and use RVT in your project. Let's get started!

1. Project Setup

In order to use RVT you need to enable it in your project first. Navigate to Edit options -> Project Settings. Find the Rendering tab and scroll down to Virtual Textures category and Enable virtual texture support.

Now it's time to restart the engine and wait for shaders to compile.

2. Create a Runtime Virtual Texture Asset

Use the Content Browser and add a Runtime Virtual Texture Asset from the Materials & Textures submenu.

Set a name for your RVT and double click on it to open it's properties. Here you can set the size and the content of the texture. We will start with YCoCg Base Color, Normal, Roughness, Specular option.

3. Add texture to the landscape

Find the Virtual Texture tab in the Landscape details and simply drag and drop your RVT there from the Content Browser.

4. Add Runtime Virtual Texture Volume

Use Place Actors panel and drag Runtime Virtual Texture Volume into the scene.

Next find the Virtual Texture tab in the RuntimeVirtualTextureVolume details and again drag and drop your RVT there from the Content Browser, the same way as in step 3.

Now select your Landscape in Transform from Bounds section and click on the Set Bounds button in order to cover whole Landscape with the created Runtime Virtual Texture Volume.

5. Add Runtime Virtual Texture Material

Open the Landscape Material, add Runtime Virtual Texture Output and connect it to the GetMaterialAttributes node, so it's attributes can be written to the virtual texture.

After compiling shaders the texture is being rendered. Now we can use it to create an asset that will sample attributes from the virtual texture. In our case it will be the pavement material.

In the pavement material add Runtime Virtual Texture Sample, select previously created RVT in the details section, connect the Base Color node and press Save.

As we can see, the pavement material samples colors from the landscape now.

We want to create a well looking blending between pavement and the terrain. To do so we need to create another virtual texture, where information about world height will be written.

Repeat step 2 and create another Runtime Virtual Texture Asset. This time in the properties we will choose World Height.

Add the texture to the Landscape (see step 3).

Also add the texture to the Runtime Virtual Texture Volume. There is only one slot for a virtual texture, so you need to duplicate Runtime Virtual Texture Volume, add virtual texture which stores height information to the second volume, select the Landscape and press Set Bounds (see step 4).

In the next step open the landscape material, add Absolute World Position block and connect it to the Runtime Virtual Texture Output via mask to supplement it with information about terrain height.

Open the pavement material and add another Runtime Virtual Texture Sample, select RVT with World Height information in the details section.

Now in order to create a nice blending we need to add Bias parameter to the height value, and the formula and your material should look like this:

In the next step add Saturate block, which is going to limit our output to absolute values.

Finally add Interpolate (Lerp) blocks to determine A or B values depending on the alpha input.

Your material should look like this:

As a result blending between our pavement and the landscape is being created.

Congratulations! After setting up a Landscape material to use a Runtime Virtual Texture, you can now experiment with other actor's materials to render them to the RVT.

84 views0 comments