BsStandardDeferredLighting.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 "Utility/BsModule.h"
  6. #include "Renderer/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. /** Helper method used for initializing variations of this material. */
  25. template<bool msaa, bool singleSampleMSAA>
  26. static const ShaderVariation& getVariation()
  27. {
  28. static ShaderVariation variation = ShaderVariation({
  29. ShaderVariation::Param("MSAA", msaa),
  30. ShaderVariation::Param("MSAA_RESOLVE_0TH", singleSampleMSAA)
  31. });
  32. return variation;
  33. }
  34. public:
  35. DirectionalLightMat();
  36. /** Binds the material for rendering and sets up any parameters. */
  37. void bind(const GBufferTextures& gBufferInput, const SPtr<Texture>& lightOcclusion,
  38. const SPtr<GpuParamBlockBuffer>& perCamera, const SPtr<GpuParamBlockBuffer>& perLight);
  39. /**
  40. * Returns the material variation matching the provided parameters.
  41. *
  42. * @param[in] msaa True if the shader will operate on a multisampled surface.
  43. * @param[in] singleSampleMSAA Only relevant of @p msaa is true. When enabled only the first sample will be
  44. * evaluated. Otherwise all samples will be evaluated.
  45. * @return Requested variation of the material.
  46. */
  47. static DirectionalLightMat* getVariation(bool msaa, bool singleSampleMSAA = false);
  48. private:
  49. GBufferParams mGBufferParams;
  50. GpuParamTexture mLightOcclusionTexParam;
  51. };
  52. /** Shader that renders point (radial & spot) light sources during deferred rendering light pass. */
  53. class PointLightMat : public RendererMaterial<PointLightMat>
  54. {
  55. RMAT_DEF("DeferredPointLight.bsl");
  56. /** Helper method used for initializing variations of this material. */
  57. template<bool inside, bool msaa, bool singleSampleMSAA>
  58. static const ShaderVariation& getVariation()
  59. {
  60. static ShaderVariation variation = ShaderVariation({
  61. ShaderVariation::Param("MSAA", msaa),
  62. ShaderVariation::Param("INSIDE_GEOMETRY", inside),
  63. ShaderVariation::Param("MSAA_RESOLVE_0TH", singleSampleMSAA)
  64. });
  65. return variation;
  66. }
  67. public:
  68. PointLightMat();
  69. /** Binds the material for rendering and sets up any parameters. */
  70. void bind(const GBufferTextures& gBufferInput, const SPtr<Texture>& lightOcclusion,
  71. const SPtr<GpuParamBlockBuffer>& perCamera, const SPtr<GpuParamBlockBuffer>& perLight);
  72. /**
  73. * Returns the material variation matching the provided parameters.
  74. *
  75. * @param[in] inside Set to true if viewer is inside the light's stencil geometry.
  76. * @param[in] msaa True if the shader will operate on a multisampled surface.
  77. * @param[in] singleSampleMSAA Only relevant of @p msaa is true. When enabled only the first sample will be
  78. * evaluated. Otherwise all samples will be evaluated.
  79. * @return Requested variation of the material.
  80. */
  81. static PointLightMat* getVariation(bool inside, bool msaa, bool singleSampleMSAA = false);
  82. private:
  83. GBufferParams mGBufferParams;
  84. GpuParamTexture mLightOcclusionTexParam;
  85. };
  86. /** Provides functionality for standard (non-tiled) deferred rendering. */
  87. class StandardDeferred : public Module<StandardDeferred>
  88. {
  89. public:
  90. StandardDeferred();
  91. /** Calculates lighting for the specified light, using the standard deferred renderer. */
  92. void renderLight(LightType type, const RendererLight& light, const RendererView& view,
  93. const GBufferTextures& gBufferInput, const SPtr<Texture>& lightOcclusion);
  94. private:
  95. SPtr<GpuParamBlockBuffer> mPerLightBuffer;
  96. };
  97. }}