SphericalHarmonicsExampleComponent.h 5.1 KB

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