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. /**
  62. * Captures the scene at the specified location into a cubemap.
  63. *
  64. * @param[in] cubemap Cubemap to store the results in.
  65. * @param[in] position Position to capture the scene at.
  66. * @param[in] hdr If true scene will be captured in a format that supports high dynamic range.
  67. * @param[in] frameInfo Global information about the the frame currently being rendered.
  68. */
  69. void captureSceneCubeMap(const SPtr<Texture>& cubemap, const Vector3& position, bool hdr, const FrameInfo& frameInfo);
  70. private:
  71. /** @copydoc Renderer::notifyCameraAdded */
  72. void notifyCameraAdded(Camera* camera) override;
  73. /** @copydoc Renderer::notifyCameraUpdated */
  74. void notifyCameraUpdated(Camera* camera, UINT32 updateFlag) override;
  75. /** @copydocRenderer::notifyCameraRemoved */
  76. void notifyCameraRemoved(Camera* camera) override;
  77. /** @copydoc Renderer::notifyLightAdded */
  78. void notifyLightAdded(Light* light) override;
  79. /** @copydoc Renderer::notifyLightUpdated */
  80. void notifyLightUpdated(Light* light) override;
  81. /** @copydoc Renderer::notifyLightRemoved */
  82. void notifyLightRemoved(Light* light) override;
  83. /** @copydoc Renderer::notifyRenderableAdded */
  84. void notifyRenderableAdded(Renderable* renderable) override;
  85. /** @copydoc Renderer::notifyRenderableUpdated */
  86. void notifyRenderableUpdated(Renderable* renderable) override;
  87. /** @copydoc Renderer::notifyRenderableRemoved */
  88. void notifyRenderableRemoved(Renderable* renderable) override;
  89. /** @copydoc Renderer::notifyReflectionProbeAdded */
  90. void notifyReflectionProbeAdded(ReflectionProbe* probe) override;
  91. /** @copydoc Renderer::notifyReflectionProbeUpdated */
  92. void notifyReflectionProbeUpdated(ReflectionProbe* probe) override;
  93. /** @copydoc Renderer::notifyReflectionProbeRemoved */
  94. void notifyReflectionProbeRemoved(ReflectionProbe* probe) override;
  95. /** @copydoc Renderer::notifyLightProbeVolumeAdded */
  96. void notifyLightProbeVolumeAdded(LightProbeVolume* volume) override;
  97. /** @copydoc Renderer::notifyLightProbeVolumeUpdated */
  98. void notifyLightProbeVolumeUpdated(LightProbeVolume* volume) override;
  99. /** @copydoc Renderer::notifyLightProbeVolumeRemoved */
  100. void notifyLightProbeVolumeRemoved(LightProbeVolume* volume) override;
  101. /** @copydoc Renderer::notifySkyboxAdded */
  102. void notifySkyboxAdded(Skybox* skybox) override;
  103. /** @copydoc Renderer::notifySkyboxTextureChanged */
  104. void notifySkyboxTextureChanged(Skybox* skybox) override;
  105. /** @copydoc Renderer::notifySkyboxRemoved */
  106. void notifySkyboxRemoved(Skybox* skybox) override;
  107. /**
  108. * Updates the render options on the core thread.
  109. *
  110. * @note Core thread only.
  111. */
  112. void syncOptions(const RenderBeastOptions& options);
  113. /**
  114. * Performs rendering over all camera proxies.
  115. *
  116. * @param[in] time Current frame time in milliseconds.
  117. * @param[in] delta Time elapsed since the last frame.
  118. *
  119. * @note Core thread only.
  120. */
  121. void renderAllCore(float time, float delta);
  122. /**
  123. * Renders all views in the provided view group.
  124. *
  125. * @note Core thread only.
  126. */
  127. void renderViews(const RendererViewGroup& viewGroup, const FrameInfo& frameInfo);
  128. /**
  129. * Renders all objects visible by the provided view.
  130. *
  131. * @note Core thread only.
  132. */
  133. void renderView(RendererView* viewInfo, float frameDelta);
  134. /**
  135. * Renders all overlay callbacks of the provided view.
  136. *
  137. * @note Core thread only.
  138. */
  139. void renderOverlay(RendererView* viewInfo);
  140. /**
  141. * Renders a single element of a renderable object.
  142. *
  143. * @param[in] element Element to render.
  144. * @param[in] passIdx Index of the material pass to render the element with.
  145. * @param[in] bindPass If true the material pass will be bound for rendering, if false it is assumed it is
  146. * already bound.
  147. * @param[in] viewProj View projection matrix of the camera the element is being rendered with.
  148. */
  149. void renderElement(const BeastRenderableElement& element, UINT32 passIdx, bool bindPass, const Matrix4& viewProj);
  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. }}