diff --git a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Mesh/MeshFeatureProcessor.h b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Mesh/MeshFeatureProcessor.h index 23cd76ca20..92e9c1e88a 100644 --- a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Mesh/MeshFeatureProcessor.h +++ b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Mesh/MeshFeatureProcessor.h @@ -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; diff --git a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Mesh/MeshFeatureProcessorInterface.h b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Mesh/MeshFeatureProcessorInterface.h index 356b1936ca..f616c06e92 100644 --- a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Mesh/MeshFeatureProcessorInterface.h +++ b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Mesh/MeshFeatureProcessorInterface.h @@ -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. diff --git a/Gems/Atom/Feature/Common/Code/Mocks/MockMeshFeatureProcessor.h b/Gems/Atom/Feature/Common/Code/Mocks/MockMeshFeatureProcessor.h index 2c818d3c9b..af1e23aa19 100644 --- a/Gems/Atom/Feature/Common/Code/Mocks/MockMeshFeatureProcessor.h +++ b/Gems/Atom/Feature/Common/Code/Mocks/MockMeshFeatureProcessor.h @@ -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&)); 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)); }; diff --git a/Gems/Atom/Feature/Common/Code/Source/Mesh/MeshFeatureProcessor.cpp b/Gems/Atom/Feature/Common/Code/Source/Mesh/MeshFeatureProcessor.cpp index dfb2b3fe6b..6b9a3fc698 100644 --- a/Gems/Atom/Feature/Common/Code/Source/Mesh/MeshFeatureProcessor.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/Mesh/MeshFeatureProcessor.cpp @@ -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()) diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Include/AtomLyIntegration/CommonFeatures/Mesh/MeshComponentBus.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Include/AtomLyIntegration/CommonFeatures/Mesh/MeshComponentBus.h index cc9c78d356..989cbcffb2 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Include/AtomLyIntegration/CommonFeatures/Mesh/MeshComponentBus.h +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Include/AtomLyIntegration/CommonFeatures/Mesh/MeshComponentBus.h @@ -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; diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp index c89546264a..5c8d2d6116 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp @@ -79,6 +79,9 @@ namespace AZ ->DataElement(AZ::Edit::UIHandlers::CheckBox, &MeshComponentConfig::m_useForwardPassIblSpecular, "Use Forward Pass IBL Specular", "Renders IBL specular reflections in the forward pass, using only the most influential probe (based on the position of the entity) and the global IBL cubemap. Can reduce rendering costs, but only recommended for static objects that are affected by at most one reflection probe.") ->Attribute(AZ::Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly) + ->DataElement(AZ::Edit::UIHandlers::CheckBox, &MeshComponentConfig::m_isRayTracingEnabled, "Use ray tracing", + "Includes this mesh in ray tracing calculations.") + ->Attribute(AZ::Edit::Attributes::ChangeNotify, Edit::PropertyRefreshLevels::ValuesOnly) ->DataElement(AZ::Edit::UIHandlers::ComboBox, &MeshComponentConfig::m_lodType, "Lod Type", "Lod Method.") ->EnumAttribute(RPI::Cullable::LodType::Default, "Default") ->EnumAttribute(RPI::Cullable::LodType::ScreenCoverage, "Screen Coverage") diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.cpp index 517ba90f89..a68ad24adf 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.cpp @@ -76,6 +76,7 @@ namespace AZ ->Field("SortKey", &MeshComponentConfig::m_sortKey) ->Field("ExcludeFromReflectionCubeMaps", &MeshComponentConfig::m_excludeFromReflectionCubeMaps) ->Field("UseForwardPassIBLSpecular", &MeshComponentConfig::m_useForwardPassIblSpecular) + ->Field("IsRayTracingEnabled", &MeshComponentConfig::m_isRayTracingEnabled) ->Field("LodType", &MeshComponentConfig::m_lodType) ->Field("LodOverride", &MeshComponentConfig::m_lodOverride) ->Field("MinimumScreenCoverage", &MeshComponentConfig::m_minimumScreenCoverage) @@ -181,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") @@ -188,6 +191,7 @@ namespace AZ ->VirtualProperty("LodOverride", "GetLodOverride", "SetLodOverride") ->VirtualProperty("MinimumScreenCoverage", "GetMinimumScreenCoverage", "SetMinimumScreenCoverage") ->VirtualProperty("QualityDecayRate", "GetQualityDecayRate", "SetQualityDecayRate") + ->VirtualProperty("RayTracingEnabled", "GetRayTracingEnabled", "SetRayTracingEnabled") ; behaviorContext->EBus("MeshComponentNotificationBus") @@ -382,6 +386,7 @@ namespace AZ meshDescriptor.m_modelAsset = m_configuration.m_modelAsset; meshDescriptor.m_useForwardPassIblSpecular = m_configuration.m_useForwardPassIblSpecular; meshDescriptor.m_requiresCloneCallback = RequiresCloning; + meshDescriptor.m_isRayTracingEnabled = m_configuration.m_isRayTracingEnabled; m_meshHandle = m_meshFeatureProcessor->AcquireMesh(meshDescriptor, materials); m_meshFeatureProcessor->ConnectModelChangeEventHandler(m_meshHandle, m_changeEventHandler); @@ -392,7 +397,7 @@ namespace AZ m_meshFeatureProcessor->SetMeshLodConfiguration(m_meshHandle, GetMeshLodConfiguration()); m_meshFeatureProcessor->SetExcludeFromReflectionCubeMaps(m_meshHandle, m_configuration.m_excludeFromReflectionCubeMaps); m_meshFeatureProcessor->SetVisible(m_meshHandle, m_isVisible); - + m_meshFeatureProcessor->SetRayTracingEnabled(m_meshHandle, meshDescriptor.m_isRayTracingEnabled); // [GFX TODO] This should happen automatically. m_changeEventHandler should be passed to AcquireMesh // If the model instance or asset already exists, announce a model change to let others know it's loaded. HandleModelChange(m_meshFeatureProcessor->GetModel(m_meshHandle)); @@ -559,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()) diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.h index 6b0731fbf7..76cf6a1b39 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.h +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.h @@ -50,7 +50,7 @@ namespace AZ RHI::DrawItemSortKey m_sortKey = 0; bool m_excludeFromReflectionCubeMaps = false; bool m_useForwardPassIblSpecular = false; - + bool m_isRayTracingEnabled = true; RPI::Cullable::LodType m_lodType = RPI::Cullable::LodType::Default; RPI::Cullable::LodOverride m_lodOverride = aznumeric_cast(0); float m_minimumScreenCoverage = 1.0f / 1080.0f; @@ -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; diff --git a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.cpp b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.cpp index 58b3d8b56e..742031c84f 100644 --- a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.cpp +++ b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.cpp @@ -379,6 +379,24 @@ namespace AZ::Render 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() { return aznumeric_caster(m_actorInstance->GetActor()->GetSkeleton()->GetNumNodes()); diff --git a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.h b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.h index 7f646466a5..73d428216c 100644 --- a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.h +++ b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.h @@ -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 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/Gems/Vegetation/Code/Tests/VegetationMocks.h b/Gems/Vegetation/Code/Tests/VegetationMocks.h index ece0833433..3361afa177 100644 --- a/Gems/Vegetation/Code/Tests/VegetationMocks.h +++ b/Gems/Vegetation/Code/Tests/VegetationMocks.h @@ -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 {