BsSkybox.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 "BsIReflectable.h"
  6. #include "BsCoreObject.h"
  7. namespace bs
  8. {
  9. namespace ct
  10. {
  11. class RendererTask;
  12. }
  13. /** @addtogroup Implementation
  14. * @{
  15. */
  16. /** Signals which portion of a skybox is dirty. */
  17. enum class SkyboxDirtyFlag
  18. {
  19. Texture = 0x01,
  20. Everything = 0x02
  21. };
  22. /** Base class for both core and sim thread implementations of a skybox. */
  23. class BS_CORE_EXPORT SkyboxBase
  24. {
  25. public:
  26. SkyboxBase();
  27. virtual ~SkyboxBase() { }
  28. /** Checks whether the skybox should be used or not. */
  29. bool getIsActive() const { return mIsActive; }
  30. /** Sets whether the skybox should be used or not. */
  31. void setIsActive(bool active) { mIsActive = active; _markCoreDirty(); }
  32. /**
  33. * Brightness multiplier that will be applied to skybox values before they're being used. Allows you to make the
  34. * skybox more or less bright. Equal to one by default.
  35. */
  36. void setBrightness(float brightness) { mBrightness = brightness; _markCoreDirty(); }
  37. /** @see setBrightness */
  38. float getBrightness() const { return mBrightness; }
  39. /** Returns an identifier that uniquely identifies the skybox. */
  40. const String& getUUID() const { return mUUID; }
  41. /**
  42. * Marks the simulation thread object as dirty and notifies the system its data should be synced with its core
  43. * thread counterpart.
  44. */
  45. virtual void _markCoreDirty(SkyboxDirtyFlag flags = SkyboxDirtyFlag::Everything) { }
  46. protected:
  47. String mUUID; /**< Identifier that uniquely identifies the skybox. */
  48. bool mIsActive; /**< Determines whether the skybox should be rendered or not. */
  49. float mBrightness; /**< Multiplier to apply to evaluated skybox values before using them. */
  50. };
  51. /** Templated base class for both core and sim thread implementations of a skybox. */
  52. template<bool Core>
  53. class BS_CORE_EXPORT TSkybox : public SkyboxBase
  54. {
  55. typedef typename TTextureType<Core>::Type TextureType;
  56. public:
  57. TSkybox();
  58. virtual ~TSkybox() { }
  59. /**
  60. * Assigns an environment map to use for sampling skybox radiance. Must be a cube-map texture, and should ideally
  61. * contain HDR data.
  62. */
  63. void setTexture(const TextureType& texture) { mTexture = texture; _markCoreDirty(SkyboxDirtyFlag::Texture); }
  64. /** Gets the texture assigned through setTexture(). */
  65. TextureType getTexture() const { return mTexture; }
  66. protected:
  67. TextureType mTexture;
  68. };
  69. /** @} */
  70. /** @addtogroup Renderer-Internal
  71. * @{
  72. */
  73. namespace ct { class Skybox; }
  74. /** Allows you to specify an environment map to use for sampling radiance of the sky. */
  75. class BS_CORE_EXPORT Skybox : public IReflectable, public CoreObject, public TSkybox<false>
  76. {
  77. public:
  78. ~Skybox();
  79. /** Retrieves an implementation of the skybox usable only from the core thread. */
  80. SPtr<ct::Skybox> getCore() const;
  81. /** Creates a new skybox. */
  82. static SPtr<Skybox> create();
  83. protected:
  84. Skybox();
  85. /**
  86. * Filters the skybox radiance texture, generating filtered radiance (for reflections) and irradiance. Should be
  87. * called any time the skybox texture changes.
  88. */
  89. void filterTexture();
  90. /** @copydoc CoreObject::createCore */
  91. SPtr<ct::CoreObject> createCore() const override;
  92. /** @copydoc SkyboxBase::_markCoreDirty */
  93. void _markCoreDirty(SkyboxDirtyFlag flags = SkyboxDirtyFlag::Everything) override;
  94. /** @copydoc CoreObject::syncToCore */
  95. CoreSyncData syncToCore(FrameAlloc* allocator) override;
  96. SPtr<Texture> mFilteredRadiance;
  97. SPtr<Texture> mIrradiance;
  98. SPtr<ct::RendererTask> mRendererTask;
  99. /************************************************************************/
  100. /* RTTI */
  101. /************************************************************************/
  102. public:
  103. friend class SkyboxRTTI;
  104. static RTTITypeBase* getRTTIStatic();
  105. RTTITypeBase* getRTTI() const override;
  106. };
  107. namespace ct
  108. {
  109. /** Core thread usable version of a bs::Skybox */
  110. class BS_CORE_EXPORT Skybox : public CoreObject, public TSkybox<true>
  111. {
  112. public:
  113. ~Skybox();
  114. /**
  115. * Returns a texture containing filtered version of the radiance texture used for reflections. This might not
  116. * be available if it hasn't been generated yet.
  117. */
  118. SPtr<Texture> getFilteredRadiance() const { return mFilteredRadiance; }
  119. /**
  120. * Returns a texture containing sky irradiance. This might not be available if it hasn't been generated yet.
  121. */
  122. SPtr<Texture> getIrradiance() const { return mIrradiance; }
  123. protected:
  124. friend class bs::Skybox;
  125. Skybox(const SPtr<Texture>& filteredRadiance, const SPtr<Texture>& irradiance);
  126. /** @copydoc CoreObject::initialize */
  127. void initialize() override;
  128. /** @copydoc CoreObject::syncToCore */
  129. void syncToCore(const CoreSyncData& data) override;
  130. SPtr<Texture> mFilteredRadiance;
  131. SPtr<Texture> mIrradiance;
  132. };
  133. }
  134. /** @} */
  135. }