BsStandardDeferredLighting.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. class DirectionalLightMat : public RendererMaterial<DirectionalLightMat>
  22. {
  23. RMAT_DEF("DeferredDirectionalLight.bsl");
  24. public:
  25. DirectionalLightMat();
  26. /** Binds the material for rendering and sets up any global parameters. */
  27. void bind(const GBufferTextures& gBufferInput, const SPtr<Texture>& lightOcclusion,
  28. const SPtr<GpuParamBlockBuffer>& perCamera);
  29. /** Updates the per-light buffers used by the material. */
  30. void setPerLightParams(const SPtr<GpuParamBlockBuffer>& perLight);
  31. /** Returns the material variation matching the provided parameters. */
  32. static DirectionalLightMat* getVariation(bool msaa);
  33. private:
  34. GBufferParams mGBufferParams;
  35. GpuParamTexture mLightOcclusionTexParam;
  36. static ShaderVariation VAR_MSAA;
  37. static ShaderVariation VAR_NoMSAA;
  38. };
  39. /** Shader that renders point (radial & spot) light sources during deferred rendering light pass. */
  40. class PointLightMat : public RendererMaterial<PointLightMat>
  41. {
  42. RMAT_DEF("DeferredPointLight.bsl");
  43. public:
  44. PointLightMat();
  45. /** Binds the material for rendering and sets up any global parameters. */
  46. void bind(const GBufferTextures& gBufferInput, const SPtr<Texture>& lightOcclusion,
  47. const SPtr<GpuParamBlockBuffer>& perCamera);
  48. /** Updates the per-light buffers used by the material. */
  49. void setPerLightParams(const SPtr<GpuParamBlockBuffer>& perLight);
  50. /** Returns the material variation matching the provided parameters. */
  51. static PointLightMat* getVariation(bool msaa, bool inside);
  52. private:
  53. GBufferParams mGBufferParams;
  54. GpuParamTexture mLightOcclusionTexParam;
  55. static ShaderVariation VAR_MSAA_Inside;
  56. static ShaderVariation VAR_MSAA_Outside;
  57. static ShaderVariation VAR_NoMSAA_Inside;
  58. static ShaderVariation VAR_NoMSAA_Outside;
  59. };
  60. /** Provides functionality for standard (non-tiled) deferred rendering. */
  61. class StandardDeferred : public Module<StandardDeferred>
  62. {
  63. public:
  64. StandardDeferred();
  65. /** Calculates lighting for the specified light, using the standard deferred renderer. */
  66. void renderLight(LightType type, const RendererLight& light, const RendererView& view,
  67. const GBufferTextures& gBufferInput, const SPtr<Texture>& lightOcclusion);
  68. private:
  69. SPtr<GpuParamBlockBuffer> mPerLightBuffer;
  70. };
  71. }}