Houdini Engine for Unity
 All Files Pages
Terrain (Heightfields)

The plug-in will generate Unity terrain for asset's with heightfields, and generate alphamaps for the layers.

Conversely, the plug-in will upload Unity terrain as Houdini heightfields through input nodes (see Terrain Input).

Unity_Terrain.png

Heightfield Size & Grid Spacing

Unity_Heightfield_Settings.png

Now there is a relationship between Houdini heightfield's Grid Spacing and Size, and Unity's terrain size, and heightmap resolution. It is recommended to work with whole numbers for Houdini's heightfield Grid Spacing as it reduces floating point conversion errors. The recommended Grid Spacing values would be either 1 or 2.

The Grid Spacing value is the terrain size divided by the heightmap resolution. For example:

Unity Terrain Size Unity Heightmap Resolution Houdini Grid Spacing Houdini Heightfield Size Recommended
513x513 257 2 513x513 Yes
500x500 513 0.975 500x500 No
1026x1026 513 2 1026x1026 Yes
1000x1000 513 1.949 1000x1000 No
1025x1025 1025 1 1025x1025 Yes

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 closest compatible size, which means the height values will not be properly applied.

Important:

  • So if outputting Unity terrain from Houdini heightfields, divide the heightfield Size by the Grid Spacing to make sure the result is a power of 2 + 1.
  • Similarly, if using Unity terrain input to create Houdini heightfields, divide the terrain size by heightmap resolution to make sure the result is a whole number, and if planning to roundtrip back to Unity, then it is a power of 2 + 1.

Heightfield Layers

The height layer will be used as the heightmap values, while the other layers will be added as the terrain detail's alphamaps. Additionally, a base alphamap will also be added with the name height. The alphamap settings will be exposed in the asset's UI for setting the terrain texture and material properties.

Base alphamap (height layer): This is for the base terrain texture. The values will be the result of summing up other layer values and subtracting from 1.

Other alphamaps: These are the representation of other layers, and therefore the other terrain textures. Each layer will be converted to an alphamap, with values ranging from 0 to 1. The value conversion is done by taking the min and max values in this layer, and dividing by the range.

Since the default terrain material in Unity uses blending for the alphamap textures, it is recommend to use values between 0 and 1 for the alphamap layers. Therefore in Houdini, remap the non-height layers' values to be between 0 and 1 inclusive.

Unity_HF_Terrain_Layers.png

Note that for each Houdini heightfield layer in the left image above, there is a corresponding alphamap section on the asset UI in Unity (under TERRAIN, shown on right image above). The alphamap UI section contains the following fields:

  • Strength: Multiplier for the incoming layer values before applying to the alphamap. Essentially controls how much this alphamap's values affect the terrain texture.

The rest of the fields mirror the Unity Terrain SplatPrototype or Terrain Layer (Unity 2018.3+):

  • Diffuse Texture: Diffuse texture of the splat applied to the Terrain. A default 2x2 white splat texture is used initially (see note below).
  • MaskMap Texture: The mask map texture used by the terrain layer (Unity 2018.3+ only).
  • NormalMap: Normal map texture used by the terrain layer.
  • Normal Scale: A float value that scales the normal vector (Unity 2018.3+ only).
  • Metallic: Metallic factor used by the terrain layer.
  • Smoothness: Smoothness of the specular reflection.
  • Specular: Specular color (Unity 2018.3+ only).
  • Tile Size: UV Tiling size.
  • Tile Offset: UV tiling offset.

Note that these alphamap values are saved as part of the asset's preset, and therefore compatible with Duplicate Asset, and Save / Load Preset. They are also retained on Rebuild and Recook Asset, but will be reset on Reset Parameters.

These alphamap values can also be set in Houdini by adding primitive attributes to the Heightfield. See attribute section Houdini Heightfields to Unity Terrain.

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


Generation

The generated heightmap is stored in a TerrainData file in the plugin asset cache directory.

Note that any cook updates will regenerate the terrain heightfield, which means that any changes made to the heightfield in Unity (via the terrain editing tools) after it was previously cooked will be lost.


Terrain Input

By setting the GameObject containing the Terrain component in an asset's input field parameter, the plug-in will convert the terrain and its layers into Houdini heightfields.

Only square sized terrain are currently supported (i.e. both width and height must be same). If the terrain should be roundtripped (i.e. brought back into Unity), it is recommended to follow the power of 2 + 1 heightmap resolution size rule described in Heightfield Size & Grid Spacing.

Note that currently only the height values, and the alphamap layers' alpha values are uploaded. Other details such as the layer material, texture, and size are not uploaded as attributes. The base alphamap layer is not uploaded, but all others will be.

In Houdini, the uploaded alphamap layers will be named as unity_alphamap_layer_id where layer_id is the index of the layer.