BsLightRendering.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 BansheeEngine
  8. {
  9. /** @addtogroup RenderBeast
  10. * @{
  11. */
  12. BS_PARAM_BLOCK_BEGIN(PerLightParamBuffer)
  13. BS_PARAM_BLOCK_ENTRY(Vector4, gLightPositionAndType)
  14. BS_PARAM_BLOCK_ENTRY(Vector4, gLightColorAndIntensity)
  15. BS_PARAM_BLOCK_ENTRY(Vector4, gLightSpotAnglesAndSqrdInvRadius)
  16. BS_PARAM_BLOCK_ENTRY(Vector3, gLightDirection)
  17. BS_PARAM_BLOCK_ENTRY(Vector4, gLightGeometry)
  18. BS_PARAM_BLOCK_ENTRY(Matrix4, gMatConeTransform)
  19. BS_PARAM_BLOCK_END
  20. /** Manipulates PerLight parameter buffer used in various shaders. */
  21. class PerLightParams
  22. {
  23. public:
  24. /** Updates data in the parameter buffer from the data in the provided light. */
  25. void setParameters(const LightCore* light);
  26. /** Returns the internal parameter buffer that can be bound to the pipeline. */
  27. const SPtr<GpuParamBlockBufferCore>& getBuffer() const;
  28. private:
  29. PerLightParamBuffer mBuffer;
  30. };
  31. /** Shader that renders directional light sources during deferred rendering light pass. */
  32. class DirectionalLightMat : public RendererMaterial<DirectionalLightMat>
  33. {
  34. RMAT_DEF("DeferredDirectionalLightPass.bsl");
  35. public:
  36. DirectionalLightMat();
  37. /** Updates parameters that are common for all lights. */
  38. void setStaticParameters(const SPtr<RenderTargets>& gbuffer, const SPtr<GpuParamBlockBufferCore>& perCamera);
  39. /** Updates the parameter buffers used by the material. */
  40. void setParameters(const LightCore* light);
  41. private:
  42. PerLightParams mParams; // Note: Should this buffer be shared between both point and directional lights?
  43. MaterialParamTextureCore mGBufferA;
  44. MaterialParamTextureCore mGBufferB;
  45. MaterialParamTextureCore mGBufferDepth;
  46. };
  47. /**
  48. * Shader that renders point (radial & spot) light sources during deferred rendering light pass. Used when the camera
  49. * is inside the point light geometry.
  50. */
  51. class PointLightInMat : public RendererMaterial<PointLightInMat>
  52. {
  53. RMAT_DEF("DeferredPointLightPassIn.bsl");
  54. public:
  55. PointLightInMat();
  56. /** Updates parameters that are common for all lights. */
  57. void setStaticParameters(const SPtr<RenderTargets>& gbuffer, const SPtr<GpuParamBlockBufferCore>& perCamera);
  58. /** Updates the parameter buffers used by the material. */
  59. void setParameters(const LightCore* light);
  60. private:
  61. PerLightParams mParams; // Note: Should this buffer be shared between both point and directional lights?
  62. MaterialParamTextureCore mGBufferA;
  63. MaterialParamTextureCore mGBufferB;
  64. MaterialParamTextureCore mGBufferDepth;
  65. };
  66. /**
  67. * Shader that renders point (radial & spot) light sources during deferred rendering light pass. Used when the camera
  68. * is outside the point light geometry.
  69. */
  70. class PointLightOutMat : public RendererMaterial<PointLightOutMat>
  71. {
  72. RMAT_DEF("DeferredPointLightPassOut.bsl");
  73. public:
  74. PointLightOutMat();
  75. /** Updates parameters that are common for all lights. */
  76. void setStaticParameters(const SPtr<RenderTargets>& gbuffer, const SPtr<GpuParamBlockBufferCore>& perCamera);
  77. /** Updates the parameter buffers used by the material. */
  78. void setParameters(const LightCore* light);
  79. private:
  80. PerLightParams mParams; // Note: Should this buffer be shared between both point and directional lights?
  81. MaterialParamTextureCore mGBufferA;
  82. MaterialParamTextureCore mGBufferB;
  83. MaterialParamTextureCore mGBufferDepth;
  84. };
  85. /** @} */
  86. }