BsRenderBeast.h 8.0 KB

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