BsLightRendering.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 "BsRendererMaterial.h"
  6. #include "BsParamBlocks.h"
  7. namespace bs { namespace ct
  8. {
  9. /** @addtogroup RenderBeast
  10. * @{
  11. */
  12. /** Information about a single light, as seen by the lighting shader. */
  13. struct LightData
  14. {
  15. Vector3 position;
  16. float radius;
  17. Vector3 direction;
  18. float intensity;
  19. Vector3 spotAngles;
  20. float radiusSqrdInv;
  21. Vector3 color;
  22. };
  23. /** Renderer information specific to a single light. */
  24. class RendererLight
  25. {
  26. public:
  27. RendererLight(Light* light);
  28. /** Populates the structure with light parameters. */
  29. void getParameters(LightData& output) const;
  30. /** Gets the internal light representation. */
  31. Light* getInternal() const { return mInternal; }
  32. private:
  33. Light* mInternal;
  34. };
  35. /** Contains GPU buffers used by the renderer to manipulate lights. */
  36. class GPULightData
  37. {
  38. public:
  39. GPULightData();
  40. /** Updates the internal buffers with a new set of lights. */
  41. void setLights(const Vector<LightData>& lightData, UINT32 numDirLights, UINT32 numRadialLights,
  42. UINT32 numSpotLights);
  43. /** Returns a GPU bindable buffer containing information about every light. */
  44. SPtr<GpuBuffer> getLightBuffer() const { return mLightBuffer; }
  45. /** Returns a GPU bindable param buffer containing meta-data about light in the ligth buffer. */
  46. SPtr<GpuParamBlockBuffer> getParamBuffer() const { return mParamBuffer; }
  47. private:
  48. SPtr<GpuParamBlockBuffer> mParamBuffer;
  49. SPtr<GpuBuffer> mLightBuffer;
  50. };
  51. BS_PARAM_BLOCK_BEGIN(TiledLightingParamDef)
  52. BS_PARAM_BLOCK_ENTRY(Vector3I, gLightOffsets)
  53. BS_PARAM_BLOCK_END
  54. extern TiledLightingParamDef gTiledLightingParamDef;
  55. /** Shader that performs a lighting pass over data stored in the Gbuffer. */
  56. class TiledDeferredLightingMat : public RendererMaterial<TiledDeferredLightingMat>
  57. {
  58. RMAT_DEF("TiledDeferredLighting.bsl");
  59. public:
  60. TiledDeferredLightingMat();
  61. /** Binds the material for rendering, sets up parameters and executes it. */
  62. void execute(const SPtr<RenderTargets>& gbuffer, const SPtr<GpuParamBlockBuffer>& perCamera);
  63. /** Binds all the active lights. */
  64. void setLights(const GPULightData& lightData);
  65. private:
  66. GpuParamTexture mGBufferA;
  67. GpuParamTexture mGBufferB;
  68. GpuParamTexture mGBufferDepth;
  69. GpuParamBuffer mLightBufferParam;
  70. GpuParamLoadStoreTexture mOutputParam;
  71. static const UINT32 TILE_SIZE;
  72. };
  73. /** @} */
  74. }}