BsRendererCamera.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 "BsPostProcessing.h"
  6. #include "BsObjectRendering.h"
  7. #include "BsRenderQueue.h"
  8. #include "BsRendererObject.h"
  9. #include "BsBounds.h"
  10. namespace bs
  11. {
  12. /** @addtogroup RenderBeast
  13. * @{
  14. */
  15. BS_PARAM_BLOCK_BEGIN(PerCameraParamBuffer)
  16. BS_PARAM_BLOCK_ENTRY(Vector3, gViewDir)
  17. BS_PARAM_BLOCK_ENTRY(Vector3, gViewOrigin)
  18. BS_PARAM_BLOCK_ENTRY(Matrix4, gMatViewProj)
  19. BS_PARAM_BLOCK_ENTRY(Matrix4, gMatView)
  20. BS_PARAM_BLOCK_ENTRY(Matrix4, gMatProj)
  21. BS_PARAM_BLOCK_ENTRY(Matrix4, gMatInvProj)
  22. BS_PARAM_BLOCK_ENTRY(Matrix4, gMatInvViewProj)
  23. BS_PARAM_BLOCK_ENTRY(Matrix4, gMatScreenToWorld)
  24. BS_PARAM_BLOCK_ENTRY(Vector2, gDeviceZToWorldZ)
  25. BS_PARAM_BLOCK_ENTRY(Vector4, gClipToUVScaleOffset)
  26. BS_PARAM_BLOCK_END
  27. /** Contains information about a Camera, used by the Renderer. */
  28. class RendererCamera
  29. {
  30. public:
  31. RendererCamera();
  32. RendererCamera(const CameraCore* camera, StateReduction reductionMode);
  33. /** Updates the internal camera data, usually called after source camera changes. */
  34. void update(StateReduction reductionMode);
  35. /** Updates the internal camera post-processing data. */
  36. void updatePP();
  37. /**
  38. * Prepares camera render targets for rendering. When done call endRendering().
  39. *
  40. * @param[in] useRenderTargets If using the internal render targets containing the GBuffer (retrieved via
  41. * getRenderTargets()) while rendering you must set this to true.
  42. */
  43. void beginRendering(bool useRenderTargets);
  44. /** Ends rendering and frees any acquired resources. */
  45. void endRendering();
  46. /** Returns the camera's renderTargets. Only valid if called in-between beginRendering() and endRendering() calls. */
  47. SPtr<RenderTargets> getRenderTargets() const { return mRenderTargets; }
  48. /**
  49. * Returns a render queue containing all opaque objects. Make sure to call determineVisible() beforehand if camera
  50. * or object transforms changed since the last time it was called.
  51. */
  52. const SPtr<RenderQueue>& getOpaqueQueue() const { return mOpaqueQueue; }
  53. /**
  54. * Returns a render queue containing all transparent objects. Make sure to call determineVisible() beforehand if
  55. * camera or object transforms changed since the last time it was called.
  56. */
  57. const SPtr<RenderQueue>& getTransparentQueue() const { return mTransparentQueue; }
  58. /**
  59. * Populates camera render queues by determining visible renderable objects.
  60. *
  61. * @param[in] renderables A set of renderable objects to iterate over and determine visibility for.
  62. * @param[in] renderableBounds A set of world bounds for the provided renderable objects. Must be the same size
  63. * as the @p renderables array.
  64. * @param[in] visibility Output parameter that will have the true bit set for any visible renderable
  65. * object. If the bit for an object is already set to true, the method will never
  66. * change it to false which allows the same bitfield to be provided to multiple
  67. * renderer cameras. Must be the same size as the @p renderables array.
  68. *
  69. * As a side-effect, per-camera visibility data is also calculated and can be
  70. * retrieved by calling getVisibilityMask().
  71. */
  72. void determineVisible(const Vector<RendererObject*>& renderables, const Vector<Bounds>& renderableBounds,
  73. Vector<bool>& visibility);
  74. /** Returns the visibility mask calculated with the last call to determineVisible(). */
  75. const Vector<bool> getVisibilityMask() const { return mVisibility; }
  76. /**
  77. * Returns a structure containing information about post-processing effects. This structure will be modified and
  78. * maintained by the post-processing system.
  79. */
  80. PostProcessInfo& getPPInfo() { return mPostProcessInfo; }
  81. /** Updates the GPU buffer containing per-camera information, with the latest data. */
  82. void updatePerCameraBuffer();
  83. /** Returns a buffer that stores per-camera parameters. */
  84. PerCameraParamBuffer& getPerCameraBuffer() { return mParams; }
  85. private:
  86. /**
  87. * Extracts the necessary values from the projection matrix that allow you to transform device Z value into
  88. * world Z value.
  89. *
  90. * @param[in] projMatrix Projection matrix that was used to create the device Z value to transform.
  91. * @return Returns two values that can be used to transform device z to world z using this formula:
  92. * z = (deviceZ + y) * x.
  93. */
  94. Vector2 getDeviceZTransform(const Matrix4& projMatrix) const;
  95. const CameraCore* mCamera;
  96. SPtr<RenderQueue> mOpaqueQueue;
  97. SPtr<RenderQueue> mTransparentQueue;
  98. SPtr<RenderTargets> mRenderTargets;
  99. PostProcessInfo mPostProcessInfo;
  100. bool mUsingRenderTargets;
  101. PerCameraParamBuffer mParams;
  102. Vector<bool> mVisibility;
  103. };
  104. /** @} */
  105. }