BsRendererCamera.h 5.0 KB

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