ezEngine Release 26.9
Loading...
Searching...
No Matches
ezTerrainSystem Class Reference

#include <TerrainSystem.h>

Inheritance diagram for ezTerrainSystem:

Public Member Functions

 ezTerrainSystem (ezWorld *pWorld)
 
ezUInt32 CreateBrushData ()
 Allocates a brush slot and returns its index. Reuses freed slots before growing the array.
 
void RemoveBrushData (ezUInt32 &ref_uiIdx)
 Releases the brush slot and sets uiIdx to ezInvalidIndex. Marks all brushes dirty for rebake.
 
const ezTerrainData_BrushReadBrushData (ezUInt32 uiIdx) const
 
ezTerrainData_BrushModifyBrushData (ezUInt32 uiIdx)
 Returns a mutable reference and marks the brush set dirty so all patches rebake next frame.
 
ezUInt32 CreateHeightfieldTerrain (ezUInt32 uiCellsPerSide)
 Allocates GPU buffers for a new heightfield patch of the given resolution and returns a slot index.
 
void RemoveHeightfieldTerrain (ezUInt32 &ref_uiPatchIndex)
 Thread-safe: queues the patch for GPU buffer destruction at the start of the next frame.
 
ezTerrainData_HeightfieldModifyHeightfieldTerrain (ezUInt32 uiIdx)
 Returns a mutable reference and marks the patch dirty so it rebakes next frame.
 
ezGALBufferHandle GetHeightfieldHeightBuffer (ezUInt32 uiPatchIndex) const
 Returns the baked GPU height buffer handle (SRV in VS, UAV in heights CS).
 
ezGALBufferHandle GetHeightfieldNormalBuffer (ezUInt32 uiPatchIndex) const
 Returns the baked GPU normal buffer handle (SRV in VS, UAV in normals CS).
 
ezGALBufferHandle GetHeightfieldCellMaterialBuffer (ezUInt32 uiPatchIndex) const
 Returns the per-cell material index buffer (uint/cell) baked by Step3. Bound as SRV in VS.
 
ezGALBufferHandle GetHeightfieldMaterialVertexWeightBuffer (ezUInt32 uiPatchIndex) const
 Returns the per-vertex f16 weight buffer (uint/vertex) baked by Step3. Bound as SRV in VS.
 
ezUInt32 GetHeightfieldCellsPerSide (ezUInt32 uiPatchIndex) const
 Returns the number of quads per side (= resolution enum value) for the given patch.
 
ezUInt64 GetHeightfieldBrushOverlapHash (ezUInt32 uiPatchIndex) const
 
ezResult ReadbackHeightfieldData (ezUInt32 uiPatchIndex, ezDynamicArray< float > &out_heights, ezDynamicArray< ezUInt8 > &out_dominantMat, ezTime timeout=ezTime::MakeFromSeconds(5.0))
 
ezUInt32 CreateVoxelTerrain (ezUInt32 uiResolution, float fVoxelSize)
 Allocates GPU buffers and readback helpers for a new voxel terrain piece. Returns a slot index.
 
void RemoveVoxelTerrain (ezUInt32 uiIndex)
 Thread-safe: queues the volume for GPU buffer destruction at the start of the next frame.
 
ezTerrainData_VoxelModifyVoxelTerrain (ezUInt32 uiIndex)
 Returns a mutable reference and marks the volume dirty so it rebakes next frame.
 
ezGALBufferHandle GetVoxelVolumeGpuMeshVertexBuffer (ezUInt32 uiIndex) const
 Returns the GPU vertex buffer (StructuredBuffer SRV) for the given voxel volume.
 
ezGALBufferHandle GetVoxelVolumeGpuMeshIndexBuffer (ezUInt32 uiIndex) const
 Returns the GPU index buffer (StructuredBuffer SRV) for the given voxel volume.
 
ezGALBufferHandle GetVoxelVolumeGpuMeshDrawArgsBuffer (ezUInt32 uiIndex) const
 Returns the indirect draw arguments buffer for the given voxel volume.
 
ezUInt64 GetVoxelBrushOverlapHash (ezUInt32 uiIndex) const
 
ezResult ReadbackVoxelData (ezUInt32 uiIndex, ezTempArray< VoxelGpuVertex > &out_verts, ezDynamicArray< ezUInt32 > &out_indices, ezUInt32 &out_uiVertexCount, ezUInt32 &out_uiPrimitiveCount, ezTime timeout=ezTime::MakeFromSeconds(5.0))
 
- Public Member Functions inherited from ezWorldModule
ezWorldGetWorld ()
 Returns the corresponding world to this module.
 
const ezWorldGetWorld () const
 Returns the corresponding world to this module.
 
ezUInt32 GetWorldIndex () const
 Same as GetWorld()->GetIndex(). Needed to break circular include dependencies.
 
- Public Member Functions inherited from ezReflectedClass
virtual const ezRTTIGetDynamicRTTI () const
 
bool IsInstanceOf (const ezRTTI *pType) const
 Returns whether the type of this instance is of the given type or derived from it.
 
template<typename T >
EZ_ALWAYS_INLINE bool IsInstanceOf () const
 Returns whether the type of this instance is of the given type or derived from it.
 

Private Member Functions

virtual void Initialize () override
 This method is called after the constructor. A derived type can override this method to do initialization work. Typically this is the method where updates function are registered.
 
virtual void Deinitialize () override
 This method is called before the destructor. A derived type can override this method to do deinitialization work.
 

Additional Inherited Members

- Static Public Member Functions inherited from ezNoBase
static const ezRTTIGetStaticRTTI ()
 
- Protected Types inherited from ezWorldModule
using UpdateFunction = ezDelegate< void(const UpdateContext &)>
 Update function delegate.
 
- Protected Member Functions inherited from ezWorldModule
 ezWorldModule (ezWorld *pWorld)
 
void RegisterUpdateFunction (const UpdateFunctionDesc &desc)
 Registers the given update function at the world.
 
void DeregisterUpdateFunction (const UpdateFunctionDesc &desc)
 De-registers the given update function from the world. Note that only the m_Function and the m_Phase of the description have to be valid for de-registration.
 
ezAllocatorGetAllocator ()
 Returns the allocator used by the world.
 
ezInternal::WorldLargeBlockAllocatorGetBlockAllocator ()
 Returns the block allocator used by the world.
 
bool GetWorldSimulationEnabled () const
 Returns whether the world simulation is enabled.
 
virtual void OnSimulationStarted ()
 This method is called at the start of the next world update when the world is simulated. This method will be called after the initialization method.
 
virtual void WorldClear ()
 Called by ezWorld::Clear(). Can be used to clear cached data when a world is completely cleared of objects (but not deleted).
 
- Protected Attributes inherited from ezWorldModule
ezWorldm_pWorld
 

Detailed Description

Manages GPU resources and compute shader dispatch for all terrain patches in a world.

Terrain components register here on activation and receive a slot index. On each BeginRender event the system re-bakes all dirty patches before the main pipeline renders. Baking is also triggered when the set of overlapping brushes changes for a given patch.

Member Function Documentation

◆ Deinitialize()

void ezTerrainSystem::Deinitialize ( )
overrideprivatevirtual

This method is called before the destructor. A derived type can override this method to do deinitialization work.

Reimplemented from ezWorldModule.

◆ GetHeightfieldBrushOverlapHash()

ezUInt64 ezTerrainSystem::GetHeightfieldBrushOverlapHash ( ezUInt32  uiPatchIndex) const

Returns a hash over all brushes whose footprint overlaps this patch's XY extent. Changes when the set of relevant brushes changes. Returns 0 for invalid indices.

◆ GetVoxelBrushOverlapHash()

ezUInt64 ezTerrainSystem::GetVoxelBrushOverlapHash ( ezUInt32  uiIndex) const

Returns the brush overlap hash stored on the voxel volume (updated each bake). Returns 0 for invalid indices. Used by export modifiers to detect stale baked files.

◆ Initialize()

void ezTerrainSystem::Initialize ( )
overrideprivatevirtual

This method is called after the constructor. A derived type can override this method to do initialization work. Typically this is the method where updates function are registered.

Reimplemented from ezWorldModule.

◆ ReadbackHeightfieldData()

ezResult ezTerrainSystem::ReadbackHeightfieldData ( ezUInt32  uiPatchIndex,
ezDynamicArray< float > &  out_heights,
ezDynamicArray< ezUInt8 > &  out_dominantMat,
ezTime  timeout = ezTime::MakeFromSeconds(5.0) 
)

Bakes the given heightfield patch and blocks while reading the result back to the CPU.

out_heights receives the full stored height grid (CellsPerSide+9)² floats — 4 border rings on each side beyond the rendered vertices. out_dominantMat receives the dominant material index per stored cell. Must be called from the main/render thread with GPU device access.

◆ ReadbackVoxelData()

ezResult ezTerrainSystem::ReadbackVoxelData ( ezUInt32  uiIndex,
ezTempArray< VoxelGpuVertex > &  out_verts,
ezDynamicArray< ezUInt32 > &  out_indices,
ezUInt32 &  out_uiVertexCount,
ezUInt32 &  out_uiPrimitiveCount,
ezTime  timeout = ezTime::MakeFromSeconds(5.0) 
)

Bakes the given voxel terrain piece and blocks while reading the mesh back to the CPU.

out_verts / out_indices receive the compacted surface-nets mesh; out_vertexCount and out_primitiveCount give the valid element counts (out_indices holds out_primitiveCount*3 indices). Must be called from the main/render thread with GPU device access.


The documentation for this class was generated from the following files: