💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
4.3 KiB

7 years ago
  1. /*
  2. * Copyright (C) 2017 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper Source Code.
  5. *
  6. * Antkeeper Source Code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper Source Code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper Source Code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef RENDER_PASSES_HPP
  20. #define RENDER_PASSES_HPP
  21. #include <emergent/emergent.hpp>
  22. using namespace Emergent;
  23. #include "material-loader.hpp"
  24. #include "model-loader.hpp"
  25. /**
  26. * Renders the distance from the view frustum's near clipping plane to scene geometry. The render target should have a depth only framebuffer.
  27. */
  28. class ShadowMapRenderPass: public RenderPass
  29. {
  30. public:
  31. ShadowMapRenderPass();
  32. virtual bool load(const RenderContext* renderContext);
  33. virtual void unload();
  34. virtual void render(const RenderContext* renderContext);
  35. private:
  36. ShaderLoader shaderLoader;
  37. Shader* depthShader;
  38. };
  39. /**
  40. * Writes clipped edges to stencil buffer.
  41. */
  42. class ClippingRenderPass: public RenderPass
  43. {
  44. public:
  45. ClippingRenderPass();
  46. virtual bool load(const RenderContext* renderContext);
  47. virtual void unload();
  48. virtual void render(const RenderContext* renderContext);
  49. void setClippingPlane(const Plane& plane);
  50. private:
  51. ShaderLoader shaderLoader;
  52. Shader* shader;
  53. Vector4 clippingPlane;
  54. };
  55. /**
  56. * Caps clipped geometry.
  57. */
  58. class CappingRenderPass: public RenderPass
  59. {
  60. public:
  61. CappingRenderPass();
  62. virtual bool load(const RenderContext* renderContext);
  63. virtual void unload();
  64. virtual void render(const RenderContext* renderContext);
  65. private:
  66. ShaderLoader shaderLoader;
  67. Shader* shader;
  68. Texture horizonOTexture;
  69. Texture horizonATexture;
  70. Texture horizonBTexture;
  71. Texture horizonCTexture;
  72. };
  73. /**
  74. * Renders scene geometry.
  75. */
  76. class LightingRenderPass: public RenderPass
  77. {
  78. public:
  79. LightingRenderPass();
  80. virtual bool load(const RenderContext* renderContext);
  81. virtual void unload();
  82. virtual void render(const RenderContext* renderContext);
  83. inline void setShadowMap(GLuint shadowMap) { this->shadowMap = shadowMap; }
  84. inline void setShadowCamera(const Camera* camera) { this->shadowCamera = camera; }
  85. inline void setClippingPlanes(const Plane* planes)
  86. {
  87. for (int i = 0; i < 5; ++i)
  88. {
  89. this->clippingPlanes[i] = planes[i];
  90. }
  91. }
  92. private:
  93. bool loadShader(const RenderOperation& operation);
  94. ShaderLoader shaderLoader;
  95. std::map<std::size_t, Shader*> shaderCache;
  96. Matrix4 biasMatrix;
  97. GLuint shadowMap;
  98. Texture treeShadow;
  99. const Camera* shadowCamera;
  100. float time;
  101. // Cutaway clipping and capping
  102. Plane clippingPlanes[5];
  103. Model* unitPlaneModel;
  104. ModelInstance cappingPlaneInstances[5];
  105. RenderQueue cappingRenderQueue;
  106. RenderContext cappingRenderContext;
  107. ClippingRenderPass clippingRenderPass;
  108. CappingRenderPass cappingRenderPass;
  109. MaterialLoader materialLoader;
  110. ModelLoader modelLoader;
  111. };
  112. /**
  113. * Renders bounding boxes, skeletons
  114. */
  115. class DebugRenderPass: public RenderPass
  116. {
  117. public:
  118. virtual bool load(const RenderContext* renderContext);
  119. virtual void unload();
  120. virtual void render(const RenderContext* renderContext);
  121. private:
  122. ShaderLoader shaderLoader;
  123. Shader* unlitSolidShader;
  124. int aabbVertexCount;
  125. int aabbIndexCount;
  126. GLuint aabbVAO;
  127. GLuint aabbVBO;
  128. GLuint aabbIBO;
  129. };
  130. /**
  131. * Renders the user interface
  132. */
  133. class UIRenderPass: public RenderPass
  134. {
  135. public:
  136. virtual bool load(const RenderContext* renderContext);
  137. virtual void unload();
  138. virtual void render(const RenderContext* renderContext);
  139. private:
  140. ShaderLoader shaderLoader;
  141. Shader* texturedUIShader;
  142. Shader* untexturedUIShader;
  143. };
  144. /**
  145. * Renders a vignette
  146. */
  147. class VignetteRenderPass: public RenderPass
  148. {
  149. public:
  150. VignetteRenderPass();
  151. virtual bool load(const RenderContext* renderContext);
  152. virtual void unload();
  153. virtual void render(const RenderContext* renderContext);
  154. private:
  155. ShaderLoader shaderLoader;
  156. Shader* shader;
  157. GLuint bayerTextureID;
  158. };
  159. #endif // RENDER_PASSES_HPP