BsRendererScene.h 5.8 KB

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