Переглянути джерело

Merge pull request #595 from aws-lumberyard-dev/Atom/dmcdiar/ATOM-18129

Updates to the SSRExampleComponent for Hybrid SSR-RT
dmcdiarmid-ly 2 роки тому
батько
коміт
a48b0e5363

+ 41 - 24
Gem/Code/Source/SSRExampleComponent.cpp

@@ -8,12 +8,14 @@
 
 #include <SSRExampleComponent.h>
 #include <Atom/Component/DebugCamera/NoClipControllerComponent.h>
+#include <Atom/RHI/RHISystemInterface.h>
 #include <Atom/RPI.Public/Scene.h>
 #include <Atom/RPI.Public/RPISystemInterface.h>
 #include <Atom/RPI.Public/Pass/PassFilter.h>
 #include <Atom/RPI.Reflect/Asset/AssetUtils.h>
 #include <Atom/RPI.Reflect/Model/ModelAsset.h>
 #include <Atom/RPI.Reflect/Material/MaterialAsset.h>
+#include <Atom/Feature/SpecularReflections/SpecularReflectionsFeatureProcessorInterface.h>
 #include <Automation/ScriptableImGui.h>
 #include <Automation/ScriptRunnerBus.h>
 #include <Utils/Utils.h>
@@ -49,13 +51,15 @@ namespace AtomSampleViewer
         InitLightingPresets(true);
 
         // enable the SSR pass in the pipeline
-        EnableSSR(true);
+        m_enableSSR = true;
+        UpdateSSROptions();
     }
 
     void SSRExampleComponent::Deactivate()
     {
         // disable the SSR pass in the pipeline
-        EnableSSR(false);
+        m_enableSSR = false;
+        UpdateSSROptions();
 
         ShutdownLightingPresets();
 
@@ -170,10 +174,29 @@ namespace AtomSampleViewer
             return;
         }
 
+        AZ::RHI::Ptr<AZ::RHI::Device> device = AZ::RHI::RHISystemInterface::Get()->GetDevice();
+        bool rayTracingSupported = device->GetFeatures().m_rayTracing;
+
+        bool optionsChanged = false;
+
+        ImGui::NewLine();
+        optionsChanged |= ImGui::Checkbox("Enable SSR", &m_enableSSR);
+
+        if (rayTracingSupported)
+        {
+            optionsChanged |= ImGui::Checkbox("Hardware Ray Tracing", &m_rayTracing);
+            if (m_rayTracing)
+            {
+                optionsChanged |= ImGui::Checkbox("Ray Trace Fallback Data", &m_rayTraceFallbackData);
+            }
+        }
+
         ImGui::NewLine();
-        if (ImGui::Checkbox("Enable SSR", &m_enableSSR))
+        ImGui::Text("Temporal Filtering Strength");
+        optionsChanged |= ImGui::SliderFloat("##Temporal Filtering Strength", &m_temporalFilteringStrength, 0.0f, 3.0f);
+        if (optionsChanged)
         {
-            EnableSSR(m_enableSSR);
+            UpdateSSROptions();
         }
 
         ImGui::NewLine();
@@ -194,26 +217,20 @@ namespace AtomSampleViewer
         m_imguiSidebar.End();
     }
 
-    void SSRExampleComponent::EnableSSR(bool enabled)
+    void SSRExampleComponent::UpdateSSROptions()
     {
-        // set screen space pass
-        {
-            AZ::RPI::PassFilter passFilter = AZ::RPI::PassFilter::CreateWithPassName(AZ::Name("ReflectionScreenSpacePass"), (AZ::RPI::Scene*) nullptr);
-            AZ::RPI::PassSystemInterface::Get()->ForEachPass(passFilter, [enabled](AZ::RPI::Pass* pass) -> AZ::RPI::PassFilterExecutionFlow
-                {
-                    pass->SetEnabled(enabled);
-                    return  AZ::RPI::PassFilterExecutionFlow::ContinueVisitingPasses;
-                });
-        }
-
-        // set copy frame buffer pass
-        {
-            AZ::RPI::PassFilter passFilter = AZ::RPI::PassFilter::CreateWithPassName(AZ::Name("ReflectionCopyFrameBufferPass"), (AZ::RPI::Scene*) nullptr);
-            AZ::RPI::PassSystemInterface::Get()->ForEachPass(passFilter, [enabled](AZ::RPI::Pass* pass) -> AZ::RPI::PassFilterExecutionFlow
-                {
-                    pass->SetEnabled(enabled);
-                    return  AZ::RPI::PassFilterExecutionFlow::ContinueVisitingPasses;
-                });
-        }
+        AZ::Render::SpecularReflectionsFeatureProcessorInterface* specularReflectionsFeatureProcessor = m_scene->GetFeatureProcessorForEntityContextId<AZ::Render::SpecularReflectionsFeatureProcessorInterface>(GetEntityContextId());
+        AZ_Assert(specularReflectionsFeatureProcessor, "SpecularReflectionsFeatureProcessor not available.");
+
+        AZ::Render::SSROptions ssrOptions = specularReflectionsFeatureProcessor->GetSSROptions();
+        ssrOptions.m_enable = m_enableSSR;
+        ssrOptions.m_rayTracing = m_rayTracing;
+        ssrOptions.m_rayTraceFallbackData = m_rayTraceFallbackData;
+        ssrOptions.m_coneTracing = false;
+        ssrOptions.m_maxRoughness = 0.5f;
+        ssrOptions.m_maxDepthThreshold = m_maxDepthThreshold;
+        ssrOptions.m_temporalFilteringStrength = m_temporalFilteringStrength;
+
+        specularReflectionsFeatureProcessor->SetSSROptions(ssrOptions);
     }
 }

+ 5 - 1
Gem/Code/Source/SSRExampleComponent.h

@@ -46,7 +46,7 @@ namespace AtomSampleViewer
 
         void OnModelReady(AZ::Data::Instance<AZ::RPI::Model> model);
         void DrawSidebar();
-        void EnableSSR(bool enabled);
+        void UpdateSSROptions();
 
         // meshes
         AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_statueMeshHandle;
@@ -64,7 +64,11 @@ namespace AtomSampleViewer
 
         ImGuiSidebar m_imguiSidebar;
         bool m_enableSSR = true;
+        bool m_rayTracing = false;
+        bool m_rayTraceFallbackData = true;
         bool m_resetCamera = true;
         float m_originalFarClipDistance = 0.0f;
+        float m_maxDepthThreshold = 0.4f;
+        float m_temporalFilteringStrength = 0.25f;
     };
 } // namespace AtomSampleViewer

+ 1 - 1
Materials/SSRExample/GroundPlaneAluminum.material

@@ -11,7 +11,7 @@
         "baseColor.factor": 0.75,
         "metallic.factor": 1.0,
         "normal.textureMap": "Textures/Default/default_normal.tif",
-        "roughness.factor": 0.20000000298023224,
+        "roughness.factor": 0.40000000298023224,
         "specularF0.enableMultiScatterCompensation": true,
         "specularF0.factor": 1.0
     }