BsRenderBeast.h 7.6 KB

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