ParallaxMappingExampleComponent.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 <CommonSampleComponentBase.h>
  10. #include <Atom/Feature/CoreLights/DirectionalLightFeatureProcessorInterface.h>
  11. #include <Atom/Feature/CoreLights/DiskLightFeatureProcessorInterface.h>
  12. #include <AzCore/Component/TickBus.h>
  13. #include <Utils/ImGuiSidebar.h>
  14. #include <Utils/Utils.h>
  15. namespace AtomSampleViewer
  16. {
  17. //! Demostrate the effect of Parallax Mapping and Pixel Depth Offset
  18. class ParallaxMappingExampleComponent final
  19. : public CommonSampleComponentBase
  20. , public AZ::TickBus::Handler
  21. {
  22. public:
  23. AZ_COMPONENT(ParallaxMappingExampleComponent, "{C2530F5A-8626-49B7-8913-DDEA25C7E7CD}", CommonSampleComponentBase);
  24. static void Reflect(AZ::ReflectContext* context);
  25. ParallaxMappingExampleComponent();
  26. ~ParallaxMappingExampleComponent() override = default;
  27. void Activate() override;
  28. void Deactivate() override;
  29. private:
  30. // AZ::TickBus::Handler overrides...
  31. void OnTick(float deltaTime, AZ::ScriptTimePoint time);
  32. static constexpr float ConeAngleInnerRatio = 0.9f;
  33. static constexpr float CutoffIntensity = 0.1f;
  34. AZ::Render::MeshFeatureProcessorInterface::MeshHandle LoadMesh(
  35. AZ::Data::Asset<AZ::RPI::ModelAsset> modelAsset,
  36. AZ::Data::Instance<AZ::RPI::Material> material,
  37. AZ::Transform transform);
  38. void CreateDirectionalLight();
  39. void CreateDiskLight();
  40. void DrawSidebar();
  41. void SaveCameraConfiguration();
  42. void RestoreCameraConfiguration();
  43. void SetCameraConfiguration();
  44. void ConfigureCameraToLookDown();
  45. // Mesh Handles
  46. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_planeHandle;
  47. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_boxHandle;
  48. // Light
  49. AZ::Render::DirectionalLightFeatureProcessorInterface* m_directionalLightFeatureProcessor = nullptr;
  50. AZ::Render::DiskLightFeatureProcessorInterface* m_diskLightFeatureProcessor = nullptr;
  51. AZ::Render::DirectionalLightFeatureProcessorInterface::LightHandle m_directionalLightHandle;
  52. AZ::Render::DiskLightFeatureProcessorInterface::LightHandle m_diskLightHandle;
  53. float m_lightRotationAngle = 0.f; // in radian
  54. bool m_lightAutoRotate = true;
  55. enum class LightSelection : int
  56. {
  57. None,
  58. Directional,
  59. Spot
  60. };
  61. int m_lightType = static_cast<int>(LightSelection::Directional);
  62. //Assets
  63. AZ::Data::Asset<AZ::RPI::ModelAsset> m_planeAsset;
  64. AZ::Data::Asset<AZ::RPI::ModelAsset> m_boxAsset;
  65. AZ::Data::Asset<AZ::RPI::MaterialAsset> m_defaultMaterialAsset;
  66. AZ::Data::Asset<AZ::RPI::MaterialAsset> m_parallaxMaterialAsset;
  67. AZ::Data::Instance<AZ::RPI::Material> m_defaultMaterial;
  68. AZ::Data::Instance<AZ::RPI::Material> m_parallaxMaterial;
  69. AZ::RPI::MaterialPropertyIndex m_parallaxEnableIndex;
  70. AZ::RPI::MaterialPropertyIndex m_parallaxFactorIndex;
  71. AZ::RPI::MaterialPropertyIndex m_parallaxOffsetIndex;
  72. AZ::RPI::MaterialPropertyIndex m_parallaxShowClippingIndex;
  73. AZ::RPI::MaterialPropertyIndex m_parallaxAlgorithmIndex;
  74. AZ::RPI::MaterialPropertyIndex m_parallaxQualityIndex;
  75. AZ::RPI::MaterialPropertyIndex m_parallaxUvIndex;
  76. AZ::RPI::MaterialPropertyIndex m_pdoEnableIndex;
  77. // Other UVs that when parallaxUv is changed, they must follow the change.
  78. AZ::RPI::MaterialPropertyIndex m_ambientOcclusionUvIndex;
  79. AZ::RPI::MaterialPropertyIndex m_baseColorUvIndex;
  80. AZ::RPI::MaterialPropertyIndex m_normalUvIndex;
  81. AZ::RPI::MaterialPropertyIndex m_roughnessUvIndex;
  82. AZ::RPI::MaterialPropertyIndex m_centerUVIndex;
  83. AZ::RPI::MaterialPropertyIndex m_tileUIndex;
  84. AZ::RPI::MaterialPropertyIndex m_tileVIndex;
  85. AZ::RPI::MaterialPropertyIndex m_scaleUVIndex;
  86. AZ::RPI::MaterialPropertyIndex m_offsetUIndex;
  87. AZ::RPI::MaterialPropertyIndex m_offsetVIndex;
  88. AZ::RPI::MaterialPropertyIndex m_rotationUVIndex;
  89. // parallax setting
  90. bool m_parallaxEnable = true;
  91. bool m_pdoEnable = true;
  92. float m_parallaxFactor = 0.05f;
  93. float m_parallaxOffset = 0.0f;
  94. bool m_parallaxShowClipping = false;
  95. // see StandardPbr.materialtype for the full enum list.
  96. int m_parallaxAlgorithm = 2; // POM
  97. int m_parallaxQuality = 2; // High
  98. int m_parallaxUv = 0; // 0 = UV0, 1 = UV1
  99. // plane setting
  100. AZ::Transform m_planeTransform;
  101. float m_planeRotationAngle = 0.f; // in radian
  102. float m_planeCenterU = 0.f;
  103. float m_planeCenterV = 0.f;
  104. float m_planeTileU = 1.f;
  105. float m_planeTileV = 1.f;
  106. float m_planeScaleUV = 1.f;
  107. float m_planeOffsetU = 0.f;
  108. float m_planeOffsetV = 0.f;
  109. float m_planeRotateUV = 0.f; // in degrees
  110. // original camera configuration
  111. float m_originalFarClipDistance = 0.f;
  112. float m_originalCameraFovRadians = 0.f;
  113. // ImGui
  114. ImGuiSidebar m_imguiSidebar;
  115. };
  116. } // namespace AtomSampleViewer