BsRenderBeast.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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::notifyLightProbeVolumeAdded */
  87. void notifyLightProbeVolumeAdded(LightProbeVolume* volume) override;
  88. /** @copydoc Renderer::notifyLightProbeVolumeUpdated */
  89. void notifyLightProbeVolumeUpdated(LightProbeVolume* volume) override;
  90. /** @copydoc Renderer::notifyLightProbeVolumeRemoved */
  91. void notifyLightProbeVolumeRemoved(LightProbeVolume* volume) override;
  92. /** @copydoc Renderer::notifySkyboxAdded */
  93. void notifySkyboxAdded(Skybox* skybox) override;
  94. /** @copydoc Renderer::notifySkyboxTextureChanged */
  95. void notifySkyboxTextureChanged(Skybox* skybox) override;
  96. /** @copydoc Renderer::notifySkyboxRemoved */
  97. void notifySkyboxRemoved(Skybox* skybox) override;
  98. /**
  99. * Updates the render options on the core thread.
  100. *
  101. * @note Core thread only.
  102. */
  103. void syncOptions(const RenderBeastOptions& options);
  104. /**
  105. * Performs rendering over all camera proxies.
  106. *
  107. * @param[in] time Current frame time in milliseconds.
  108. * @param[in] delta Time elapsed since the last frame.
  109. *
  110. * @note Core thread only.
  111. */
  112. void renderAllCore(float time, float delta);
  113. /**
  114. * Renders all views in the provided view group.
  115. *
  116. * @note Core thread only.
  117. */
  118. void renderViews(const RendererViewGroup& viewGroup, const FrameInfo& frameInfo);
  119. /**
  120. * Renders all objects visible by the provided view.
  121. *
  122. * @note Core thread only.
  123. */
  124. void renderView(RendererView* viewInfo, float frameDelta);
  125. /**
  126. * Renders all overlay callbacks of the provided view.
  127. *
  128. * @note Core thread only.
  129. */
  130. void renderOverlay(RendererView* viewInfo);
  131. /**
  132. * Renders a single element of a renderable object.
  133. *
  134. * @param[in] element Element to render.
  135. * @param[in] passIdx Index of the material pass to render the element with.
  136. * @param[in] bindPass If true the material pass will be bound for rendering, if false it is assumed it is
  137. * already bound.
  138. * @param[in] viewProj View projection matrix of the camera the element is being rendered with.
  139. */
  140. void renderElement(const BeastRenderableElement& element, UINT32 passIdx, bool bindPass, const Matrix4& viewProj);
  141. /**
  142. * Captures the scene at the specified location into a cubemap.
  143. *
  144. * @param[in] cubemap Cubemap to store the results in.
  145. * @param[in] position Position to capture the scene at.
  146. * @param[in] hdr If true scene will be captured in a format that supports high dynamic range.
  147. * @param[in] frameInfo Global information about the the frame currently being rendered.
  148. */
  149. void captureSceneCubeMap(const SPtr<Texture>& cubemap, const Vector3& position, bool hdr, const FrameInfo& frameInfo);
  150. /** Creates data used by the renderer on the core thread. */
  151. void initializeCore();
  152. /** Destroys data used by the renderer on the core thread. */
  153. void destroyCore();
  154. /** Updates light probes, rendering & filtering ones that are dirty and updating the global probe cubemap array. */
  155. void updateLightProbes(const FrameInfo& frameInfo);
  156. // Core thread only fields
  157. // Scene data
  158. SPtr<RendererScene> mScene;
  159. //// Reflection probes
  160. Vector<bool> mCubemapArrayUsedSlots;
  161. SPtr<Texture> mReflCubemapArrayTex;
  162. //// Sky light
  163. Skybox* mSkybox = nullptr;
  164. SPtr<Texture> mSkyboxTexture;
  165. SPtr<Texture> mSkyboxFilteredReflections;
  166. SPtr<Texture> mSkyboxIrradiance;
  167. // Materials & GPU data
  168. //// Base pass
  169. ObjectRenderer* mObjectRenderer = nullptr;
  170. //// Lighting
  171. TiledDeferredLightingMaterials* mTiledDeferredLightingMats = nullptr;
  172. LightGrid* mLightGrid = nullptr;
  173. VisibleLightData* mVisibleLightInfo = nullptr;
  174. //// Image based lighting
  175. TiledDeferredImageBasedLightingMaterials* mTileDeferredImageBasedLightingMats = nullptr;
  176. VisibleReflProbeData* mVisibleReflProbeInfo = nullptr;
  177. SPtr<Texture> mPreintegratedEnvBRDF;
  178. //// Sky
  179. SkyboxMat<false>* mSkyboxMat;
  180. SkyboxMat<true>* mSkyboxSolidColorMat;
  181. //// Other
  182. FlatFramebufferToTextureMat* mFlatFramebufferToTextureMat = nullptr;
  183. SPtr<RenderBeastOptions> mCoreOptions;
  184. // Helpers to avoid memory allocations
  185. RendererViewGroup mMainViewGroup;
  186. // Sim thread only fields
  187. SPtr<RenderBeastOptions> mOptions;
  188. bool mOptionsDirty = true;
  189. };
  190. /** @} */
  191. }}