How to Display Deformable Terrains in Unity

How to Display Deformable Terrains in Unity

Deformable Terrains, dynamically simulated in Vortex Studio, can be rendered in Unity during simulation. When a Deformable Terrain is loaded, a deformable terrain prefab is loaded from an asset bundle file located in the same directory as the Vortex file that contains the Deformable Terrain.

Manually creating prefabs and Asset Bundles

To manually create assets for the Deformable Terrain, a Unity project with the Vortex Integration Package is needed (such as VortexUnityTools or your own project), some deformable terrain and terrain prefabs must be added and the assets must be packaged in asset bundles.

For an overview of the assets workflow, refer to Workflow for Preparing and Using Assets for a Vortex Simulation with Unity Graphics.

Deformable Terrain Prefabs

At simulation time, when a Deformable Terrain instance is added, the Vortex Integration will look for a deformable terrain prefab with a specific name. The prefab name must contain the Deformable Terrain hierarchy from the Vortex Editor explorer without the parent element that is contained in a Vortex file. The hierarchy levels are separated with period characters. Folders are omitted from the hierarchy. The name and hierarchy are case sensitive.

For example, for the following hierarchy, the prefab name would be Deformable Terrain.

Creating a Deformable Terrain Prefab

The deformable terrain prefab must have a Vortex Deformable Terrain component and a Vortex Deformable Terrain Renderer component.

  1. Create an empty GameObject

  2. Rename it with the proper name (see the deformable terrain Prefabs section introduction)

  3. Select the created GameObject and add the VortexDeformableTerrain and VortexDeformableTerrainRenderer components in the inspector

  4. Create a new material based on the DefaultDeformableTerrainShader shader and assign it to the VortexDeformableTerrainRenderer material field

  5. Drag and drop the GameObject somewhere in the Assets folder in the project pane to create the prefab
    You can create folders in in the assets folder to store the prefabs 

In the following section, we present in great detail the required components and materials that compose a deformable terrain prefab.

The VortexDeformableTerrain Component

The VortexDeformableTerrain component is in charge of managing the deformable terrain data and to updating the renderer.

These public fields can be configured through the inspector:

Field

Description

Field

Description

Height Offset

An height offset that can be applied to the deformable terrain.

Hole Offset Factor

An offset factor to shrink down the hole created in the terrain where the Deformable Terrain is located.

Heights Blur Radius

Sets the smoothing factor on the deformable terrain geometry

Heights Blur Distribution Factor

Distribution factor that affects the heights blurring (the factor is the standard deviation on a normal distribution). 

Disturbed Soil Blur Radius

Sets the smoothing factor for the transition between undisturbed and disturbed soil.

Disturbed Soil Blur Distribution Factor

Distribution factor that affects the undisturbed and disturbed soil transition blurring (the factor is the standard deviation on a normal distribution). 

The VortexDeformableTerrainRenderer Component

This component is used to render the deformable terrain as a dynamic mesh. The mesh is generated once and updated based on the incoming deformable terrain data.

These public fields can be configured through the inspector:

Field

Description

Field

Description

Material

The Unity material assigned to the generated deformable terrain mesh. The material must be based on the DefaultDeformableTerrainShader.

The Deformable Terrain Material

The material must be based on the DefaultDeformableTerrainShader. To get a seamless transition between the overlapped terrain and the Deformable Terrain un-disturbed soil, the material must use the same parameters as the terrain meshes it intersects. The disturbed soil look can be controlled independently. The material will support intersections with up to two different terrain meshes.

These public fields can be configured through the inspector:

Field

Description

Field

Description

BaseMap<n>

The color texture used on the un-disturbed soil on the terrain mesh <n>. It must use the same texture from the intersected terrain material.

NormalMap<n>

The normal texture for the un-disturbed soil on the terrain mesh <n>.  It must use the same texture from the intersected terrain material.

Metallic<n>

Determines how “metal-like” the surface is (between 0 and 1). It must match the value from the intersected terrain material on the terrain mesh <n>.

Smoothness<n>

Determines how smooth the surface is (between 0 and 1). It must match the value from the intersected terrain material on the terrain mesh <n>.

Disturbed Soil Albedo

The color texture for the disturbed soil

Disturbed Soil Normal Map

The normal texture for the disturbed soil

Disturbed Soil Normal Strength

The strength of the normal from the normal texture

Disturbed Soil Texture Tiling

The disturb soil texture texture tiling