BsStandardDeferredLighting.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. 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. /**
  32. * Returns the material variation matching the provided parameters.
  33. *
  34. * @param[in] msaa True if the shader will operate on a multisampled surface.
  35. * @param[in] singleSampleMSAA Only relevant of @p msaa is true. When enabled only the first sample will be
  36. * evaluated. Otherwise all samples will be evaluated.
  37. * @return Requested variation of the material.
  38. */
  39. static DirectionalLightMat* getVariation(bool msaa, bool singleSampleMSAA = false);
  40. private:
  41. GBufferParams mGBufferParams;
  42. GpuParamTexture mLightOcclusionTexParam;
  43. static ShaderVariation VAR_FullMSAA;
  44. static ShaderVariation VAR_SingleMSAA;
  45. static ShaderVariation VAR_NoMSAA;
  46. };
  47. /** Shader that renders point (radial & spot) light sources during deferred rendering light pass. */
  48. class PointLightMat : public RendererMaterial<PointLightMat>
  49. {
  50. RMAT_DEF("DeferredPointLight.bsl");
  51. public:
  52. PointLightMat();
  53. /** Binds the material for rendering and sets up any global parameters. */
  54. void bind(const GBufferTextures& gBufferInput, const SPtr<Texture>& lightOcclusion,
  55. const SPtr<GpuParamBlockBuffer>& perCamera);
  56. /** Updates the per-light buffers used by the material. */
  57. void setPerLightParams(const SPtr<GpuParamBlockBuffer>& perLight);
  58. /**
  59. * Returns the material variation matching the provided parameters.
  60. *
  61. * @param[in] inside Set to true if viewer is inside the light's stencil geometry.
  62. * @param[in] msaa True if the shader will operate on a multisampled surface.
  63. * @param[in] singleSampleMSAA Only relevant of @p msaa is true. When enabled only the first sample will be
  64. * evaluated. Otherwise all samples will be evaluated.
  65. * @return Requested variation of the material.
  66. */
  67. static PointLightMat* getVariation(bool inside, bool msaa, bool singleSampleMSAA = false);
  68. private:
  69. GBufferParams mGBufferParams;
  70. GpuParamTexture mLightOcclusionTexParam;
  71. static ShaderVariation VAR_FullMSAA_Inside;
  72. static ShaderVariation VAR_SingleMSAA_Inside;
  73. static ShaderVariation VAR_FullMSAA_Outside;
  74. static ShaderVariation VAR_SingleMSAA_Outside;
  75. static ShaderVariation VAR_NoMSAA_Inside;
  76. static ShaderVariation VAR_NoMSAA_Outside;
  77. };
  78. /** Provides functionality for standard (non-tiled) deferred rendering. */
  79. class StandardDeferred : public Module<StandardDeferred>
  80. {
  81. public:
  82. StandardDeferred();
  83. /** Calculates lighting for the specified light, using the standard deferred renderer. */
  84. void renderLight(LightType type, const RendererLight& light, const RendererView& view,
  85. const GBufferTextures& gBufferInput, const SPtr<Texture>& lightOcclusion);
  86. private:
  87. SPtr<GpuParamBlockBuffer> mPerLightBuffer;
  88. };
  89. }}