BsRenderBeast.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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 "BsBounds.h"
  7. #include "BsSamplerOverrides.h"
  8. #include "BsRendererMaterial.h"
  9. #include "BsLightRendering.h"
  10. #include "BsObjectRendering.h"
  11. #include "BsPostProcessing.h"
  12. #include "BsRendererCamera.h"
  13. #include "BsRendererObject.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 specific to a single render target. */
  38. struct RendererRenderTarget
  39. {
  40. SPtr<RenderTarget> target;
  41. Vector<const Camera*> cameras;
  42. };
  43. /** Renderer information for a single material. */
  44. struct RendererMaterial
  45. {
  46. Vector<SPtr<GpuParamsSet>> params;
  47. UINT32 matVersion;
  48. };
  49. /** Contains information global to an entire frame. */
  50. struct FrameInfo
  51. {
  52. FrameInfo(float timeDelta, const RendererAnimationData& animData)
  53. :timeDelta(timeDelta), animData(animData)
  54. { }
  55. float timeDelta;
  56. const RendererAnimationData& animData;
  57. };
  58. public:
  59. RenderBeast();
  60. ~RenderBeast() { }
  61. /** @copydoc Renderer::getName */
  62. const StringID& getName() const override;
  63. /** @copydoc Renderer::renderAll */
  64. void renderAll() override;
  65. /** Sets options used for controlling the rendering. */
  66. void setOptions(const SPtr<RendererOptions>& options) override;
  67. /** Returns current set of options used for controlling the rendering. */
  68. SPtr<RendererOptions> getOptions() const override;
  69. /** @copydoc Renderer::initialize */
  70. void initialize() override;
  71. /** @copydoc Renderer::destroy */
  72. void destroy() override;
  73. /** @copydoc Renderer::createPostProcessSettings */
  74. SPtr<PostProcessSettings> createPostProcessSettings() const override;
  75. private:
  76. /** @copydoc Renderer::notifyCameraAdded */
  77. void notifyCameraAdded(const Camera* camera) override;
  78. /** @copydoc Renderer::notifyCameraUpdated */
  79. void notifyCameraUpdated(const Camera* camera, UINT32 updateFlag) override;
  80. /** @copydocRenderer::notifyCameraRemoved */
  81. void notifyCameraRemoved(const Camera* camera) override;
  82. /** @copydoc Renderer::notifyLightAdded */
  83. void notifyLightAdded(Light* light) override;
  84. /** @copydoc Renderer::notifyLightUpdated */
  85. void notifyLightUpdated(Light* light) override;
  86. /** @copydoc Renderer::notifyLightRemoved */
  87. void notifyLightRemoved(Light* light) override;
  88. /** @copydoc Renderer::notifyRenderableAdded */
  89. void notifyRenderableAdded(Renderable* renderable) override;
  90. /** @copydoc Renderer::notifyRenderableUpdated */
  91. void notifyRenderableUpdated(Renderable* renderable) override;
  92. /** @copydoc Renderer::notifyRenderableRemoved */
  93. void notifyRenderableRemoved(Renderable* renderable) override;
  94. /**
  95. * Updates (or adds) renderer specific data for the specified camera. Should be called whenever camera properties
  96. * change.
  97. *
  98. * @param[in] camera Camera whose data to update.
  99. * @param[in] forceRemove If true, the camera data will be removed instead of updated.
  100. * @return Renderer camera object that represents the camera. Null if camera was removed.
  101. */
  102. RendererCamera* updateCameraData(const Camera* camera, bool forceRemove = false);
  103. /**
  104. * Updates the render options on the core thread.
  105. *
  106. * @note Core thread only.
  107. */
  108. void syncOptions(const RenderBeastOptions& options);
  109. /**
  110. * Performs rendering over all camera proxies.
  111. *
  112. * @param[in] time Current frame time in milliseconds.
  113. * @param[in] delta Time elapsed since the last frame.
  114. *
  115. * @note Core thread only.
  116. */
  117. void renderAllCore(float time, float delta);
  118. /**
  119. * Renders all provided views.
  120. *
  121. * @note Core thread only.
  122. */
  123. void renderViews(RendererCamera** views, UINT32 numViews, const FrameInfo& frameInfo);
  124. /**
  125. * Renders all objects visible by the provided view.
  126. *
  127. * @note Core thread only.
  128. */
  129. void renderView(RendererCamera* viewInfo, float frameDelta);
  130. /**
  131. * Renders all overlay callbacks of the provided view.
  132. *
  133. * @note Core thread only.
  134. */
  135. void renderOverlay(RendererCamera* viewInfo);
  136. /**
  137. * Renders a single element of a renderable object.
  138. *
  139. * @param[in] element Element to render.
  140. * @param[in] passIdx Index of the material pass to render the element with.
  141. * @param[in] bindPass If true the material pass will be bound for rendering, if false it is assumed it is
  142. * already bound.
  143. * @param[in] viewProj View projection matrix of the camera the element is being rendered with.
  144. */
  145. void renderElement(const BeastRenderableElement& element, UINT32 passIdx, bool bindPass, const Matrix4& viewProj);
  146. /**
  147. * Captures the scene at the specified location into a cubemap.
  148. *
  149. * @param[in] position Position to capture the scene at.
  150. * @param[in] hdr If true scene will be captured in a format that supports high dynamic range.
  151. * @param[in] size Cubemap face width/height in pixels.
  152. * @param[in] frameInfo Global information about the the frame currently being rendered.
  153. */
  154. SPtr<Texture> captureSceneCubeMap(const Vector3& position, bool hdr, UINT32 size, const FrameInfo& frameInfo);
  155. /** Creates data used by the renderer on the core thread. */
  156. void initializeCore();
  157. /** Destroys data used by the renderer on the core thread. */
  158. void destroyCore();
  159. /**
  160. * Checks all sampler overrides in case material sampler states changed, and updates them.
  161. *
  162. * @param[in] force If true, all sampler overrides will be updated, regardless of a change in the material
  163. * was detected or not.
  164. */
  165. void refreshSamplerOverrides(bool force = false);
  166. // Core thread only fields
  167. Vector<RendererRenderTarget> mRenderTargets;
  168. UnorderedMap<const Camera*, RendererCamera*> mCameras;
  169. UnorderedMap<SamplerOverrideKey, MaterialSamplerOverrides*> mSamplerOverrides;
  170. Vector<RendererObject*> mRenderables;
  171. Vector<CullInfo> mRenderableCullInfos;
  172. Vector<bool> mRenderableVisibility; // Transient
  173. Vector<RendererLight> mDirectionalLights;
  174. Vector<RendererLight> mRadialLights;
  175. Vector<RendererLight> mSpotLights;
  176. Vector<Sphere> mPointLightWorldBounds;
  177. Vector<Sphere> mSpotLightWorldBounds;
  178. SPtr<RenderBeastOptions> mCoreOptions;
  179. DefaultMaterial* mDefaultMaterial;
  180. ITiledDeferredLightingMat* mTiledDeferredLightingMats[4];
  181. FlatFramebufferToTextureMat* mFlatFramebufferToTextureMat;
  182. SkyboxMat<false>* mSkyboxMat;
  183. SkyboxMat<true>* mSkyboxSolidColorMat;
  184. GPULightData* mGPULightData;
  185. LightGrid* mLightGrid;
  186. ObjectRenderer* mObjectRenderer;
  187. // Sim thread only fields
  188. SPtr<RenderBeastOptions> mOptions;
  189. bool mOptionsDirty;
  190. // Helpers to avoid memory allocations
  191. Vector<LightData> mLightDataTemp;
  192. Vector<bool> mLightVisibilityTemp;
  193. };
  194. /** @} */
  195. }}