[LYN-3265] Vegetation failed to display in the launcher because we hadn't deleted enough legacy code out of the system yet.
The actual bug was the "if (!m_engine)" early-out in CreateInstanceNode that needed to be removed, but all the rest of this legacy-based merged mesh code was ripe for removal as well.
This commit is contained in:
@@ -15,8 +15,6 @@
|
||||
#include <AzCore/Component/ComponentBus.h>
|
||||
#include <Vegetation/Descriptor.h>
|
||||
|
||||
struct IRenderNode;
|
||||
|
||||
namespace Vegetation
|
||||
{
|
||||
struct InstanceData;
|
||||
@@ -48,12 +46,6 @@ namespace Vegetation
|
||||
virtual void DestroyAllInstances() = 0;
|
||||
|
||||
virtual void Cleanup() = 0;
|
||||
|
||||
// Notify the instance system whenever a merged mesh instance is created / destroyed.
|
||||
// This is necessary because we only want to refresh a full merged mesh once per set of
|
||||
// changes, not once per instance change.
|
||||
virtual void RegisterMergedMeshInstance(InstancePtr instance, IRenderNode* mergedMeshNode) = 0;
|
||||
virtual void ReleaseMergedMeshInstance(InstancePtr instance) = 0;
|
||||
};
|
||||
|
||||
using InstanceSystemRequestBus = AZ::EBus<InstanceSystemRequests>;
|
||||
|
||||
@@ -21,10 +21,7 @@
|
||||
|
||||
#include <LmbrCentral/Rendering/MaterialAsset.h>
|
||||
#include <LmbrCentral/Rendering/MeshAsset.h>
|
||||
#include <MathConversion.h>
|
||||
#include <I3DEngine.h>
|
||||
#include <ISystem.h>
|
||||
#include <Tarray.h>
|
||||
|
||||
#include <Vegetation/Ebuses/AreaInfoBus.h>
|
||||
#include <Vegetation/Ebuses/AreaSystemRequestBus.h>
|
||||
#include <Vegetation/Ebuses/DebugNotificationBus.h>
|
||||
@@ -41,33 +38,6 @@ namespace Vegetation
|
||||
static const int s_minTaskBatchSize = 1;
|
||||
static const int s_maxTaskBatchSize = 2000; //prevents user from reserving excessive space as batches are processed faster than they can be filled
|
||||
}
|
||||
|
||||
void ApplyConfigurationToConsoleVars(ISystem* system, const InstanceSystemConfig& config)
|
||||
{
|
||||
if (!system)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto* console = system->GetIConsole();
|
||||
if (!console)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (console && console->GetCVar("e_MergedMeshesLodRatio"))
|
||||
{
|
||||
console->GetCVar("e_MergedMeshesLodRatio")->Set(config.m_mergedMeshesLodRatio);
|
||||
}
|
||||
if (console && console->GetCVar("e_MergedMeshesViewDistRatio"))
|
||||
{
|
||||
console->GetCVar("e_MergedMeshesViewDistRatio")->Set(config.m_mergedMeshesViewDistanceRatio);
|
||||
}
|
||||
if (console && console->GetCVar("e_MergedMeshesInstanceDist"))
|
||||
{
|
||||
console->GetCVar("e_MergedMeshesInstanceDist")->Set(config.m_mergedMeshesInstanceDistance);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -78,12 +48,9 @@ namespace Vegetation
|
||||
if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
||||
{
|
||||
serializeContext->Class<InstanceSystemConfig, AZ::ComponentConfig>()
|
||||
->Version(2)
|
||||
->Version(3)
|
||||
->Field("MaxInstanceProcessTimeMicroseconds", &InstanceSystemConfig::m_maxInstanceProcessTimeMicroseconds)
|
||||
->Field("MaxInstanceTaskBatchSize", &InstanceSystemConfig::m_maxInstanceTaskBatchSize)
|
||||
->Field("MergedMeshesLodRatio", &InstanceSystemConfig::m_mergedMeshesLodRatio)
|
||||
->Field("MergedMeshesViewDistanceRatio", &InstanceSystemConfig::m_mergedMeshesViewDistanceRatio)
|
||||
->Field("MergedMeshesInstanceDistance", &InstanceSystemConfig::m_mergedMeshesInstanceDistance)
|
||||
;
|
||||
|
||||
if (AZ::EditContext* editContext = serializeContext->GetEditContext())
|
||||
@@ -98,23 +65,6 @@ namespace Vegetation
|
||||
->DataElement(0, &InstanceSystemConfig::m_maxInstanceTaskBatchSize, "Max Instance Task Batch Size", "Maximum number of instance management tasks that can be batch processed together")
|
||||
->Attribute(AZ::Edit::Attributes::Min, InstanceSystemUtil::Constants::s_minTaskBatchSize)
|
||||
->Attribute(AZ::Edit::Attributes::Max, InstanceSystemUtil::Constants::s_maxTaskBatchSize)
|
||||
->ClassElement(AZ::Edit::ClassElements::Group, "Merged Meshes")
|
||||
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
|
||||
->DataElement(0, &InstanceSystemConfig::m_mergedMeshesLodRatio, "LOD Distance Ratio", "Controls the distance where the merged mesh vegetation use less detailed models")
|
||||
->Attribute(AZ::Edit::Attributes::Min, 0.0f)
|
||||
->Attribute(AZ::Edit::Attributes::Max, std::numeric_limits<float>::max())
|
||||
->Attribute(AZ::Edit::Attributes::SoftMin, 1.0f)
|
||||
->Attribute(AZ::Edit::Attributes::SoftMax, 1024.0f)
|
||||
->DataElement(0, &InstanceSystemConfig::m_mergedMeshesViewDistanceRatio, "View Distance Ratio", "Controls the maximum view distance for merged mesh vegetation instances")
|
||||
->Attribute(AZ::Edit::Attributes::Min, 0.0f)
|
||||
->Attribute(AZ::Edit::Attributes::Max, std::numeric_limits<float>::max())
|
||||
->Attribute(AZ::Edit::Attributes::SoftMin, 1.0f)
|
||||
->Attribute(AZ::Edit::Attributes::SoftMax, 1024.0f)
|
||||
->DataElement(0, &InstanceSystemConfig::m_mergedMeshesInstanceDistance, "Instance Animation Distance", "Relates to the distance at which animated vegetation will be processed")
|
||||
->Attribute(AZ::Edit::Attributes::Min, 0.0f)
|
||||
->Attribute(AZ::Edit::Attributes::Max, std::numeric_limits<float>::max())
|
||||
->Attribute(AZ::Edit::Attributes::SoftMin, 1.0f)
|
||||
->Attribute(AZ::Edit::Attributes::SoftMax, 1024.0f)
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -185,36 +135,20 @@ namespace Vegetation
|
||||
|
||||
void InstanceSystemComponent::Activate()
|
||||
{
|
||||
m_system = GetISystem();
|
||||
m_engine = m_system ? m_system->GetI3DEngine() : nullptr;
|
||||
Cleanup();
|
||||
AZ::TickBus::Handler::BusConnect();
|
||||
InstanceSystemRequestBus::Handler::BusConnect();
|
||||
InstanceSystemStatsRequestBus::Handler::BusConnect();
|
||||
InstanceStatObjEventBus::Handler::BusConnect();
|
||||
SystemConfigurationRequestBus::Handler::BusConnect();
|
||||
CrySystemEventBus::Handler::BusConnect();
|
||||
|
||||
InstanceSystemUtil::ApplyConfigurationToConsoleVars(m_system, m_configuration);
|
||||
}
|
||||
|
||||
void InstanceSystemComponent::Deactivate()
|
||||
{
|
||||
auto environment = m_system ? m_system->GetGlobalEnvironment() : nullptr;
|
||||
if (environment)
|
||||
{
|
||||
environment->SetDynamicMergedMeshGenerationEnabled(environment->IsEditor());
|
||||
}
|
||||
|
||||
InstanceStatObjEventBus::Handler::BusDisconnect();
|
||||
AZ::TickBus::Handler::BusDisconnect();
|
||||
InstanceSystemRequestBus::Handler::BusDisconnect();
|
||||
InstanceSystemStatsRequestBus::Handler::BusDisconnect();
|
||||
SystemConfigurationRequestBus::Handler::BusDisconnect();
|
||||
CrySystemEventBus::Handler::BusDisconnect();
|
||||
Cleanup();
|
||||
m_system = nullptr;
|
||||
m_engine = nullptr;
|
||||
}
|
||||
|
||||
bool InstanceSystemComponent::ReadInConfig(const AZ::ComponentConfig* baseConfig)
|
||||
@@ -466,15 +400,9 @@ namespace Vegetation
|
||||
GarbageCollectUniqueDescriptors();
|
||||
}
|
||||
|
||||
void InstanceSystemComponent::ReleaseData()
|
||||
{
|
||||
DestroyAllInstances();
|
||||
}
|
||||
|
||||
void InstanceSystemComponent::UpdateSystemConfig(const AZ::ComponentConfig* baseConfig)
|
||||
{
|
||||
ReadInConfig(baseConfig);
|
||||
InstanceSystemUtil::ApplyConfigurationToConsoleVars(m_system, m_configuration);
|
||||
}
|
||||
|
||||
void InstanceSystemComponent::GetSystemConfig(AZ::ComponentConfig* outBaseConfig) const
|
||||
@@ -482,29 +410,6 @@ namespace Vegetation
|
||||
WriteOutConfig(outBaseConfig);
|
||||
}
|
||||
|
||||
void InstanceSystemComponent::OnCrySystemInitialized(ISystem& system, [[maybe_unused]] const SSystemInitParams& systemInitParams)
|
||||
{
|
||||
auto environment = system.GetGlobalEnvironment();
|
||||
if (environment)
|
||||
{
|
||||
environment->SetDynamicMergedMeshGenerationEnabled(true);
|
||||
}
|
||||
m_system = &system;
|
||||
m_engine = m_system ? m_system->GetI3DEngine() : nullptr;
|
||||
}
|
||||
|
||||
void InstanceSystemComponent::OnCrySystemShutdown(ISystem& system)
|
||||
{
|
||||
auto environment = system.GetGlobalEnvironment();
|
||||
if (environment)
|
||||
{
|
||||
environment->SetDynamicMergedMeshGenerationEnabled(environment->IsEditor());
|
||||
}
|
||||
Cleanup();
|
||||
m_system = nullptr;
|
||||
m_engine = nullptr;
|
||||
}
|
||||
|
||||
InstanceId InstanceSystemComponent::CreateInstanceId()
|
||||
{
|
||||
AZStd::lock_guard<decltype(m_instanceIdMutex)> scopedLock(m_instanceIdMutex);
|
||||
@@ -549,12 +454,6 @@ namespace Vegetation
|
||||
{
|
||||
AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::Entity);
|
||||
|
||||
if (!m_engine)
|
||||
{
|
||||
AZ_Error("vegetation", m_engine, "Could not acquire I3DEngine!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsInstanceSkippable(instanceData))
|
||||
{
|
||||
return;
|
||||
@@ -592,63 +491,6 @@ namespace Vegetation
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceSystemComponent::RegisterMergedMeshInstance(InstancePtr instance, IRenderNode* mergedMeshNode)
|
||||
{
|
||||
if (instance && mergedMeshNode)
|
||||
{
|
||||
//merged mesh nodes should only refresh once for a batch of instances
|
||||
m_instanceNodeToMergedMeshNodeRegistrationMap[instance] = mergedMeshNode;
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceSystemComponent::ReleaseMergedMeshInstance(InstancePtr instance)
|
||||
{
|
||||
//stop tracking this node for registration
|
||||
m_instanceNodeToMergedMeshNodeRegistrationMap.erase(instance);
|
||||
}
|
||||
|
||||
void InstanceSystemComponent::CreateInstanceNodeBegin()
|
||||
{
|
||||
AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::Entity);
|
||||
|
||||
AZ_Error("vegetation", m_instanceNodeToMergedMeshNodeRegistrationMap.empty(), "m_instanceNodeToMergedMeshNodeRegistrationMap should be empty!");
|
||||
m_instanceNodeToMergedMeshNodeRegistrationMap.clear();
|
||||
}
|
||||
|
||||
void InstanceSystemComponent::CreateInstanceNodeEnd()
|
||||
{
|
||||
AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::Entity);
|
||||
|
||||
if (!m_engine)
|
||||
{
|
||||
AZ_Error("vegetation", m_engine, "Could not acquire I3DEngine!");
|
||||
m_instanceNodeToMergedMeshNodeRegistrationMap.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
//gather all unique mesh nodes to re-register
|
||||
m_mergedMeshNodeRegistrationSet.clear();
|
||||
m_mergedMeshNodeRegistrationSet.reserve(m_instanceNodeToMergedMeshNodeRegistrationMap.size());
|
||||
|
||||
for (auto nodePair : m_instanceNodeToMergedMeshNodeRegistrationMap)
|
||||
{
|
||||
InstancePtr instanceNode = nodePair.first;
|
||||
IRenderNode* mergedMeshNode = nodePair.second;
|
||||
if (instanceNode && mergedMeshNode)
|
||||
{
|
||||
m_mergedMeshNodeRegistrationSet.insert(mergedMeshNode);
|
||||
}
|
||||
}
|
||||
m_instanceNodeToMergedMeshNodeRegistrationMap.clear();
|
||||
|
||||
//re-register final merged mesh nodes
|
||||
for (auto mergedMeshNode : m_mergedMeshNodeRegistrationSet)
|
||||
{
|
||||
m_engine->UnRegisterEntityAsJob(mergedMeshNode);
|
||||
m_engine->RegisterEntity(mergedMeshNode);
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceSystemComponent::ReleaseInstanceNode(InstanceId instanceId)
|
||||
{
|
||||
AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::Entity);
|
||||
@@ -752,9 +594,7 @@ namespace Vegetation
|
||||
{
|
||||
AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::Entity);
|
||||
|
||||
CreateInstanceNodeBegin();
|
||||
ExecuteTasks();
|
||||
CreateInstanceNodeEnd();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,9 +28,6 @@
|
||||
#include <Vegetation/Ebuses/InstanceSystemRequestBus.h>
|
||||
#include <Vegetation/Ebuses/SystemConfigurationBus.h>
|
||||
|
||||
#include <StatObjBus.h>
|
||||
#include <CrySystemBus.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
class Aabb;
|
||||
@@ -39,10 +36,6 @@ namespace AZ
|
||||
class EntityId;
|
||||
}
|
||||
|
||||
struct IRenderNode;
|
||||
struct ISystem;
|
||||
struct I3DEngine;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace Vegetation
|
||||
@@ -63,11 +56,6 @@ namespace Vegetation
|
||||
|
||||
// maximum number of instance management tasks that can be batch processed together
|
||||
int m_maxInstanceTaskBatchSize = 100;
|
||||
|
||||
// merged mesh visual features
|
||||
float m_mergedMeshesViewDistanceRatio = 100.0f;
|
||||
float m_mergedMeshesLodRatio = 3.0f;
|
||||
float m_mergedMeshesInstanceDistance = 4.5f;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -78,9 +66,7 @@ namespace Vegetation
|
||||
, private InstanceSystemRequestBus::Handler
|
||||
, private InstanceSystemStatsRequestBus::Handler
|
||||
, private AZ::TickBus::Handler
|
||||
, private InstanceStatObjEventBus::Handler
|
||||
, private SystemConfigurationRequestBus::Handler
|
||||
, private CrySystemEventBus::Handler
|
||||
{
|
||||
friend class EditorInstanceSystemComponent;
|
||||
|
||||
@@ -116,9 +102,6 @@ namespace Vegetation
|
||||
void DestroyAllInstances() override;
|
||||
void Cleanup() override;
|
||||
|
||||
void RegisterMergedMeshInstance(InstancePtr instance, IRenderNode* mergedMeshNode) override;
|
||||
void ReleaseMergedMeshInstance(InstancePtr instance) override;
|
||||
|
||||
// InstanceSystemStatsRequestBus
|
||||
AZ::u32 GetInstanceCount() const override;
|
||||
AZ::u32 GetTotalTaskCount() const override;
|
||||
@@ -128,19 +111,11 @@ namespace Vegetation
|
||||
// AZ::TickBus
|
||||
void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
|
||||
|
||||
// InstanceStatObjEventBus
|
||||
void ReleaseData() override;
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// SystemConfigurationRequestBus
|
||||
void UpdateSystemConfig(const AZ::ComponentConfig* config) override;
|
||||
void GetSystemConfig(AZ::ComponentConfig* config) const override;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// CrySystemEvents
|
||||
void OnCrySystemInitialized(ISystem& system, const SSystemInitParams& systemInitParams) override;
|
||||
void OnCrySystemShutdown(ISystem& system) override;
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
// vegetation instance id management
|
||||
InstanceId CreateInstanceId();
|
||||
@@ -155,9 +130,6 @@ namespace Vegetation
|
||||
bool IsInstanceSkippable(const InstanceData& instanceData) const;
|
||||
void CreateInstanceNode(const InstanceData& instanceData);
|
||||
|
||||
void CreateInstanceNodeBegin();
|
||||
void CreateInstanceNodeEnd();
|
||||
|
||||
void ReleaseInstanceNode(InstanceId instanceId);
|
||||
|
||||
mutable AZStd::recursive_mutex m_instanceMapMutex;
|
||||
@@ -192,15 +164,6 @@ namespace Vegetation
|
||||
AZStd::map<DescriptorPtr, DescriptorDetails> m_uniqueDescriptors;
|
||||
AZStd::map<DescriptorPtr, DescriptorDetails> m_uniqueDescriptorsToDelete;
|
||||
|
||||
//refresh events can queue the creation and deletion of the same node in the same frame
|
||||
//this map is used to track which nodes remain after all tasks have executed for the frame
|
||||
//registration will only be done on the final set each frame
|
||||
AZStd::unordered_map<InstancePtr, IRenderNode*> m_instanceNodeToMergedMeshNodeRegistrationMap;
|
||||
AZStd::unordered_set<IRenderNode*> m_mergedMeshNodeRegistrationSet;
|
||||
|
||||
ISystem* m_system = nullptr;
|
||||
I3DEngine* m_engine = nullptr;
|
||||
|
||||
AZStd::atomic_int m_instanceCount{ 0 };
|
||||
AZStd::atomic_int m_createTaskCount{ 0 };
|
||||
AZStd::atomic_int m_destroyTaskCount{ 0 };
|
||||
|
||||
@@ -165,10 +165,6 @@ namespace UnitTest
|
||||
void DestroyAllInstances() override {}
|
||||
|
||||
void Cleanup() override {}
|
||||
|
||||
void RegisterMergedMeshInstance([[maybe_unused]] Vegetation::InstancePtr instance, [[maybe_unused]] IRenderNode* mergedMeshNode) override {}
|
||||
void ReleaseMergedMeshInstance([[maybe_unused]] Vegetation::InstancePtr instance) override {}
|
||||
|
||||
};
|
||||
|
||||
struct MockGradientRequestHandler
|
||||
|
||||
Reference in New Issue
Block a user