BsSkybox.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "Reflection/BsIReflectable.h"
  6. #include "CoreThread/BsCoreObject.h"
  7. #include "Scene/BsSceneActor.h"
  8. namespace bs
  9. {
  10. namespace ct
  11. {
  12. class RendererTask;
  13. }
  14. /** @addtogroup Implementation
  15. * @{
  16. */
  17. /** Signals which portion of a Skybox is dirty. */
  18. enum class SkyboxDirtyFlag
  19. {
  20. // First few bits reserved by ActorDiryFlag
  21. Texture = 1 << 4
  22. };
  23. /** Base class for both core and sim thread implementations of a skybox. */
  24. class BS_CORE_EXPORT SkyboxBase : public SceneActor
  25. {
  26. public:
  27. SkyboxBase();
  28. virtual ~SkyboxBase() { }
  29. /**
  30. * Brightness multiplier that will be applied to skybox values before they're being used. Allows you to make the
  31. * skybox more or less bright. Equal to one by default.
  32. */
  33. void setBrightness(float brightness) { mBrightness = brightness; _markCoreDirty(); }
  34. /** @see setBrightness */
  35. float getBrightness() const { return mBrightness; }
  36. protected:
  37. float mBrightness; /**< Multiplier to apply to evaluated skybox values before using them. */
  38. };
  39. /** @} */
  40. /** @addtogroup Renderer-Internal
  41. * @{
  42. */
  43. namespace ct { class Skybox; }
  44. /** Allows you to specify an environment map to use for sampling radiance of the sky. */
  45. class BS_CORE_EXPORT Skybox : public IReflectable, public CoreObject, public SkyboxBase
  46. {
  47. public:
  48. ~Skybox();
  49. /**
  50. * Determines an environment map to use for sampling skybox radiance. Must be a cube-map texture, and should ideally
  51. * contain HDR data.
  52. */
  53. void setTexture(const HTexture& texture);
  54. /** @copydoc setTexture */
  55. HTexture getTexture() const { return mTexture; }
  56. /** Retrieves an implementation of the skybox usable only from the core thread. */
  57. SPtr<ct::Skybox> getCore() const;
  58. /** Creates a new skybox. */
  59. static SPtr<Skybox> create();
  60. protected:
  61. Skybox();
  62. /**
  63. * Filters the skybox radiance texture, generating filtered radiance (for reflections) and irradiance. Should be
  64. * called any time the skybox texture changes.
  65. */
  66. void filterTexture();
  67. /** @copydoc CoreObject::createCore */
  68. SPtr<ct::CoreObject> createCore() const override;
  69. /** @copydoc SkyboxBase::_markCoreDirty */
  70. void _markCoreDirty(ActorDirtyFlag flags = ActorDirtyFlag::Everything) override;
  71. /** @copydoc CoreObject::syncToCore */
  72. CoreSyncData syncToCore(FrameAlloc* allocator) override;
  73. HTexture mTexture;
  74. SPtr<Texture> mFilteredRadiance;
  75. SPtr<Texture> mIrradiance;
  76. SPtr<ct::RendererTask> mRendererTask;
  77. /************************************************************************/
  78. /* RTTI */
  79. /************************************************************************/
  80. public:
  81. friend class SkyboxRTTI;
  82. static RTTITypeBase* getRTTIStatic();
  83. RTTITypeBase* getRTTI() const override;
  84. /** Creates a new skybox instance without initializing it. */
  85. static SPtr<Skybox> createEmpty();
  86. };
  87. namespace ct
  88. {
  89. /** Core thread usable version of a bs::Skybox */
  90. class BS_CORE_EXPORT Skybox : public CoreObject, public SkyboxBase
  91. {
  92. public:
  93. ~Skybox();
  94. /** @copydoc bs::Skybox::setTexture */
  95. SPtr<Texture> getTexture() const { return mTexture; }
  96. /**
  97. * Returns a texture containing filtered version of the radiance texture used for reflections. This might not
  98. * be available if it hasn't been generated yet.
  99. */
  100. SPtr<Texture> getFilteredRadiance() const { return mFilteredRadiance; }
  101. /**
  102. * Returns a texture containing sky irradiance. This might not be available if it hasn't been generated yet.
  103. */
  104. SPtr<Texture> getIrradiance() const { return mIrradiance; }
  105. protected:
  106. friend class bs::Skybox;
  107. Skybox(const SPtr<Texture>& radiance, const SPtr<Texture>& filteredRadiance, const SPtr<Texture>& irradiance);
  108. /** @copydoc CoreObject::initialize */
  109. void initialize() override;
  110. /** @copydoc CoreObject::syncToCore */
  111. void syncToCore(const CoreSyncData& data) override;
  112. SPtr<Texture> mTexture;
  113. SPtr<Texture> mFilteredRadiance;
  114. SPtr<Texture> mIrradiance;
  115. };
  116. }
  117. /** @} */
  118. }