DiffuseGIExampleComponent.h 6.1 KB

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