BsLightRendering.h 3.6 KB

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