DiffuseGIExampleComponent.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzFramework/Components/CameraBus.h>
  10. #include <CommonSampleComponentBase.h>
  11. #include <AzCore/Component/EntityBus.h>
  12. #include <AzCore/Component/TickBus.h>
  13. #include <Utils/Utils.h>
  14. #include <Utils/ImGuiSidebar.h>
  15. #include <Utils/ImGuiMaterialDetails.h>
  16. #include <Utils/ImGuiAssetBrowser.h>
  17. #include <Atom/RPI.Public/WindowContext.h>
  18. #include <Atom/Feature/Mesh/MeshFeatureProcessorInterface.h>
  19. #include <Atom/Feature/CoreLights/PointLightFeatureProcessorInterface.h>
  20. #include <Atom/Feature/CoreLights/DirectionalLightFeatureProcessorInterface.h>
  21. #include <Atom/Feature/DiffuseGlobalIllumination/DiffuseProbeGridFeatureProcessorInterface.h>
  22. #include <Atom/Feature/DiffuseGlobalIllumination/DiffuseGlobalIlluminationFeatureProcessorInterface.h>
  23. namespace AtomSampleViewer
  24. {
  25. //! This sample demonstrates diffuse global illumination using the DiffuseProbeGrid.
  26. class DiffuseGIExampleComponent final
  27. : public CommonSampleComponentBase
  28. , public AZ::TickBus::Handler
  29. {
  30. public:
  31. AZ_COMPONENT(AtomSampleViewer::DiffuseGIExampleComponent, "{46E0E36D-707D-42D6-B4CB-08A19F576299}", CommonSampleComponentBase);
  32. static void Reflect(AZ::ReflectContext* context);
  33. DiffuseGIExampleComponent() = default;
  34. ~DiffuseGIExampleComponent() override = default;
  35. // Component
  36. void Activate() override;
  37. void Deactivate() override;
  38. private:
  39. AZ_DISABLE_COPY_MOVE(DiffuseGIExampleComponent);
  40. // TickBus::Handler
  41. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  42. // EntityBus::MultiHandler
  43. void OnEntityDestruction(const AZ::EntityId& entityId) override;
  44. float ComputePointLightAttenuationRadius(AZ::Color color, float intensity);
  45. void LoadSampleSceneAssets();
  46. void CreateCornellBoxScene(bool geometryOnly);
  47. void CreateSponzaScene();
  48. void UpdateImGui();
  49. void SetSampleScene(bool geometryOnly = false);
  50. void UnloadSampleScene(bool geometryOnly);
  51. void DisableGlobalIbl();
  52. void EnableDiffuseIbl();
  53. // camera
  54. bool m_resetCamera = true;
  55. float m_originalFarClipDistance = 0.0f;
  56. AZ::Vector3 m_cameraTranslation = AZ::Vector3(0.0f);
  57. float m_cameraHeading = 0.0f;
  58. Utils::DefaultIBL m_defaultIbl;
  59. // directional light
  60. float m_directionalLightPitch = -AZ::Constants::QuarterPi;
  61. float m_directionalLightYaw = 0.0f;
  62. float m_directionalLightIntensity = 20.0f;
  63. AZ::Color m_directionalLightColor;
  64. // point light
  65. AZ::Vector3 m_pointLightPos;
  66. AZ::Color m_pointLightColor;
  67. float m_pointLightIntensity = 20.0f;
  68. // ImGui
  69. ImGuiSidebar m_imguiSidebar;
  70. enum SampleScene
  71. {
  72. None,
  73. CornellBox,
  74. Sponza
  75. };
  76. SampleScene m_sampleScene = SampleScene::None;
  77. // CornellBox scene
  78. enum class CornellBoxMeshes
  79. {
  80. LeftWall,
  81. RightWall,
  82. BackWall,
  83. Ceiling,
  84. Floor,
  85. LargeBox,
  86. SmallBox,
  87. Count
  88. };
  89. enum class CornellBoxColors
  90. {
  91. Red,
  92. Green,
  93. Blue,
  94. Yellow,
  95. White,
  96. Count
  97. };
  98. static const char* CornellBoxColorNames[aznumeric_cast<uint32_t>(CornellBoxColors::Count)];
  99. static const uint32_t CornellBoxColorNamesCount = sizeof(CornellBoxColorNames) / sizeof(CornellBoxColorNames[0]);
  100. AZ::Data::Asset<AZ::RPI::MaterialAsset>& GetCornellBoxMaterialAsset(CornellBoxColors color);
  101. // models
  102. AZ::Data::Asset<AZ::RPI::ModelAsset> m_planeModelAsset;
  103. AZ::Data::Asset<AZ::RPI::ModelAsset> m_cubeModelAsset;
  104. // materials
  105. AZ::Data::Asset<AZ::RPI::MaterialAsset> m_redMaterialAsset;
  106. AZ::Data::Asset<AZ::RPI::MaterialAsset> m_greenMaterialAsset;
  107. AZ::Data::Asset<AZ::RPI::MaterialAsset> m_blueMaterialAsset;
  108. AZ::Data::Asset<AZ::RPI::MaterialAsset> m_yellowMaterialAsset;
  109. AZ::Data::Asset<AZ::RPI::MaterialAsset> m_whiteMaterialAsset;
  110. // wall visibility
  111. bool m_leftWallVisible = true;
  112. bool m_rightWallVisible = true;
  113. bool m_backWallVisible = true;
  114. bool m_floorVisible = true;
  115. bool m_ceilingVisible = true;
  116. // wall material colors
  117. CornellBoxColors m_leftWallColor = CornellBoxColors::Red;
  118. CornellBoxColors m_rightWallColor = CornellBoxColors::Green;
  119. CornellBoxColors m_backWallColor = CornellBoxColors::White;
  120. CornellBoxColors m_floorColor = CornellBoxColors::White;
  121. CornellBoxColors m_ceilingColor = CornellBoxColors::White;
  122. // Sponza scene
  123. enum class SponzaMeshes
  124. {
  125. Inside,
  126. Count
  127. };
  128. // models
  129. AZ::Data::Asset<AZ::RPI::ModelAsset> m_sponzaModelAsset;
  130. // scene
  131. AZStd::vector<AZ::Render::MeshFeatureProcessorInterface::MeshHandle> m_meshHandles;
  132. AZ::Render::PointLightFeatureProcessorInterface::LightHandle m_pointLightHandle;
  133. AZ::Render::DirectionalLightFeatureProcessorInterface::LightHandle m_directionalLightHandle;
  134. AZ::Render::DiffuseProbeGridHandle m_diffuseProbeGrid;
  135. // diffuse IBL (Sponza only)
  136. bool m_useDiffuseIbl = true;
  137. AZ::Data::Asset<AZ::RPI::StreamingImageAsset> m_diffuseImageAsset;
  138. float m_diffuseIblExposure = 2.0f;
  139. // shadow settings
  140. static const AZ::Render::ShadowmapSize s_shadowmapSizes[];
  141. static const char* s_directionalLightShadowmapSizeLabels[];
  142. static constexpr int s_shadowmapSizeIndexDefault = 3;
  143. static constexpr int s_cascadesCountDefault = 4;
  144. // GI settings
  145. bool m_enableDiffuseGI = true;
  146. float m_viewBias = 0.4f;
  147. float m_normalBias = 0.1f;
  148. float m_ambientMultiplier = 1.0f;
  149. AZ::Vector3 m_origin;
  150. bool m_giShadows = true;
  151. };
  152. } // namespace AtomSampleViewer