SkyboxComponent.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // Copyright (C) 2009-2023, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Scene/Components/SceneComponent.h>
  7. #include <AnKi/Scene/Spatial.h>
  8. #include <AnKi/Resource/Forward.h>
  9. #include <AnKi/Math.h>
  10. namespace anki {
  11. // Forward
  12. class SkyboxQueueElement;
  13. /// @addtogroup scene
  14. /// @{
  15. /// @memberof SkyboxComponent
  16. enum class SkyboxType : U8
  17. {
  18. kSolidColor,
  19. kImage2D
  20. };
  21. /// Skybox config.
  22. class SkyboxComponent : public SceneComponent
  23. {
  24. ANKI_SCENE_COMPONENT(SkyboxComponent)
  25. public:
  26. SkyboxComponent(SceneNode* node);
  27. ~SkyboxComponent();
  28. void setSolidColor(const Vec3& color)
  29. {
  30. m_type = SkyboxType::kSolidColor;
  31. m_color = color.max(Vec3(0.0f));
  32. }
  33. void loadImageResource(CString filename);
  34. void setMinFogDensity(F32 density)
  35. {
  36. m_fog.m_minDensity = clamp(density, 0.0f, 100.0f);
  37. }
  38. F32 getMinFogDensity() const
  39. {
  40. return m_fog.m_minDensity;
  41. }
  42. void setMaxFogDensity(F32 density)
  43. {
  44. m_fog.m_maxDensity = clamp(density, 0.0f, 100.0f);
  45. }
  46. F32 getMaxFogDensity() const
  47. {
  48. return m_fog.m_maxDensity;
  49. }
  50. /// The height (units) where fog density is getMinFogDensity().
  51. void setHeightOfMinFogDensity(F32 height)
  52. {
  53. m_fog.m_heightOfMinDensity = height;
  54. }
  55. F32 getHeightOfMinFogDensity() const
  56. {
  57. return m_fog.m_heightOfMinDensity;
  58. }
  59. /// The height (units) where fog density is getMaxFogDensity().
  60. void setHeightOfMaxFogDensity(F32 height)
  61. {
  62. m_fog.m_heightOfMaxDensity = height;
  63. }
  64. F32 getHeightOfMaxFogDensity() const
  65. {
  66. return m_fog.m_heightOfMaxDensity;
  67. }
  68. void setFogScatteringCoefficient(F32 coeff)
  69. {
  70. m_fog.m_scatteringCoeff = coeff;
  71. }
  72. F32 getFogScatteringCoefficient() const
  73. {
  74. return m_fog.m_scatteringCoeff;
  75. }
  76. void setFogAbsorptionCoefficient(F32 coeff)
  77. {
  78. m_fog.m_absorptionCoeff = coeff;
  79. }
  80. F32 getFogAbsorptionCoefficient() const
  81. {
  82. return m_fog.m_absorptionCoeff;
  83. }
  84. void setFogDiffuseColor(const Vec3& color)
  85. {
  86. m_fog.m_diffuseColor = color;
  87. }
  88. const Vec3& getFogDiffuseColor() const
  89. {
  90. return m_fog.m_diffuseColor;
  91. }
  92. void setupSkyboxQueueElement(SkyboxQueueElement& queueElement) const;
  93. private:
  94. Spatial m_spatial;
  95. SkyboxType m_type = SkyboxType::kSolidColor;
  96. Vec3 m_color = Vec3(0.0f, 0.0f, 0.5f);
  97. ImageResourcePtr m_image;
  98. // Fog
  99. class
  100. {
  101. public:
  102. F32 m_minDensity = 0.0f;
  103. F32 m_maxDensity = 0.9f;
  104. F32 m_heightOfMinDensity = 20.0f; ///< The height (meters) where fog density is max.
  105. F32 m_heightOfMaxDensity = 0.0f; ///< The height (meters) where fog density is the min value.
  106. F32 m_scatteringCoeff = 0.01f;
  107. F32 m_absorptionCoeff = 0.02f;
  108. Vec3 m_diffuseColor = Vec3(1.0f);
  109. } m_fog;
  110. Error update(SceneComponentUpdateInfo& info, Bool& updated) override;
  111. };
  112. /// @}
  113. } // end namespace anki