BsRenderBeast.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsRenderBeastPrerequisites.h"
  5. #include "BsRenderer.h"
  6. #include "BsRendererMaterial.h"
  7. #include "BsLightRendering.h"
  8. #include "BsImageBasedLighting.h"
  9. #include "BsObjectRendering.h"
  10. #include "BsPostProcessing.h"
  11. #include "BsRendererView.h"
  12. #include "BsRendererObject.h"
  13. #include "BsRendererScene.h"
  14. namespace bs
  15. {
  16. struct RendererAnimationData;
  17. namespace ct
  18. {
  19. class LightGrid;
  20. /** @addtogroup RenderBeast
  21. * @{
  22. */
  23. /** Contains information global to an entire frame. */
  24. struct FrameInfo
  25. {
  26. FrameInfo(float timeDelta, const RendererAnimationData& animData)
  27. :timeDelta(timeDelta), animData(animData)
  28. { }
  29. float timeDelta;
  30. const RendererAnimationData& animData;
  31. };
  32. /**
  33. * Default renderer for Banshee. Performs frustum culling, sorting and renders all scene objects while applying
  34. * lighting, shadowing, special effects and post-processing.
  35. */
  36. class RenderBeast : public Renderer
  37. {
  38. /** Renderer information for a single material. */
  39. struct RendererMaterial
  40. {
  41. Vector<SPtr<GpuParamsSet>> params;
  42. UINT32 matVersion;
  43. };
  44. public:
  45. RenderBeast();
  46. ~RenderBeast() { }
  47. /** @copydoc Renderer::getName */
  48. const StringID& getName() const override;
  49. /** @copydoc Renderer::renderAll */
  50. void renderAll() override;
  51. /** Sets options used for controlling the rendering. */
  52. void setOptions(const SPtr<RendererOptions>& options) override;
  53. /** Returns current set of options used for controlling the rendering. */
  54. SPtr<RendererOptions> getOptions() const override;
  55. /** @copydoc Renderer::initialize */
  56. void initialize() override;
  57. /** @copydoc Renderer::destroy */
  58. void destroy() override;
  59. /** @copydoc Renderer::createPostProcessSettings */
  60. SPtr<PostProcessSettings> createPostProcessSettings() const override;
  61. private:
  62. /** @copydoc Renderer::notifyCameraAdded */
  63. void notifyCameraAdded(Camera* camera) override;
  64. /** @copydoc Renderer::notifyCameraUpdated */
  65. void notifyCameraUpdated(Camera* camera, UINT32 updateFlag) override;
  66. /** @copydocRenderer::notifyCameraRemoved */
  67. void notifyCameraRemoved(Camera* camera) override;
  68. /** @copydoc Renderer::notifyLightAdded */
  69. void notifyLightAdded(Light* light) override;
  70. /** @copydoc Renderer::notifyLightUpdated */
  71. void notifyLightUpdated(Light* light) override;
  72. /** @copydoc Renderer::notifyLightRemoved */
  73. void notifyLightRemoved(Light* light) override;
  74. /** @copydoc Renderer::notifyRenderableAdded */
  75. void notifyRenderableAdded(Renderable* renderable) override;
  76. /** @copydoc Renderer::notifyRenderableUpdated */
  77. void notifyRenderableUpdated(Renderable* renderable) override;
  78. /** @copydoc Renderer::notifyRenderableRemoved */
  79. void notifyRenderableRemoved(Renderable* renderable) override;
  80. /** @copydoc Renderer::notifyReflectionProbeAdded */
  81. void notifyReflectionProbeAdded(ReflectionProbe* probe) override;
  82. /** @copydoc Renderer::notifyReflectionProbeUpdated */
  83. void notifyReflectionProbeUpdated(ReflectionProbe* probe) override;
  84. /** @copydoc Renderer::notifyReflectionProbeRemoved */
  85. void notifyReflectionProbeRemoved(ReflectionProbe* probe) override;
  86. /** @copydoc Renderer::notifySkyboxAdded */
  87. void notifySkyboxAdded(Skybox* skybox) override;
  88. /** @copydoc Renderer::notifySkyboxTextureChanged */
  89. void notifySkyboxTextureChanged(Skybox* skybox) override;
  90. /** @copydoc Renderer::notifySkyboxRemoved */
  91. void notifySkyboxRemoved(Skybox* skybox) override;
  92. /**
  93. * Updates the render options on the core thread.
  94. *
  95. * @note Core thread only.
  96. */
  97. void syncOptions(const RenderBeastOptions& options);
  98. /**
  99. * Performs rendering over all camera proxies.
  100. *
  101. * @param[in] time Current frame time in milliseconds.
  102. * @param[in] delta Time elapsed since the last frame.
  103. *
  104. * @note Core thread only.
  105. */
  106. void renderAllCore(float time, float delta);
  107. /**
  108. * Renders all views in the provided view group.
  109. *
  110. * @note Core thread only.
  111. */
  112. void renderViews(const RendererViewGroup& viewGroup, const FrameInfo& frameInfo);
  113. /**
  114. * Renders all objects visible by the provided view.
  115. *
  116. * @note Core thread only.
  117. */
  118. void renderView(RendererView* viewInfo, float frameDelta);
  119. /**
  120. * Renders all overlay callbacks of the provided view.
  121. *
  122. * @note Core thread only.
  123. */
  124. void renderOverlay(RendererView* viewInfo);
  125. /**
  126. * Renders a single element of a renderable object.
  127. *
  128. * @param[in] element Element to render.
  129. * @param[in] passIdx Index of the material pass to render the element with.
  130. * @param[in] bindPass If true the material pass will be bound for rendering, if false it is assumed it is
  131. * already bound.
  132. * @param[in] viewProj View projection matrix of the camera the element is being rendered with.
  133. */
  134. void renderElement(const BeastRenderableElement& element, UINT32 passIdx, bool bindPass, const Matrix4& viewProj);
  135. /**
  136. * Captures the scene at the specified location into a cubemap.
  137. *
  138. * @param[in] cubemap Cubemap to store the results in.
  139. * @param[in] position Position to capture the scene at.
  140. * @param[in] hdr If true scene will be captured in a format that supports high dynamic range.
  141. * @param[in] frameInfo Global information about the the frame currently being rendered.
  142. */
  143. void captureSceneCubeMap(const SPtr<Texture>& cubemap, const Vector3& position, bool hdr, const FrameInfo& frameInfo);
  144. /** Creates data used by the renderer on the core thread. */
  145. void initializeCore();
  146. /** Destroys data used by the renderer on the core thread. */
  147. void destroyCore();
  148. /** Updates light probes, rendering & filtering ones that are dirty and updating the global probe cubemap array. */
  149. void updateLightProbes(const FrameInfo& frameInfo);
  150. // Core thread only fields
  151. // Scene data
  152. SPtr<RendererScene> mScene;
  153. //// Reflection probes
  154. Vector<bool> mCubemapArrayUsedSlots;
  155. SPtr<Texture> mReflCubemapArrayTex;
  156. //// Sky light
  157. Skybox* mSkybox = nullptr;
  158. SPtr<Texture> mSkyboxTexture;
  159. SPtr<Texture> mSkyboxFilteredReflections;
  160. SPtr<Texture> mSkyboxIrradiance;
  161. // Materials & GPU data
  162. //// Base pass
  163. ObjectRenderer* mObjectRenderer = nullptr;
  164. //// Lighting
  165. TiledDeferredLightingMaterials* mTiledDeferredLightingMats = nullptr;
  166. LightGrid* mLightGrid = nullptr;
  167. VisibleLightData* mVisibleLightInfo = nullptr;
  168. //// Image based lighting
  169. TiledDeferredImageBasedLightingMaterials* mTileDeferredImageBasedLightingMats = nullptr;
  170. VisibleReflProbeData* mVisibleReflProbeInfo = nullptr;
  171. SPtr<Texture> mPreintegratedEnvBRDF;
  172. //// Sky
  173. SkyboxMat<false>* mSkyboxMat;
  174. SkyboxMat<true>* mSkyboxSolidColorMat;
  175. //// Other
  176. FlatFramebufferToTextureMat* mFlatFramebufferToTextureMat = nullptr;
  177. SPtr<RenderBeastOptions> mCoreOptions;
  178. // Helpers to avoid memory allocations
  179. RendererViewGroup mMainViewGroup;
  180. // Sim thread only fields
  181. SPtr<RenderBeastOptions> mOptions;
  182. bool mOptionsDirty = true;
  183. };
  184. /** @} */
  185. }}