On this page |
There are 2 methods of scattering instances using the HeightField Scatter node within an HDA:
Prefab Instances ¶
When a HeightField Scatter node is used in a height field network, the output is a point cloud. The unity_instance
attribute can be added to these points with paths to existing Unity prefabs in the project. The plugin creates prefab instances for each point, as well as the terrain associated with the height field if Keep Incoming Terrain is enabled on the HeightField Scatter node. Note that this works well for small number of points, but can be inefficient for a larger set.
Tree Instances ¶
A more efficient method of scattering is to directly feed in the point cloud into the generated Unity terrain via TreeInstances and TreePrototypes. The TreePrototypes allows to set a list of prefabs, while the TreeInstances allows to set the list of points with instance data per point. Using this method, hundreds of thousands of trees can be scattered efficiently.
TreeProtoypes must be defined with the unity_hf_tree_prototype + index
string attribute on the height layer. These should be set to Primitive owner. The value should be the relative path in the Assets folder (e.g. Assets/Trees/tree1.prefab). The index
value starts at 0, and increments for each additional prototype. The index corresponds to the index referenced in the TreeInstance definition below. As an example, to define 3 TreePrototypes, the following 3 attributes are defined:
-
unity_hf_tree_prototype0
- Assets/Tree/large_tree.prefab -
unity_hf_tree_prototype1
- Assets/Tree/regular_tree.prefab -
unity_hf_tree_prototype2
- Assets/Tree/small_tree.prefab
Detail Layers ¶
For smaller sized environment details such as grass, shrubs, etc., height field layers can be specified to be converted to Unity terrain’s detail layer for efficient drawing.
A Unity terrain detail layer contains a map of integer values that specify the number of instances for the area covered by each value in the height field. These values must be integers between 0 and 16, so the float values from the height field will be simply converted to integers as they are. For a point in the height field, a value of 0 denotes no instances, while values between 1 and 16 denote the number of desired instances for the area covered by the height point. The area covered by each height point is determined by dividing the terrain size by the Detail Resolution, which is inferred from the size of the height field layer. For example, a terrain of size 1024×1024 with the Detail Resolution of 256 means that for each height point in a detail layer, it covers a 4×4 area.
Note that the Detail Resolution cannot be set via attribute. It is inferred from the detail layer’s size, which must be a square size between 0 and 4048, as required by Unity. Therefore all specified detail layers must be of the same size.
In order to use detail layers, the height field network requires setting detail properties, as described below.
Detail Layer Properties:
-
The height field layer to be converted to detail layer must be marked as detail type. This is done by setting a Primitive String attribute named
unity_hf_layer_type
on the layer with the value detail. -
On the same heigthfield layer, a DetailPrototype must also be specified via the following attributes:
-
To use a prefab, set a Primitive String attribute named
unity_hf_detail_prototype_prefab
on the prefab or mesh’s layer to instantiate. -
Or to use a texture, set a Primitive String attribute named
unity_hf_detail_prototype_texture
on the layer with the path to the texture.
-
Attributes ¶
Tree Instances ¶
Tree Instances are defined using the following Point attributes after the HeightField Scatter node in the network. Automatically setting Terrain tree instances is only available for Unity 2019.1 or newer.
Attribute |
Description |
---|---|
|
Set the index (Integer) of the TreePrototype to use (starting at 0). The index refers to the TreePrototype definition described above |
|
Set the height scale (Float) of the TreePrototype |
|
Set the width scale (Float) of the TreePrototype |
|
Set the lightmap color (4 Float) of the TreePrototype |
|
Set the color (4 Float) of the TreePrototype |
|
Set the rotation of the TreePrototype |
Terrain Detail Layers ¶
Attribute |
Description |
---|---|
|
Converts the height field layer to a detai llayer. Set a Primitive String on the layer with a value detail. |
unity_hf_detail_prototype_prefab
unity_hf_detail_prototype_texture
|
Set a Primitive Float attribute with a bend factor value. |
|
Set a Primitive Color (4 float) attribute with dry color value. |
|
Set a Primitive Color (4 float) attribute with healthy color value. |
|
Set a Primitive Float attribute with maximum height value. |
|
Set a Primitive Float attribute with maximum width value. |
|
Set a Primitive Float attribute with minimum height value. |
|
Set a Primitive Float attribute with minimum width value. |
|
Set a Primitive Float attribute with a noise spread value. |
|
Set a Primitive Integer attribute with a DetailRenderMode value of 0 for GrassBillboard, 1 for VertexLit, and 2 for Grass (Default). |
Detail Layers - Global Detail Properties ¶
-
On the height layer, the following attributes can be specified to set the detail values for the generated TerrainData:
Attribute |
Description |
---|---|
|
Set a Detail Integer attribute with value from 0 to 250 for Detail Distance |
|
Set a Detail Float attribute with value from 0 to 1 for Detail Density |
|
Set a Detail Integer attribute with value from 8 to 128 for Density Resolution Per Patch |