Instanced Terrain Foliage
A component designed to dynamically load and manage instances of trees and detail foliage from a Unity Terrain.
Overview
The InstancedTerrainFoliage
component loads instances of trees and details from the terrain data and updates them dynamically based on their distance from a camera. This component allows for fine-tuned control over how foliage is loaded, rendered, and culled, ensuring optimal performance.
Key Features
Dynamic Loading: Load and unload instances of trees and details based on their distance from the camera.
Flexible Culling: Choose between prototype-based or custom render distances for culling instances.
Terrain Integration: Seamlessly integrates with Unity's Terrain component and TerrainData asset.
Event Handling: Handle changes to the terrain data with events.
Usage Example
Here's an example of how to use the InstancedTerrainFoliage
component in a script:
Detailed Documentation
Enums
InstancingTerrainDirtyFlag
Flags that specify which parts of the terrain have changed and which instances need to be updated:
None: No changes have occurred.
DetailsConfig: The details configuration has changed.
DetailsInstances: The detail instances have changed.
Details: Both details configuration and instances have changed.
TreesConfig: The trees configuration has changed.
TreesInstances: The tree instances have changed.
Trees: Both trees configuration and instances have changed.
Height: The terrain height has changed.
All: All parts of the terrain have changed.
InstancedTerrainFoliageLoadMode
Determines how instances of terrain foliage are loaded:
AlwaysLoaded: Instances are always loaded.
OnDemand: Instances are loaded based on the instance prototype's streaming range.
OnDemandDistance: Instances are loaded based on a custom streaming range.
InstancedTerrainFoliageCullMode
Determines how instances of terrain foliage are culled:
FromPrototype: Instances are culled based on the instance prototype's render distance.
Override: Instances are culled based on the distance specified by the component.
Properties
Terrain
: The terrain component that contains the foliage instances.TerrainData
: The terrain data asset that contains the foliage instances.DetailsLoadMode
: Determines how detail instances are loaded from the terrain data.DetailsLoadDistance
: The custom render distance for detail instances.DetailsCullMode
: Determines how detail instances choose their render distance.DetailsOverrideRenderDistance
: The custom render distance for detail instances.TreesLoadMode
: Determines how tree instances are loaded from the terrain data.TreesLoadDistance
: The custom render distance for tree instances.TreesCullMode
: Determines how tree instances choose their render distance.TreesOverrideRenderDistance
: The custom render distance for tree instances.TreePatchesPerEdge
: The number of patches per edge of the terrain for tree instances.
Methods
SetInstancesDirty(InstancingTerrainDirtyFlag flags = InstancingTerrainDirtyFlag.All)
: Marks the terrain instances as dirty.ForceLoadInstances()
: Forces all instances to be loaded, regardless of their distance from the camera.
Events
TerrainInstancesChanged
: Occurs when the terrain foliage has changed.
Last updated