BsRenderBeast.h 7.6 KB

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