BsRendererScene.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 "BsObjectRendering.h"
  6. #include "BsSamplerOverrides.h"
  7. #include "BsLightRendering.h"
  8. #include "BsRendererView.h"
  9. #include "BsLight.h"
  10. namespace bs
  11. {
  12. struct RendererAnimationData;
  13. namespace ct
  14. {
  15. struct FrameInfo;
  16. /** @addtogroup RenderBeast
  17. * @{
  18. */
  19. // Limited by max number of array elements in texture for DX11 hardware
  20. constexpr UINT32 MaxReflectionCubemaps = 2048 / 6;
  21. /** Contains information about the skybox in the current scene. */
  22. struct SkyInfo
  23. {
  24. Skybox* skybox = nullptr;
  25. SPtr<Texture> radiance;
  26. SPtr<Texture> filteredReflections;
  27. SPtr<Texture> irradiance;
  28. };
  29. /** Contains most scene objects relevant to the renderer. */
  30. struct SceneInfo
  31. {
  32. // Cameras and render targets
  33. Vector<RendererRenderTarget> renderTargets;
  34. Vector<RendererView*> views;
  35. UnorderedMap<const Camera*, UINT32> cameraToView;
  36. // Renderables
  37. Vector<RendererObject*> renderables;
  38. Vector<CullInfo> renderableCullInfos;
  39. // Lights
  40. Vector<RendererLight> directionalLights;
  41. Vector<RendererLight> radialLights;
  42. Vector<RendererLight> spotLights;
  43. Vector<Sphere> radialLightWorldBounds;
  44. Vector<Sphere> spotLightWorldBounds;
  45. // Reflection probes
  46. Vector<RendererReflectionProbe> reflProbes;
  47. Vector<Sphere> reflProbeWorldBounds;
  48. Vector<bool> reflProbeCubemapArrayUsedSlots;
  49. SPtr<Texture> reflProbeCubemapsTex;
  50. // Sky
  51. SkyInfo sky;
  52. // Buffers for various transient data that gets rebuilt every frame
  53. //// Rebuilt every frame
  54. mutable Vector<bool> renderableReady;
  55. };
  56. /** Contains information about the scene (e.g. renderables, lights, cameras) required by the renderer. */
  57. class RendererScene
  58. {
  59. public:
  60. RendererScene(const SPtr<RenderBeastOptions>& options);
  61. ~RendererScene();
  62. /** Registers a new camera in the scene. */
  63. void registerCamera(Camera* camera);
  64. /** Updates information about a previously registered camera. */
  65. void updateCamera(Camera* camera, UINT32 updateFlag);
  66. /** Removes a camera from the scene. */
  67. void unregisterCamera(Camera* camera);
  68. /** Registers a new light in the scene. */
  69. void registerLight(Light* light);
  70. /** Updates information about a previously registered light. */
  71. void updateLight(Light* light);
  72. /** Removes a light from the scene. */
  73. void unregisterLight(Light* light);
  74. /** Registers a new renderable object in the scene. */
  75. void registerRenderable(Renderable* renderable);
  76. /** Updates information about a previously registered renderable object. */
  77. void updateRenderable(Renderable* renderable);
  78. /** Removes a renderable object from the scene. */
  79. void unregisterRenderable(Renderable* renderable);
  80. /** Registers a new reflection probe in the scene. */
  81. void registerReflectionProbe(ReflectionProbe* probe);
  82. /** Updates information about a previously registered reflection probe. */
  83. void updateReflectionProbe(ReflectionProbe* probe);
  84. /** Removes a reflection probe from the scene. */
  85. void unregisterReflectionProbe(ReflectionProbe* probe);
  86. /** Updates or replaces the filtered reflection texture of the probe at the specified index. */
  87. void setReflectionProbeTexture(UINT32 probeIdx, const SPtr<Texture>& texture);
  88. /** Updates the index at which the reflection probe's texture is stored at, in the global array. */
  89. void setReflectionProbeArrayIndex(UINT32 probeIdx, UINT32 arrayIdx, bool markAsClean);
  90. /** Registers a new sky texture in the scene. */
  91. void registerSkybox(Skybox* skybox);
  92. /** Updates information about the previously registered skybox. */
  93. void updateSkybox(Skybox* skybox);
  94. /** Removes a skybox from the scene. */
  95. void unregisterSkybox(Skybox* skybox);
  96. /** Returns a container with all relevant scene objects. */
  97. const SceneInfo& getSceneInfo() const { return mInfo; }
  98. /** Updates scene according to the newly provided renderer options. */
  99. void setOptions(const SPtr<RenderBeastOptions>& options);
  100. /**
  101. * Checks all sampler overrides in case material sampler states changed, and updates them.
  102. *
  103. * @param[in] force If true, all sampler overrides will be updated, regardless of a change in the material
  104. * was detected or not.
  105. */
  106. void refreshSamplerOverrides(bool force = false);
  107. /**
  108. * Performs necessary steps to make a renderable ready for rendering. This must be called at least once every frame,
  109. * for every renderable that will be drawn. Multiple calls for the same renderable during a single frame will result
  110. * in a no-op.
  111. *
  112. * @param[in] idx Index of the renderable to prepare.
  113. * @param[in] frameInfo Global information describing the current frame.
  114. */
  115. void prepareRenderable(UINT32 idx, const FrameInfo& frameInfo);
  116. /** Returns a modifiable version of SceneInfo. Only to be used by friends who know what they are doing. */
  117. SceneInfo& _getSceneInfo() { return mInfo; }
  118. private:
  119. /** Creates a renderer view descriptor for the particular camera. */
  120. RENDERER_VIEW_DESC createViewDesc(Camera* camera) const;
  121. /**
  122. * Find the render target the camera belongs to and adds it to the relevant list. If the camera was previously
  123. * registered with some other render target it will be removed from it and added to the new target.
  124. */
  125. void updateCameraRenderTargets(Camera* camera, bool remove = false);
  126. SceneInfo mInfo;
  127. UnorderedMap<SamplerOverrideKey, MaterialSamplerOverrides*> mSamplerOverrides;
  128. SPtr<RenderBeastOptions> mOptions;
  129. };
  130. /** @} */
  131. }}