Is.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <anki/renderer/RenderingPass.h>
  7. #include <anki/resource/TextureResource.h>
  8. #include <anki/resource/ShaderResource.h>
  9. #include <anki/Gr.h>
  10. #include <anki/Math.h>
  11. #include <anki/renderer/Sm.h>
  12. #include <anki/util/StdTypes.h>
  13. #include <anki/util/Array.h>
  14. #include <anki/core/Timestamp.h>
  15. #include <anki/collision/Plane.h>
  16. namespace anki
  17. {
  18. // Forward
  19. class Camera;
  20. class PerspectiveCamera;
  21. class PointLight;
  22. class SpotLight;
  23. class LightComponent;
  24. class MoveComponent;
  25. class SpatialComponent;
  26. class FrustumComponent;
  27. class TaskCommonData;
  28. class ClustererTestResult;
  29. /// @addtogroup renderer
  30. /// @{
  31. /// Illumination stage
  32. class Is : public RenderingPass
  33. {
  34. friend class WriteLightsTask;
  35. public:
  36. static const U MIPMAPS_COUNT = 7;
  37. anki_internal:
  38. static const PixelFormat RT_PIXEL_FORMAT;
  39. Is(Renderer* r);
  40. ~Is();
  41. ANKI_USE_RESULT Error init(const ConfigSet& initializer);
  42. ANKI_USE_RESULT Error run(CommandBufferPtr& cmdBuff);
  43. TexturePtr getRt() const
  44. {
  45. return m_rt;
  46. }
  47. void generateMipmaps(CommandBufferPtr& cmdb)
  48. {
  49. cmdb->generateMipmaps(m_rt);
  50. }
  51. void setAmbientColor(const Vec4& color)
  52. {
  53. m_ambientColor = color;
  54. }
  55. Sm& getSm()
  56. {
  57. return m_sm;
  58. }
  59. DynamicBufferToken getCommonVarsToken() const
  60. {
  61. return m_commonVarsToken;
  62. }
  63. DynamicBufferToken getPointLightsToken() const
  64. {
  65. return m_pLightsToken;
  66. }
  67. DynamicBufferToken getSpotLightsToken() const
  68. {
  69. return m_sLightsToken;
  70. }
  71. DynamicBufferToken getClustersToken() const
  72. {
  73. return m_clustersToken;
  74. }
  75. DynamicBufferToken getLightIndicesToken() const
  76. {
  77. return m_lightIdsToken;
  78. }
  79. private:
  80. /// The IS render target
  81. TexturePtr m_rt;
  82. /// The IS FBO
  83. FramebufferPtr m_fb;
  84. DynamicBufferToken m_commonVarsToken;
  85. DynamicBufferToken m_pLightsToken;
  86. DynamicBufferToken m_sLightsToken;
  87. DynamicBufferToken m_clustersToken;
  88. DynamicBufferToken m_lightIdsToken;
  89. ResourceGroupPtr m_rcGroup;
  90. // Light shaders
  91. ShaderResourcePtr m_lightVert;
  92. ShaderResourcePtr m_lightFrag;
  93. PipelinePtr m_lightPpline;
  94. /// Shadow mapping
  95. Sm m_sm;
  96. /// Opt because many ask for it
  97. FrustumComponent* m_frc = nullptr;
  98. /// If enabled the ground emmits a light
  99. Bool8 m_groundLightEnabled;
  100. /// Keep the prev light dir to avoid uniform block updates
  101. Vec3 m_prevGroundLightDir = Vec3(0.0);
  102. /// @name Limits
  103. /// @{
  104. U16 m_maxPointLights;
  105. U32 m_maxSpotLights;
  106. U32 m_maxSpotTexLights;
  107. U32 m_maxLightIds;
  108. /// @}
  109. Vec4 m_ambientColor = Vec4(0.0);
  110. WeakPtr<Barrier> m_barrier;
  111. /// Called by init
  112. ANKI_USE_RESULT Error initInternal(const ConfigSet& initializer);
  113. /// Do the actual pass
  114. ANKI_USE_RESULT Error lightPass(CommandBufferPtr& cmdBuff);
  115. /// Prepare GL for rendering
  116. void setState(CommandBufferPtr& cmdBuff);
  117. void updateCommonBlock(
  118. CommandBufferPtr& cmdBuff, const FrustumComponent& frc);
  119. // Binning
  120. void binLights(U32 threadId, PtrSize threadsCount, TaskCommonData& data);
  121. I writePointLight(const LightComponent& light,
  122. const MoveComponent& move,
  123. const FrustumComponent& camfrc,
  124. TaskCommonData& task);
  125. I writeSpotLight(const LightComponent& lightc,
  126. const MoveComponent& lightMove,
  127. const FrustumComponent* lightFrc,
  128. const MoveComponent& camMove,
  129. const FrustumComponent& camFrc,
  130. TaskCommonData& task);
  131. void binLight(SpatialComponent& sp,
  132. U pos,
  133. U lightType,
  134. TaskCommonData& task,
  135. ClustererTestResult& testResult);
  136. };
  137. /// @}
  138. } // end namespace anki