BsStandardDeferredLighting.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 "BsModule.h"
  6. #include "BsRendererMaterial.h"
  7. #include "BsLightRendering.h"
  8. namespace bs { namespace ct {
  9. class RendererLight;
  10. BS_PARAM_BLOCK_BEGIN(PerLightParamDef)
  11. BS_PARAM_BLOCK_ENTRY(Vector4, gLightPositionAndSrcRadius)
  12. BS_PARAM_BLOCK_ENTRY(Vector4, gLightColorAndLuminance)
  13. BS_PARAM_BLOCK_ENTRY(Vector4, gLightSpotAnglesAndSqrdInvAttRadius)
  14. BS_PARAM_BLOCK_ENTRY(Vector4, gLightDirectionAndAttRadius)
  15. BS_PARAM_BLOCK_ENTRY(Vector4, gShiftedLightPositionAndType)
  16. BS_PARAM_BLOCK_ENTRY(Vector4, gLightGeometry)
  17. BS_PARAM_BLOCK_ENTRY(Matrix4, gMatConeTransform)
  18. BS_PARAM_BLOCK_END
  19. extern PerLightParamDef gPerLightParamDef;
  20. /** Shader that renders directional light sources during deferred rendering light pass. */
  21. template<bool MSAA>
  22. class DirectionalLightMat : public RendererMaterial<DirectionalLightMat<MSAA>>
  23. {
  24. RMAT_DEF("DeferredDirectionalLight.bsl");
  25. public:
  26. DirectionalLightMat();
  27. /** Binds the material for rendering and sets up any global parameters. */
  28. void bind(const RenderTargets& renderTargets, const SPtr<GpuParamBlockBuffer>& perCamera);
  29. /** Updates the per-light buffers used by the material. */
  30. void setPerLightParams(const SPtr<GpuParamBlockBuffer>& perLight);
  31. private:
  32. GBufferParams mGBufferParams;
  33. GpuParamTexture mLightOcclusionTexParam;
  34. };
  35. /** Shader that renders point (radial & spot) light sources during deferred rendering light pass. */
  36. template<bool MSAA, bool InsideGeometry>
  37. class PointLightMat : public RendererMaterial<PointLightMat<MSAA, InsideGeometry>>
  38. {
  39. RMAT_DEF("DeferredPointLight.bsl");
  40. public:
  41. PointLightMat();
  42. /** Binds the material for rendering and sets up any global parameters. */
  43. void bind(const RenderTargets& renderTargets, const SPtr<GpuParamBlockBuffer>& perCamera);
  44. /** Updates the per-light buffers used by the material. */
  45. void setPerLightParams(const SPtr<GpuParamBlockBuffer>& perLight);
  46. private:
  47. GBufferParams mGBufferParams;
  48. GpuParamTexture mLightOcclusionTexParam;
  49. };
  50. /** Provides functionality for standard (non-tiled) deferred rendering. */
  51. class StandardDeferred : public Module<StandardDeferred>
  52. {
  53. public:
  54. StandardDeferred();
  55. /** Calculates lighting for the specified light, using the standard deferred renderer. */
  56. void renderLight(LightType type, const RendererLight& light, const RendererView& view,
  57. const RenderTargets& renderTargets);
  58. private:
  59. SPtr<GpuParamBlockBuffer> mPerLightBuffer;
  60. PointLightMat<true, true> mPointLightMat_TT;
  61. PointLightMat<true, false> mPointLightMat_TF;
  62. PointLightMat<false, true> mPointLightMat_FT;
  63. PointLightMat<false, false> mPointLightMat_FF;
  64. DirectionalLightMat<true> mDirLightMat_T;
  65. DirectionalLightMat<false> mDirLightMat_F;
  66. };
  67. }}