Is.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #ifndef ANKI_RENDERER_IS_H
  2. #define ANKI_RENDERER_IS_H
  3. #include "anki/renderer/RenderingPass.h"
  4. #include "anki/resource/TextureResource.h"
  5. #include "anki/resource/Resource.h"
  6. #include "anki/resource/ShaderProgramResource.h"
  7. #include "anki/gl/Gl.h"
  8. #include "anki/Math.h"
  9. #include "anki/renderer/Sm.h"
  10. #include "anki/util/StdTypes.h"
  11. #include "anki/util/Array.h"
  12. #include "anki/core/Timestamp.h"
  13. #include "anki/collision/Plane.h"
  14. namespace anki {
  15. class Camera;
  16. class PerspectiveCamera;
  17. class PointLight;
  18. class SpotLight;
  19. /// Illumination stage
  20. class Is: private RenderingPass
  21. {
  22. friend struct WriteLightsJob;
  23. public:
  24. Is(Renderer* r);
  25. ~Is();
  26. void init(const RendererInitializer& initializer);
  27. void run();
  28. /// @name Accessors
  29. /// @{
  30. const Texture& getFai() const
  31. {
  32. return fai;
  33. }
  34. Texture& getFai()
  35. {
  36. return fai;
  37. }
  38. /// @}
  39. private:
  40. static const U COMMON_UNIFORMS_BLOCK_BINDING = 0;
  41. static const U POINT_LIGHTS_BLOCK_BINDING = 1;
  42. static const U SPOT_LIGHTS_BLOCK_BINDING = 2;
  43. static const U SPOT_TEX_LIGHTS_BLOCK_BINDING = 3;
  44. static const U TILES_BLOCK_BINDING = 4;
  45. static const U TILES_POINT_LIGHT_INDICES_BLOCK_BINDING = 5;
  46. static const U TILES_SPOT_LIGHT_INDICES_BLOCK_BINDING = 6;
  47. /// The IS FAI
  48. Texture fai;
  49. /// The IS FBO
  50. Fbo fbo;
  51. /// @name GPU buffers
  52. /// @{
  53. PtrSize uboAlignment = MAX_PTR_SIZE; ///< Cache the value here
  54. /// Contains common data for all shader programs
  55. Ubo commonUbo;
  56. /// Track the updates of commonUbo
  57. Timestamp commonUboUpdateTimestamp = getGlobTimestamp();
  58. /// Contains all the lights
  59. Ubo lightsUbo;
  60. /// Contains the number of lights per tile
  61. BufferObject tilesBuffer;
  62. BufferObject pointLightIndicesBuffer;
  63. BufferObject spotLightIndicesBuffer;
  64. /// @}
  65. // Light shaders
  66. ShaderProgramResourcePointer lightPassProg;
  67. ShaderProgramResourcePointer rejectProg;
  68. /// Shadow mapping
  69. Sm sm;
  70. /// Opt because many ask for it
  71. Camera* cam;
  72. /// If enabled the ground emmits a light
  73. Bool groundLightEnabled;
  74. /// Keep the prev light dir to avoid uniform block updates
  75. Vec3 prevGroundLightDir = Vec3(0.0);
  76. /// @name For drawing a quad into the active framebuffer
  77. /// @{
  78. Vbo quadPositionsVbo; ///< The VBO for quad positions
  79. Vao quadVao; ///< This VAO is used everywhere except material stage
  80. /// @}
  81. /// @name Limits
  82. /// @{
  83. U16 maxPointLights;
  84. U8 maxSpotLights;
  85. U8 maxSpotTexLights;
  86. U8 maxPointLightsPerTile;
  87. U8 maxSpotLightsPerTile;
  88. U8 maxSpotTexLightsPerTile;
  89. /// @}
  90. /// Called by init
  91. void initInternal(const RendererInitializer& initializer);
  92. /// Do the actual pass
  93. void lightPass();
  94. /// Prepare GL for rendering
  95. void setState();
  96. /// Calculate the size of the lights UBO
  97. PtrSize calcLightsUboSize() const;
  98. /// Calculate the size of the indices of point lights
  99. PtrSize calcPointLightIndicesBufferSize() const;
  100. /// Calculate the size of the indices of spot lights
  101. PtrSize calcSpotLightIndicesBufferSize() const;
  102. /// Setup the binding of the block and do some sanity checks on the size
  103. void blockSetupAndSanityCheck(const char* name, U binding, PtrSize size);
  104. };
  105. } // end namespace anki
  106. #endif