ParallaxMappingExampleComponent.h 5.3 KB

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