Game.Rendering.VegetationRenderSystem
Assembly:
Namespace: Game.Rendering
Type: class
Base: GameSystemBase
Summary:
Manages terrain vegetation VisualEffect (VFX) for foliage rendering. Loads a VisualEffectAsset from Resources, creates a runtime VisualEffect GameObject when a camera viewer is active, and updates the effect's parameters each frame (terrain bounds, heightmap, splatmap, terrain offset/scale, and camera position/direction). Cleans up the created VisualEffect when the system stops.
Fields
-
private TerrainSystem m_TerrainSystem
Reference to the TerrainSystem used to query terrain bounds and the heightmap texture. -
private TerrainMaterialSystem m_TerrainMaterialSystem
Reference to the TerrainMaterialSystem used to access the terrain splatmap texture. -
private CameraUpdateSystem m_CameraUpdateSystem
Reference to the CameraUpdateSystem used to obtain active viewer, camera position and direction. -
private static VisualEffectAsset s_FoliageVFXAsset
Static cached VisualEffectAsset loaded from Resources at path "Vegetation/FoliageVFX". If present, used to instantiate the runtime VisualEffect. -
private VisualEffect m_FoliageVFX
Instance of the VisualEffect component created at runtime (on a new GameObject named "FoliageVFX") and assigned s_FoliageVFXAsset.
Properties
- This class does not expose public properties.
Constructors
public VegetationRenderSystem()
Default constructor. (Marked [Preserve] in source.) No custom initialization beyond default behavior.
Methods
-
protected virtual OnCreate() : System.Void
Initializes system references and resources. Retrieves or creates required systems via base.World.GetOrCreateSystemManaged for CameraUpdateSystem, TerrainSystem, and TerrainMaterialSystem. Loads the foliage VFX asset from Resources ("Vegetation/FoliageVFX") into s_FoliageVFXAsset. Disables the system initially (base.Enabled = false). Marked with [Preserve]. -
protected virtual OnStopRunning() : System.Void
Cleans up the instantiated VisualEffect when the system stops running. Calls CoreUtils.Destroy(m_FoliageVFX) to properly destroy the runtime GameObject/component. Marked with [Preserve]. -
protected virtual OnUpdate() : System.Void
Called each frame while the system is running. If CameraUpdateSystem.activeViewer is not null, ensures the dynamic VFX exists (CreateDynamicVFXIfNeeded) and updates its parameters (UpdateEffect). Marked with [Preserve]. -
private UpdateEffect() : System.Void
Pushes runtime data into the VisualEffect: - Sets terrain bounds center and size ("TerrainBounds_center", "TerrainBounds_size").
- Sets terrain heightmap and splatmap textures ("Terrain HeightMap", "Terrain SplatMap").
- Reads shader global vectors "colossal_TerrainScale" and "colossal_TerrainOffset" and packs components into "Terrain Offset Scale".
-
Updates camera vectors ("CameraPosition", "CameraDirection"). Requires m_FoliageVFX to be non-null.
-
private CreateDynamicVFXIfNeeded() : System.Void
Creates the runtime VisualEffect GameObject and component if the asset (s_FoliageVFXAsset) is loaded and no instance exists. Logs creation via COSystemBase.baseLog.DebugFormat("Creating FoliageVFX"), instantiates new GameObject("FoliageVFX") and adds a VisualEffect component, assigning the loaded asset. -
protected virtual OnDestroy() : System.Void
Calls base.OnDestroy(). No additional teardown logic is present in the source. Marked with [Preserve].
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Example: ensure systems are acquired and VFX asset is loaded as in the original implementation.
m_CameraUpdateSystem = base.World.GetOrCreateSystemManaged<CameraUpdateSystem>();
m_TerrainSystem = base.World.GetOrCreateSystemManaged<TerrainSystem>();
m_TerrainMaterialSystem = base.World.GetOrCreateSystemManaged<TerrainMaterialSystem>();
s_FoliageVFXAsset = Resources.Load<VisualEffectAsset>("Vegetation/FoliageVFX");
// Optionally enable the system when ready:
// base.Enabled = true;
}
Notes: - Depends on the Resources asset at "Vegetation/FoliageVFX" and on TerrainSystem, TerrainMaterialSystem, and CameraUpdateSystem being available in the world. - Uses UnityEngine.VFX.VisualEffect and Unity shader global vectors "colossal_TerrainScale" / "colossal_TerrainOffset". - The system disables itself by default in OnCreate; enable it (base.Enabled = true) when you want it to run.