SphericalHarmonicsExampleComponent.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 <RHI/BasicRHIComponent.h>
  10. #include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
  11. #include <Atom/RHI/BufferPool.h>
  12. #include <Atom/RHI/DrawItem.h>
  13. #include <Atom/RHI.Reflect/SamplerState.h>
  14. #include <AzCore/Component/TickBus.h>
  15. #include <Utils/ImGuiSidebar.h>
  16. namespace AtomSampleViewer
  17. {
  18. /*
  19. * sample for demonstrating application of spherical harominics with two modes
  20. * Demo mode: provides visualisation of shapes of each SH basis, and differences
  21. * between three solvers on performance and flexibility
  22. * Render mode: demonstrates how to calculate exiting diffuse radiance based on SH coefficients and how to
  23. * rotate an exsiting SH sets with provided functions
  24. */
  25. class SphericalHarmonicsExampleComponent final
  26. : public BasicRHIComponent
  27. , public AZ::TickBus::Handler
  28. {
  29. public:
  30. AZ_COMPONENT(SphericalHarmonicsExampleComponent, "{7E99662E-2C3D-4E3F-87B1-B9A6BB4B4AF5}", AZ::Component);
  31. static void Reflect(AZ::ReflectContext* context);
  32. SphericalHarmonicsExampleComponent();
  33. ~SphericalHarmonicsExampleComponent() = default;
  34. protected:
  35. AZ_DISABLE_COPY(SphericalHarmonicsExampleComponent);
  36. // AZ::Component overrides ...
  37. virtual void Activate() override;
  38. virtual void Deactivate() override;
  39. // AZ::TickBus::Handler overrides ...
  40. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  41. // AZ::Component overrides ...
  42. bool ReadInConfig(const AZ::ComponentConfig* baseConfig) override;
  43. void DrawIMGui();
  44. float CalFakeLightSH(bool& flag);
  45. // ------------------- demo mode variables -------------------
  46. AZ::RHI::ConstPtr<AZ::RHI::PipelineState> m_demoPipelineState;
  47. AZ::Data::Instance<AZ::RPI::ShaderResourceGroup> m_demoShaderResourceGroup;
  48. AZ::RHI::ShaderInputConstantIndex m_demoObjectMatrixInputIndex;
  49. AZ::RHI::ShaderInputConstantIndex m_SHBandInputIndex;
  50. AZ::RHI::ShaderInputConstantIndex m_SHOrderInputIndex;
  51. AZ::RHI::ShaderInputConstantIndex m_SHSolverInputIndex;
  52. AZ::RHI::ShaderInputConstantIndex m_EnableDistortionInputIndex;
  53. // set band(l) of displayed SHbasis
  54. int m_shaderInputSHBand = 0;
  55. // set order(m) of displayed SHbasis
  56. int m_shaderInputSHOrder = 0;
  57. // change solver used for evaluation
  58. int m_shaderInputSHSolver = 0;
  59. // enable distortion based on magnitude of SH basis
  60. bool m_shaderInputEnableDistortion = true;
  61. bool m_updateDemoSRG = true;
  62. // -----------------------------------------------------------
  63. // ------------------- render mode variables -------------------
  64. AZ::RHI::ConstPtr<AZ::RHI::PipelineState> m_renderPipelineState;
  65. AZ::Data::Instance<AZ::RPI::ShaderResourceGroup> m_renderShaderResourceGroup;
  66. AZ::Data::Instance<AZ::RPI::ShaderResourceGroup> m_viewShaderResourceGroup;
  67. AZ::RHI::ShaderInputConstantIndex m_renderObjectMatrixInputIndex;
  68. AZ::RHI::ShaderInputConstantIndex m_presetIndexInputIndex;
  69. AZ::RHI::ShaderInputConstantIndex m_exposureInputIndex;
  70. AZ::RHI::ShaderInputConstantIndex m_enableGammaCorrectionInputIndex;
  71. AZ::RHI::ShaderInputConstantIndex m_SHFakeLightCoefficientsInputIndex;
  72. AZ::RHI::ShaderInputConstantIndex m_rotationAngleInputIndex;
  73. // change SH coeffiicent set used for shading
  74. int m_shaderInputPresetIndex = 0;
  75. // change tone mapping exposure
  76. float m_shaderInputExposure = 1.0;
  77. // enable gamme correction
  78. bool m_shaderInputEnableGammaCorrection = false;
  79. // 16 floats represent first 4 bands SH coefficients (0 to 3) for fake ligt function
  80. AZ::Matrix4x4 m_shaderInputSHFakeLightCoefficients;
  81. // Euler angle for rotation demo case
  82. AZ::Vector3 m_shaderInputRotationAngle;
  83. bool m_updateRenderSRG = true;
  84. // -------------------------------------------------------------
  85. // ----------------------- gui variables -----------------------
  86. ImGuiSidebar m_imguiSidebar;
  87. bool m_mode = true;
  88. bool m_recomputeFakeLight = false;
  89. // -------------------------------------------------------------
  90. // ---------------- streaming buffer variables ----------------
  91. AZ::RHI::Ptr<AZ::RHI::BufferPool> m_bufferPool;
  92. AZ::RHI::Ptr<AZ::RHI::Buffer> m_indexBuffer;
  93. AZ::RHI::Ptr<AZ::RHI::Buffer> m_positionBuffer;
  94. AZ::RHI::Ptr<AZ::RHI::Buffer> m_uvBuffer;
  95. struct BufferData
  96. {
  97. AZStd::array<VertexPosition, 4> m_positions;
  98. AZStd::array<VertexUV, 4> m_uvs;
  99. AZStd::array<uint16_t, 6> m_indices;
  100. };
  101. AZ::RHI::DrawItem m_drawItem;
  102. AZStd::array<AZ::RHI::StreamBufferView, 2> m_streamBufferViews;
  103. // ------------------------------------------------------------
  104. AZ::EntityId m_cameraEntityId;
  105. };
  106. }