DiffuseGIExampleComponent.h 6.4 KB

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