ShadowMapping.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Renderer/RendererObject.h>
  7. #include <AnKi/Gr.h>
  8. #include <AnKi/Resource/ImageResource.h>
  9. #include <AnKi/Renderer/Utils/TileAllocator.h>
  10. namespace anki {
  11. // Forward
  12. class GpuVisibilityOutput;
  13. /// @addtogroup renderer
  14. /// @{
  15. ANKI_CVAR2(NumericCVar<U32>, Render, Sm, TileResolution, (ANKI_PLATFORM_MOBILE) ? 128 : 256, 16, 2048, "Shadowmapping tile resolution")
  16. ANKI_CVAR2(NumericCVar<U32>, Render, Sm, TileCountPerRowOrColumn, 32, 1, 256, "Shadowmapping atlas will have this number squared number of tiles")
  17. ANKI_CVAR2(BoolCVar, Render, Sm, Pcf, (ANKI_PLATFORM_MOBILE) ? false : true, "Shadow PCF")
  18. ANKI_CVAR2(BoolCVar, Render, Sm, Pcss, (ANKI_PLATFORM_MOBILE) ? false : true, "Shadow PCSS")
  19. /// Shadowmapping pass
  20. class ShadowMapping : public RendererObject
  21. {
  22. public:
  23. Error init();
  24. /// Populate the rendergraph.
  25. void populateRenderGraph(RenderingContext& ctx);
  26. RenderTargetHandle getShadowmapRt() const
  27. {
  28. return m_runCtx.m_rt;
  29. }
  30. private:
  31. class ShadowSubpassInfo
  32. {
  33. public:
  34. UVec4 m_viewport;
  35. Mat4 m_viewProjMat;
  36. Mat3x4 m_viewMat;
  37. BufferView m_clearTileIndirectArgs;
  38. RenderTargetHandle m_hzbRt;
  39. };
  40. TileAllocator m_tileAlloc;
  41. static constexpr U32 kTileAllocHierarchyCount = 4;
  42. static constexpr U32 kPointLightMaxTileAllocHierarchy = 1;
  43. static constexpr U32 kSpotLightMaxTileAllocHierarchy = 1;
  44. TexturePtr m_atlasTex; ///< Size (m_tileResolution*m_tileCountBothAxis)^2
  45. Bool m_rtImportedOnce = false;
  46. U32 m_tileResolution = 0; ///< Tile resolution.
  47. U32 m_tileCountBothAxis = 0;
  48. ShaderProgramResourcePtr m_clearDepthProg;
  49. ShaderProgramPtr m_clearDepthGrProg;
  50. ShaderProgramResourcePtr m_vetVisibilityProg;
  51. ShaderProgramPtr m_vetVisibilityGrProg;
  52. Array<RenderTargetDesc, kMaxShadowCascades> m_cascadeHzbRtDescrs;
  53. class
  54. {
  55. public:
  56. RenderTargetHandle m_rt;
  57. } m_runCtx;
  58. void processLights(RenderingContext& ctx);
  59. TileAllocatorResult2 allocateAtlasTiles(U32 lightUuid, U32 componentIndex, U32 faceCount, const U32* hierarchies, UVec4* atlasTileViewports);
  60. Mat4 createSpotLightTextureMatrix(const UVec4& viewport) const;
  61. void chooseDetail(const Vec3& cameraOrigin, const LightComponent& lightc, Vec2 lodDistances, U32& tileAllocatorHierarchy) const;
  62. BufferView createVetVisibilityPass(CString passName, const LightComponent& lightc, const GpuVisibilityOutput& visOut,
  63. RenderGraphBuilder& rgraph) const;
  64. void createDrawShadowsPass(const UVec4& viewport, const Mat4& viewProjMat, const Mat3x4& viewMat, const GpuVisibilityOutput& visOut,
  65. const BufferView& clearTileIndirectArgs, const RenderTargetHandle hzbRt, CString passName, RenderGraphBuilder& rgraph);
  66. void createDrawShadowsPass(ConstWeakArray<ShadowSubpassInfo> subPasses, const GpuVisibilityOutput& visOut, CString passName,
  67. RenderGraphBuilder& rgraph);
  68. };
  69. /// @}
  70. } // end namespace anki