BsLightRendering.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 parameters used in various light rendering shaders. */
  21. class LightRenderingParams
  22. {
  23. public:
  24. LightRenderingParams(const SPtr<MaterialCore>& lightMaterial, const SPtr<GpuParamsSetCore>& paramsSet);
  25. /** Updates parameters that are common for all lights. */
  26. void setStaticParameters(const SPtr<RenderTargets>& gbuffer,
  27. const SPtr<GpuParamBlockBufferCore>& perCamera);
  28. /** Updates data in the parameter buffer from the data in the provided light. */
  29. void setParameters(const LightCore* light);
  30. /** Returns the internal parameter buffer that can be bound to the pipeline. */
  31. const SPtr<GpuParamBlockBufferCore>& getBuffer() const;
  32. private:
  33. SPtr<MaterialCore> mMaterial;
  34. SPtr<GpuParamsSetCore> mParamsSet;
  35. GpuParamTextureCore mGBufferA;
  36. GpuParamTextureCore mGBufferB;
  37. GpuParamTextureCore mGBufferDepth;
  38. PerLightParamBuffer mBuffer;
  39. };
  40. /** Shader that renders directional light sources during deferred rendering light pass. */
  41. class DirectionalLightMat : public RendererMaterial<DirectionalLightMat>
  42. {
  43. RMAT_DEF("DeferredDirectionalLightPass.bsl");
  44. public:
  45. DirectionalLightMat();
  46. /** Binds the material for rendering and sets up any global parameters. */
  47. void bind(const SPtr<RenderTargets>& gbuffer, const SPtr<GpuParamBlockBufferCore>& perCamera);
  48. /** Updates the per-light buffers used by the material. */
  49. void setPerLightParams(const LightCore* light);
  50. private:
  51. LightRenderingParams mParams;
  52. };
  53. /**
  54. * Shader that renders point (radial & spot) light sources during deferred rendering light pass. Used when the camera
  55. * is inside the point light geometry.
  56. */
  57. class PointLightInMat : public RendererMaterial<PointLightInMat>
  58. {
  59. RMAT_DEF("DeferredPointLightPassIn.bsl");
  60. public:
  61. PointLightInMat();
  62. /** Binds the material for rendering and sets up any global parameters. */
  63. void bind(const SPtr<RenderTargets>& gbuffer, const SPtr<GpuParamBlockBufferCore>& perCamera);
  64. /** Updates the per-light buffers used by the material. */
  65. void setPerLightParams(const LightCore* light);
  66. private:
  67. LightRenderingParams mParams;
  68. };
  69. /**
  70. * Shader that renders point (radial & spot) light sources during deferred rendering light pass. Used when the camera
  71. * is outside the point light geometry.
  72. */
  73. class PointLightOutMat : public RendererMaterial<PointLightOutMat>
  74. {
  75. RMAT_DEF("DeferredPointLightPassOut.bsl");
  76. public:
  77. PointLightOutMat();
  78. /** Binds the material for rendering and sets up any global parameters. */
  79. void bind(const SPtr<RenderTargets>& gbuffer, const SPtr<GpuParamBlockBufferCore>& perCamera);
  80. /** Updates the per-light buffers used by the material. */
  81. void setPerLightParams(const LightCore* light);
  82. private:
  83. LightRenderingParams mParams;
  84. };
  85. /** @} */
  86. }