BsLightRendering.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. BS_PARAM_BLOCK_BEGIN(TiledLightingParamDef)
  36. BS_PARAM_BLOCK_ENTRY(Vector3I, gLightOffsets)
  37. BS_PARAM_BLOCK_END
  38. extern TiledLightingParamDef gTiledLightingParamDef;
  39. /** Shader that performs a lighting pass over data stored in the Gbuffer. */
  40. class TiledDeferredLightingMat : public RendererMaterial<TiledDeferredLightingMat>
  41. {
  42. RMAT_DEF("TiledDeferredLighting.bsl");
  43. public:
  44. TiledDeferredLightingMat();
  45. /** Binds the material for rendering, sets up parameters and executes it. */
  46. void execute(const SPtr<RenderTargets>& gbuffer, const SPtr<GpuParamBlockBuffer>& perCamera);
  47. /** Binds all the active lights. */
  48. void setLights(const Vector<LightData>& lightData, UINT32 numDirLights, UINT32 numRadialLights,
  49. UINT32 numSpotLights);
  50. private:
  51. GpuParamTexture mGBufferA;
  52. GpuParamTexture mGBufferB;
  53. GpuParamTexture mGBufferDepth;
  54. GpuParamBuffer mLightBufferParam;
  55. GpuParamLoadStoreTexture mOutputParam;
  56. SPtr<GpuParamBlockBuffer> mParamBuffer;
  57. SPtr<GpuBuffer> mLightBuffer;
  58. static const UINT32 TILE_SIZE;
  59. };
  60. /** @} */
  61. }}