BsRendererScene.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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, bool texture);
  84. /** Removes a reflection probe from the scene. */
  85. void unregisterReflectionProbe(ReflectionProbe* probe);
  86. /** Updates the index at which the reflection probe's texture is stored at, in the global array. */
  87. void setReflectionProbeArrayIndex(UINT32 probeIdx, UINT32 arrayIdx, bool markAsClean);
  88. /** Registers a new sky texture in the scene. */
  89. void registerSkybox(Skybox* skybox);
  90. /** Updates information about the previously registered skybox. */
  91. void updateSkybox(Skybox* skybox);
  92. /** Removes a skybox from the scene. */
  93. void unregisterSkybox(Skybox* skybox);
  94. /** Returns a container with all relevant scene objects. */
  95. const SceneInfo& getSceneInfo() const { return mInfo; }
  96. /** Updates scene according to the newly provided renderer options. */
  97. void setOptions(const SPtr<RenderBeastOptions>& options);
  98. /**
  99. * Checks all sampler overrides in case material sampler states changed, and updates them.
  100. *
  101. * @param[in] force If true, all sampler overrides will be updated, regardless of a change in the material
  102. * was detected or not.
  103. */
  104. void refreshSamplerOverrides(bool force = false);
  105. /**
  106. * Performs necessary steps to make a renderable ready for rendering. This must be called at least once every frame,
  107. * for every renderable that will be drawn. Multiple calls for the same renderable during a single frame will result
  108. * in a no-op.
  109. *
  110. * @param[in] idx Index of the renderable to prepare.
  111. * @param[in] frameInfo Global information describing the current frame.
  112. */
  113. void prepareRenderable(UINT32 idx, const FrameInfo& frameInfo);
  114. /** Returns a modifiable version of SceneInfo. Only to be used by friends who know what they are doing. */
  115. SceneInfo& _getSceneInfo() { return mInfo; }
  116. private:
  117. /** Creates a renderer view descriptor for the particular camera. */
  118. RENDERER_VIEW_DESC createViewDesc(Camera* camera) const;
  119. /**
  120. * Find the render target the camera belongs to and adds it to the relevant list. If the camera was previously
  121. * registered with some other render target it will be removed from it and added to the new target.
  122. */
  123. void updateCameraRenderTargets(Camera* camera, bool remove = false);
  124. SceneInfo mInfo;
  125. UnorderedMap<SamplerOverrideKey, MaterialSamplerOverrides*> mSamplerOverrides;
  126. SPtr<RenderBeastOptions> mOptions;
  127. };
  128. /** @} */
  129. }}