SkyboxComponent.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // Copyright (C) 2009-present, 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/Resource/Forward.h>
  8. #include <AnKi/Math.h>
  9. namespace anki {
  10. // Forward
  11. class SkyboxQueueElement;
  12. enum class SkyboxType : U8
  13. {
  14. kSolidColor,
  15. kImage2D,
  16. kGenerated
  17. };
  18. // Skybox config.
  19. class SkyboxComponent : public SceneComponent
  20. {
  21. ANKI_SCENE_COMPONENT(SkyboxComponent)
  22. public:
  23. SkyboxComponent(SceneNode* node);
  24. ~SkyboxComponent();
  25. SkyboxType getSkyboxType() const
  26. {
  27. return m_type;
  28. }
  29. void setSolidColor(const Vec3& color)
  30. {
  31. m_type = SkyboxType::kSolidColor;
  32. m_color = color.max(Vec3(0.0f));
  33. }
  34. Vec3 getSolidColor() const
  35. {
  36. ANKI_ASSERT(m_type == SkyboxType::kSolidColor);
  37. return m_color;
  38. }
  39. void loadImageResource(CString filename);
  40. ImageResource& getImageResource() const
  41. {
  42. ANKI_ASSERT(m_type == SkyboxType::kImage2D);
  43. return *m_image;
  44. }
  45. void setImageScale(Vec3 s)
  46. {
  47. m_imageScale = s;
  48. }
  49. const Vec3& getImageScale() const
  50. {
  51. return m_imageScale;
  52. }
  53. void setImageBias(Vec3 s)
  54. {
  55. m_imageBias = s;
  56. }
  57. const Vec3& getImageBias() const
  58. {
  59. return m_imageBias;
  60. }
  61. void setGeneratedSky()
  62. {
  63. m_type = SkyboxType::kGenerated;
  64. }
  65. void setMinFogDensity(F32 density)
  66. {
  67. m_fog.m_minDensity = clamp(density, 0.0f, 100.0f);
  68. }
  69. F32 getMinFogDensity() const
  70. {
  71. return m_fog.m_minDensity;
  72. }
  73. void setMaxFogDensity(F32 density)
  74. {
  75. m_fog.m_maxDensity = clamp(density, 0.0f, 100.0f);
  76. }
  77. F32 getMaxFogDensity() const
  78. {
  79. return m_fog.m_maxDensity;
  80. }
  81. /// The height (units) where fog density is getMinFogDensity().
  82. void setHeightOfMinFogDensity(F32 height)
  83. {
  84. m_fog.m_heightOfMinDensity = height;
  85. }
  86. F32 getHeightOfMinFogDensity() const
  87. {
  88. return m_fog.m_heightOfMinDensity;
  89. }
  90. /// The height (units) where fog density is getMaxFogDensity().
  91. void setHeightOfMaxFogDensity(F32 height)
  92. {
  93. m_fog.m_heightOfMaxDensity = height;
  94. }
  95. F32 getHeightOfMaxFogDensity() const
  96. {
  97. return m_fog.m_heightOfMaxDensity;
  98. }
  99. void setFogScatteringCoefficient(F32 coeff)
  100. {
  101. m_fog.m_scatteringCoeff = coeff;
  102. }
  103. F32 getFogScatteringCoefficient() const
  104. {
  105. return m_fog.m_scatteringCoeff;
  106. }
  107. void setFogAbsorptionCoefficient(F32 coeff)
  108. {
  109. m_fog.m_absorptionCoeff = coeff;
  110. }
  111. F32 getFogAbsorptionCoefficient() const
  112. {
  113. return m_fog.m_absorptionCoeff;
  114. }
  115. void setFogDiffuseColor(const Vec3& color)
  116. {
  117. m_fog.m_diffuseColor = color;
  118. }
  119. const Vec3& getFogDiffuseColor() const
  120. {
  121. return m_fog.m_diffuseColor;
  122. }
  123. private:
  124. SkyboxType m_type = SkyboxType::kSolidColor;
  125. Vec3 m_color = Vec3(0.0f, 0.0f, 0.5f);
  126. ImageResourcePtr m_image;
  127. Vec3 m_imageScale = Vec3(1.0f);
  128. Vec3 m_imageBias = Vec3(0.0f);
  129. // Fog
  130. class
  131. {
  132. public:
  133. F32 m_minDensity = 0.0f;
  134. F32 m_maxDensity = 0.9f;
  135. F32 m_heightOfMinDensity = 20.0f; // The height (meters) where fog density is max.
  136. F32 m_heightOfMaxDensity = 0.0f; // The height (meters) where fog density is the min value.
  137. F32 m_scatteringCoeff = 0.01f;
  138. F32 m_absorptionCoeff = 0.02f;
  139. Vec3 m_diffuseColor = Vec3(1.0f);
  140. } m_fog;
  141. void update(SceneComponentUpdateInfo& info, Bool& updated) override;
  142. Error serialize(SceneSerializer& serializer) override;
  143. };
  144. } // end namespace anki