On this page

Houdini height fields can be used to generate Unity terrain. Conversely, Unity terrain can be used as input to generate height fields in Houdini through input nodes (see Terrain Input).

Due to the differences between Houdini height fields and Unity terrain, please follow the instructions below to setup the height field size and layers in an HDA to properly generate Unity terrain.

Height Field Size & Grid Spacing

Unity requires the heightmap resolution to be a power of 2 + 1. In order to achieve the best results given this constraint, you’ll need to understand how the height field node parms marked in red boxes above work together and should be used.

For Sampling use Corner type to match Unity’s terrain generation, as well as the power of 2 size requirement. Houdini uses Center sampling by default but this results in floating point calculation errors when converting to Unity terrain. Therefore Corner sampling is recommended.

For Grid Spacing, use 1 or use a power of 2 (e.g. 2, 4, 8, etc.) to control height map resolution.

For Size use power of 2 starting at 64 (e.g. 64, 128, 256, 512, 1024, 2048, 4096, etc.).

For the resulting Unity terrain

  • terrain width and length are calculated by adding the grid spacing to the height field size (i.e. terrain width = height field size + grid spacing)

  • terrain height is the range of height values (i.e. terrain height = max height - min height)

  • heightmap resolution is calculated by dividing the height field size by the grid spacing and adding 1 (i.e. heightmap resolution size = height field size / grid spacing + 1)

Example settings using Corner sampling:

Houdini Height Field Size

Houdini Grid Spacing

width: 8% Unity Terrain Size

Unity Heightmap Resolution

512×512

1

513×513

513×513

512×512

2

514×514

257×257

512×512

4

516×516

129×129

1024×1024

1

1025×1025

1025×1025

1024×1024

2

1026×1026

513×513

1024×1024

4

1028×1028

257×257

2048×2048

2

2050×2050

1025×1025

4096×4096

2

4098×4098

2049×2049

In all cases, Unity’s heightmap resolution must be power of 2 + 1. These would be:

  • 8193 x 8193

  • 4097 x 4097

  • 2049 x 2049

  • 1025 x 1025

  • 513 x 513

  • 257 x 257

  • 129 x 129

  • 65 x 65

When using other heightmap resolution sizes, Unity will automatically change to the next lowest power of 2 size, which means the height values will not be properly applied. Therefore stick to power of 2 values for the height field size and grid spacing.

The plugin ships with an example HDA (Assets/Plugins/HoudiniEngineUnity/HDAs/TerrainGenerator.hda) which shows the various recommended configurations of sizes and grid spacing values.

For using Unity terrain as input to generate Houdini height fields, it is just a matter of reversing the above calculation to figure out the height field size and grid spacing. Note that both the terrain width and length must be the same value (i.e. square sized terrain). Use the following steps:

1. decide on the grid spacing, either 1 for simplicity, or a power of 2 (e.g. grid spacing = 2) 2. for terrain width and length, choose a power of 2 size starting at 64, and add the grid spacing (e.g. terrain width, length = 512 + 2 = 514) 3. for heightmap resolution, it should now be the terrain width - grid spacing divided by the grid spacing plus 1 (e.g. heightmap resolution = (514 - 2) / 2 + 1 = 257)

The simplest method is to first choose a power of 2 value for terrain width and height, then add 1 for both the final terrain width and height, as well as the height map resolution (e.g. 512 + 1 = 513).

Height Field Layers

A Houdini height field volume consists of height and mask layers, and potentially could have a number of other layers. A Unity terrain consists of a Terrain component, and a TerrainData with height values, any number of TerrainLayers (or SplatPrototypes for Unity versions prior to 2018.3), and corresponding number of splatmaps. A TerrainLayer specifies the material to paint on the terrain. The splatmap specifies the masking or weights of each pixel from the TerrainLayer material at each point on the terrain.

The following describes how Houdini’s height field layers are treated by the plugin:

The height layer will be used for the terrain’s heightmap values. The range of the heightmap values form the height range for the terrain. The unity_hf_terraindata_file attribute can be specified on this layer (and only on this layer) to reference an existing TerrainData asset file to use (Houdini Heightfields to Unity Terrain). There will NOT be a corresponding TerrainLayer created for this layer.

The mask layer is NOT used.

For each of the other layers, a corresponding TerrainLayer and a splatmap will be created or loaded, and set on the TerrainData. Therefore a height field volume with, for example, 4 layers (height, mask, ground, cliffs), will have 2 TerrainLayers and 2 splatmaps; a TerrainLayer and splatmap for the ground and the other 2 for the cliffs. The height field layer’s name will be used for the TerrainLayer’s name. An existing TerrainLayer asset can be specified via the unity_hf_terrainlayer_file attribute. On Recook, existing TerrainLayers will be reused if their name matches with the height field layers' name. If not specified or not found, the TerrainLayer will be created. In order to maintain the reference in the Unity project, the TerrainLayer will be saved to an asset file (see Generation for the saved file path).

The splatmaps are generated from the height field layer’s height values. The values should be between 0 and 1 inclusive (i.e. normalized). If there are values outside this range, the plugin will normalize them back to within this range, using the minimum and maximum values (each value is subtracted by the minimum and divided by the range). Also, it is recommended that the splatmap values of each layer at any coordinate sum up to a total of 1. For example, if there are 2 splatmap layers, then for the splat values at (0,0), if the 1st layer has value of 0.7, then 2nd layer should have a value of 0.3. Note that ultimately these values are used by the material and shader used by the Unity terrain, so the recommended range is for the default Unity terrain material.

To create values between 0 and 1, a HeightField Remap SOP node could be employed. The following screenshot shows an example of this for height field layer named base:

TerrainLayers UI

The plugin provides a Strength control for each splatmap layer, exposed on the HDA’s Inspector UI. The Strength value is a multiplier applied to each splatmap value, with a default value of 1. It allows to control the splatmap values generated from Houdini with a single parameter, and is useful for troubleshooting and when additional TerrainLayers have been manually added by the user.

TerrainLayer Properties via Attributes

Each of the TerrainLayer properties can be individually set using primitive attributes. The values specified by the attributes will override the existing TerrainLayer properties. See (Houdini Heightfields to Unity Terrain).

TerrainLayers Example with Tiles

The following HDA contains a height field network that outputs 2 merged terrain tiles, with 3 height field layers (height, mask, and base). The base layer is a copy of the height layer, with values remapped to 0 and 1. An string attribute is created on the base layer to specify the TerrainLayer file to set in Unity for the base layer.

The following image shows the final merge node’s info. There are 6 layers in total (3 layers (height, mask, base) for each terrain tile):

Finally, the HDA is loaded in Unity and generates 2 terrains, each having a single TerrainLayer (from the base height field layer):

Generation

During generation of a Unity terrain, the plugin does several things depending on the asset settings, existing terrain state, and cooking type:

TerrainData

The TerrainData file is by default saved into the plugin asset cache directory, at the following path

Assets/HoudiniEngineAssetCache/Working/{asset name}/{geo name}/Terrain/Tile{index}/TerranData.asset

Existing TerrainData asset files are copied into the above directory, if specified via attribute.

But an explicit export path could be set via a string attribute (unity_hf_terraindata_export_file) on the height field (e.g. unity_hf_terraindata_export_file=Assets/Terrain/myterraindata.asset). Note that the path should end with a file name with extension .asset.

TerrainLayers

TerrainLayers that are modified via attributes or created newly are saved in the plugin asset cache directory, at the following path format

Assets/HoudiniEngineAssetCache/Working/{asset name}/{geo name}/Terrain/Tile{index}/{layer name}.terrainlayer

Note that if an existing TerrainLayer asset file is specified via attribute, it is used as is, unless other custom attributes are specified to override its properties. In the latter case, a copy of the file is made, overrides are then applied, and the file is stored at the above location. This allows to leave the original TerrainLayer as is.

On Recook, the TerrainData, TerrainLayers, and splatmaps are reused (and settings untouched) unless overridden by the generated height field.

On Rebuild, and Reset Parameters, the TerrainData, TerrainLayers, and splatmaps are created newly (or asset files loaded from original references if specified via attributes).

Default Settings

When a new Terrain and TerrainData are created, the following settings are applied as defaults:

  • Allow Auto Connect to True

  • Draw Instanced to True

  • Detail Resolution to 1024

  • Resolution Per Patch to 32

  • Terrain height to 600 if range in height field is 0 (i.e. flat height field)

Materials

The material used for generated Terrains can be specified through the Plugin Settings window, in the GEOMETRY section:

For Unity HDRP projects, it is recommended to set this to the DefaultHDTerrainMaterial that is shipped with the HDRP package. For other render pipelines, use the default Unity terrain material shipped for that pipeline.

Similarly, the default splat texture can be changed in the Plugin Settings to point to another texture file.

Attributes

Heightfield Layers

The following table lists special attributes which can be set on heightfield layers in order to set the corresponding Terrain Layer properties on the generated Unity Terrain. Note that height and mask layers are ignored when creating Terrain Layers, so these attributes must be set on other heightfield layers.

Attribute Name

Owner

Type

Description

unity_hf_terrainlayer_file

prim

string

Path in Unity project of a TerrainLayer asset to set as the Terrain Layer. Relative to project Assets folder

example: Assets/Terrain/base.terrainlayer

unity_hf_texture_diffuse

prim

string

Path in Unity project of a Texture asset to set as the terrain layer’s diffuse texture. Relative to project Assets folder

example: Assets/Texture/sand.png

unity_hf_texture_mask

prim

string

Path in Unity project of a Texture asset to set as the terrain layer’s mask texture. Relative to project Assets folder

unity_hf_texture_normal

prim

string

Path in Unity project of a Texture asset to set as the terrain layer’s normal texture. Relative to project Assets folder

unity_hf_normal_scale

prim

float

Terrain layer’s normal scale (float of size 1)

unity_hf_metallic

prim

float

Terrain layer’s shader’s metallic value (float of size 1, with value between 0 and 1)

unity_hf_smoothness

prim

float

Terrain layer’s shader’s smoothness value (float of size 1, with value between 0 and 1)

unity_hf_specular

prim

float array

Terrain layer’s shader’s specular color (float of size 4, with values between 0 and 1)

unity_hf_tile_offset

prim

float array

Terrain layer’s texture’s tile offset (float of size 2)

unity_hf_tile_size

prim

float array

Terrain layer’s texture’s tile size (float of size 2)

Terrain Data

The following table lists special attributes which can be set on the height heightfield layer to specify an existing TerrainData asset file to used. A copy of the TerrainData asset file will be created on generation in Unity.

Attribute Name

Owner

Type

Description

unity_hf_terraindata_file

prim

string

Path in Unity project of a TerrainData asset to set as the Terrain Data. Relative to project Assets folder

example: Assets/Terrain/terlayer.asset

unity_hf_terraindata_export_file

prim

string

Path to write the generated or copied TerrainData asset to

unity_hf_tile

point

int

Specifies the terrain tile of a scatter point. Useful for tree instancing with the tile split node

Terrain (height fields)