Adding ray tracing toggle to behavior context so it can be used with scripting.

Signed-off-by: windbagjacket <nibor@ntlworld.com>
This commit is contained in:
windbagjacket
2022-01-14 17:07:13 +00:00
parent 5c52df7211
commit 7474c5480e
10 changed files with 75 additions and 1 deletions
@@ -176,6 +176,7 @@ namespace AZ
void SetExcludeFromReflectionCubeMaps(const MeshHandle& meshHandle, bool excludeFromReflectionCubeMaps) override;
void SetRayTracingEnabled(const MeshHandle& meshHandle, bool rayTracingEnabled) override;
bool GetRayTracingEnabled(const MeshHandle& meshHandle) const override;
void SetVisible(const MeshHandle& meshHandle, bool visible) override;
void SetUseForwardPassIblSpecular(const MeshHandle& meshHandle, bool useForwardPassIblSpecular) override;
@@ -105,6 +105,8 @@ namespace AZ
virtual void SetExcludeFromReflectionCubeMaps(const MeshHandle& meshHandle, bool excludeFromReflectionCubeMaps) = 0;
//! Sets the option to exclude this mesh from raytracing
virtual void SetRayTracingEnabled(const MeshHandle& meshHandle, bool rayTracingEnabled) = 0;
//! Gets whether this mesh is excluded from raytracing
virtual bool GetRayTracingEnabled(const MeshHandle& meshHandle) const = 0;
//! Sets the mesh as visible or hidden. When the mesh is hidden it will not be rendered by the feature processor.
virtual void SetVisible(const MeshHandle& meshHandle, bool visible) = 0;
//! Sets the mesh to render IBL specular in the forward pass.
@@ -38,6 +38,7 @@ namespace UnitTest
MOCK_METHOD2(AcquireMesh, MeshHandle (const AZ::Render::MeshHandleDescriptor&, const AZ::Render::MaterialAssignmentMap&));
MOCK_METHOD2(AcquireMesh, MeshHandle (const AZ::Render::MeshHandleDescriptor&, const AZ::Data::Instance<AZ::RPI::Material>&));
MOCK_METHOD2(SetRayTracingEnabled, void (const MeshHandle&, bool));
MOCK_CONST_METHOD1(GetRayTracingEnabled, bool(const MeshHandle&));
MOCK_METHOD2(SetVisible, void (const MeshHandle&, bool));
MOCK_METHOD2(SetUseForwardPassIblSpecular, void (const MeshHandle&, bool));
};
@@ -435,6 +435,19 @@ namespace AZ
}
}
bool MeshFeatureProcessor::GetRayTracingEnabled(const MeshHandle& meshHandle) const
{
if (meshHandle.IsValid())
{
return meshHandle->m_descriptor.m_isRayTracingEnabled;
}
else
{
AZ_Assert(false, "Invalid mesh handle");
return false;
}
}
void MeshFeatureProcessor::SetVisible(const MeshHandle& meshHandle, bool visible)
{
if (meshHandle.IsValid())
@@ -51,6 +51,9 @@ namespace AZ
virtual void SetVisibility(bool visible) = 0;
virtual bool GetVisibility() const = 0;
virtual void SetRayTracingEnabled(bool enabled) = 0;
virtual bool GetRayTracingEnabled() const = 0;
virtual AZ::Aabb GetWorldBounds() = 0;
virtual AZ::Aabb GetLocalBounds() = 0;
@@ -182,6 +182,8 @@ namespace AZ
->Event("GetMinimumScreenCoverage", &MeshComponentRequestBus::Events::GetMinimumScreenCoverage)
->Event("SetQualityDecayRate", &MeshComponentRequestBus::Events::SetQualityDecayRate)
->Event("GetQualityDecayRate", &MeshComponentRequestBus::Events::GetQualityDecayRate)
->Event("SetRayTracingEnabled", &MeshComponentRequestBus::Events::SetRayTracingEnabled)
->Event("GetRayTracingEnabled", &MeshComponentRequestBus::Events::GetRayTracingEnabled)
->VirtualProperty("ModelAssetId", "GetModelAssetId", "SetModelAssetId")
->VirtualProperty("ModelAssetPath", "GetModelAssetPath", "SetModelAssetPath")
->VirtualProperty("SortKey", "GetSortKey", "SetSortKey")
@@ -189,6 +191,7 @@ namespace AZ
->VirtualProperty("LodOverride", "GetLodOverride", "SetLodOverride")
->VirtualProperty("MinimumScreenCoverage", "GetMinimumScreenCoverage", "SetMinimumScreenCoverage")
->VirtualProperty("QualityDecayRate", "GetQualityDecayRate", "SetQualityDecayRate")
->VirtualProperty("RayTracingEnabled", "GetRayTracingEnabled", "SetRayTracingEnabled")
;
behaviorContext->EBus<MeshComponentNotificationBus>("MeshComponentNotificationBus")
@@ -561,6 +564,25 @@ namespace AZ
return m_isVisible;
}
void MeshComponentController::SetRayTracingEnabled(bool enabled)
{
if (m_meshHandle.IsValid() && m_meshFeatureProcessor)
{
m_meshFeatureProcessor->SetRayTracingEnabled(m_meshHandle, enabled);
m_configuration.m_isRayTracingEnabled = enabled;
}
}
bool MeshComponentController::GetRayTracingEnabled() const
{
if (m_meshHandle.IsValid() && m_meshFeatureProcessor)
{
return m_meshFeatureProcessor->GetRayTracingEnabled(m_meshHandle);
}
return false;
}
Aabb MeshComponentController::GetWorldBounds()
{
if (const AZ::Aabb localBounds = GetLocalBounds(); localBounds.IsValid())
@@ -116,6 +116,9 @@ namespace AZ
void SetVisibility(bool visible) override;
bool GetVisibility() const override;
void SetRayTracingEnabled(bool enabled) override;
bool GetRayTracingEnabled() const override;
// BoundsRequestBus and MeshComponentRequestBus overrides ...
AZ::Aabb GetWorldBounds() override;
AZ::Aabb GetLocalBounds() override;
@@ -376,7 +376,25 @@ namespace AZ::Render
bool AtomActorInstance::GetVisibility() const
{
return IsVisible();
return IsVisible();
}
void AtomActorInstance::SetRayTracingEnabled(bool enabled)
{
if (m_meshHandle->IsValid() && m_meshFeatureProcessor)
{
m_meshFeatureProcessor->SetRayTracingEnabled(*m_meshHandle, enabled);
}
}
bool AtomActorInstance::GetRayTracingEnabled() const
{
if (m_meshHandle->IsValid() && m_meshFeatureProcessor)
{
return m_meshFeatureProcessor->GetRayTracingEnabled(*m_meshHandle);
}
return false;
}
AZ::u32 AtomActorInstance::GetJointCount()
@@ -152,6 +152,8 @@ namespace AZ
float GetQualityDecayRate() const override;
void SetVisibility(bool visible) override;
bool GetVisibility() const override;
void SetRayTracingEnabled(bool enabled) override;
bool GetRayTracingEnabled() const override;
// GetWorldBounds/GetLocalBounds already overridden by BoundsRequestBus::Handler
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -444,6 +444,15 @@ namespace UnitTest
m_GetVisibilityOutput = visibility;
}
void SetRayTracingEnabled([[maybe_unused]] bool enabled) override
{
}
bool GetRayTracingEnabled() const override
{
return false;
}
AZ::Data::AssetId m_assetIdOutput;
void SetModelAssetId(AZ::Data::AssetId modelAssetId) override
{