BsLightRendering.h 3.7 KB

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