💿🐜 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.

332 lines
8.8 KiB

7 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
7 years ago
6 years ago
7 years ago
7 years ago
6 years ago
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. * Clears framebuffers
  27. */
  28. class ClearRenderPass: public RenderPass
  29. {
  30. public:
  31. ClearRenderPass();
  32. virtual bool load(const RenderContext* renderContext);
  33. virtual void unload();
  34. virtual void render(RenderContext* renderContext);
  35. void setClear(bool color, bool depth, bool stencil);
  36. void setClearColor(const Vector4& color);
  37. void setClearDepth(float depth);
  38. void setClearStencil(int index);
  39. private:
  40. bool clearColor;
  41. bool clearDepth;
  42. bool clearStencil;
  43. Vector4 color;
  44. float depth;
  45. int index;
  46. };
  47. /**
  48. * Renders the distance from the view frustum's near clipping plane to scene geometry. The render target should have a depth only framebuffer.
  49. */
  50. class ShadowMapRenderPass: public RenderPass
  51. {
  52. public:
  53. ShadowMapRenderPass();
  54. virtual bool load(const RenderContext* renderContext);
  55. virtual void unload();
  56. virtual void render(RenderContext* renderContext);
  57. inline void setViewCamera(const Camera* camera) { this->viewCamera = camera; }
  58. inline void setLightCamera(Camera* camera) { this->lightCamera = camera; }
  59. inline int getFrustumSplitCount() const { return frustumSplitCount; }
  60. inline const ViewFrustum& getSplitViewFrustum(std::size_t index) const { return splitViewFrustum->getSubfrustum(index); }
  61. inline const Matrix4& getCropMatrix(std::size_t index) const { return cropMatrices[index]; }
  62. inline const Matrix4& getTileMatrix(std::size_t index) const { return tileMatrices[index]; }
  63. private:
  64. ShaderParameterSet parameterSet;
  65. const ShaderParameter* modelViewProjectionParam;
  66. const ShaderParameter* matrixPaletteParam;
  67. ShaderLoader shaderLoader;
  68. Shader* unskinnedShader;
  69. Shader* skinnedShader;
  70. int maxBoneCount;
  71. int frustumSplitCount;
  72. int shadowMapResolution;
  73. int croppedShadowMapResolution;
  74. Vector4* croppedShadowMapViewports;
  75. Matrix4* cropMatrices;
  76. Matrix4* tileMatrices;
  77. const Camera* viewCamera;
  78. Camera* lightCamera;
  79. SplitViewFrustum* splitViewFrustum;
  80. };
  81. /**
  82. * Writes clipped edges to stencil buffer.
  83. */
  84. class ClippingRenderPass: public RenderPass
  85. {
  86. public:
  87. ClippingRenderPass();
  88. virtual bool load(const RenderContext* renderContext);
  89. virtual void unload();
  90. virtual void render(RenderContext* renderContext);
  91. void setClippingPlane(const Plane& plane);
  92. private:
  93. ShaderParameterSet parameterSet;
  94. const ShaderParameter* modelParam;
  95. const ShaderParameter* modelViewProjectionParam;
  96. const ShaderParameter* clippingPlanesParam;
  97. ShaderLoader shaderLoader;
  98. Shader* shader;
  99. Vector4 clippingPlane;
  100. };
  101. /**
  102. * Renders soil profiles.
  103. *
  104. * A soil profile generally of five soil horizons: O, A, B, C, and R.
  105. *
  106. * Horizon O: Organic
  107. * Horizon A: Surface
  108. * Horizon B: Subsoil
  109. * Horizon C: Substratum
  110. * Horizon R: Bedrock
  111. *
  112. * In this render pass, only the O, A, B, and C horizons are used.
  113. */
  114. class SoilRenderPass: public RenderPass
  115. {
  116. public:
  117. SoilRenderPass();
  118. virtual bool load(const RenderContext* renderContext);
  119. virtual void unload();
  120. virtual void render(RenderContext* renderContext);
  121. inline void setHorizonOTexture(Texture* texture) { horizonOTexture = texture; }
  122. inline void setHorizonATexture(Texture* texture) { horizonATexture = texture; }
  123. inline void setHorizonBTexture(Texture* texture) { horizonBTexture = texture; }
  124. inline void setHorizonCTexture(Texture* texture) { horizonCTexture = texture; }
  125. private:
  126. ShaderParameterSet parameterSet;
  127. const ShaderParameter* modelParam;
  128. const ShaderParameter* modelViewProjectionParam;
  129. const ShaderParameter* horizonTexturesParam;
  130. ShaderLoader shaderLoader;
  131. Shader* shader;
  132. Texture* horizonOTexture;
  133. Texture* horizonATexture;
  134. Texture* horizonBTexture;
  135. Texture* horizonCTexture;
  136. };
  137. /**
  138. * Renders scene geometry.
  139. */
  140. class LightingRenderPass: public RenderPass
  141. {
  142. public:
  143. LightingRenderPass();
  144. virtual bool load(const RenderContext* renderContext);
  145. virtual void unload();
  146. virtual void render(RenderContext* renderContext);
  147. inline void setShadowMap(GLuint shadowMap) { this->shadowMap = shadowMap; }
  148. inline void setShadowCamera(const Camera* camera) { this->shadowCamera = camera; }
  149. inline void setShadowMapPass(const ShadowMapRenderPass* shadowMapPass) { this->shadowMapPass = shadowMapPass; }
  150. inline void setDiffuseCubemap(const Texture* cubemap) { this->diffuseCubemap = cubemap; }
  151. inline void setSpecularCubemap(const Texture* cubemap) { this->specularCubemap = cubemap; }
  152. private:
  153. class RenderOpCompare
  154. {
  155. public:
  156. // Sort render opations
  157. bool operator()(const RenderOperation& opA, const RenderOperation& opB) const;
  158. };
  159. bool loadShader(const RenderOperation& operation);
  160. ShaderParameterSet parameterSet;
  161. const ShaderParameter* matrixPaletteParam;
  162. const ShaderParameter* modelParam;
  163. const ShaderParameter* modelViewParam;
  164. const ShaderParameter* modelViewProjectionParam;
  165. const ShaderParameter* normalModelViewParam;
  166. const ShaderParameter* normalModelParam;
  167. const ShaderParameter* lightViewProjectionParam;
  168. const ShaderParameter* shadowMapParam;
  169. const ShaderParameter* cameraPositionParam;
  170. const ShaderParameter* directionalLightCountParam;
  171. const ShaderParameter* directionalLightColorsParam;
  172. const ShaderParameter* directionalLightDirectionsParam;
  173. const ShaderParameter* albedoOpacityMapParam;
  174. const ShaderParameter* metalnessRoughnessMapParam;
  175. const ShaderParameter* normalOcclusionMapParam;
  176. const ShaderParameter* diffuseCubemapParam;
  177. const ShaderParameter* specularCubemapParam;
  178. Shader* unskinnedShader;
  179. Shader* skinnedShader;
  180. int maxBoneCount;
  181. ShaderLoader shaderLoader;
  182. std::map<std::size_t, Shader*> shaderCache;
  183. //Shader* lightingShader;
  184. Matrix4 biasMatrix;
  185. GLuint shadowMap;
  186. Texture* treeShadow;
  187. const Texture* diffuseCubemap;
  188. const Texture* specularCubemap;
  189. const Camera* shadowCamera;
  190. float time;
  191. const ShadowMapRenderPass* shadowMapPass;
  192. };
  193. /**
  194. * Renders bounding boxes, skeletons
  195. */
  196. class DebugRenderPass: public RenderPass
  197. {
  198. public:
  199. DebugRenderPass();
  200. virtual bool load(const RenderContext* renderContext);
  201. virtual void unload();
  202. virtual void render(RenderContext* renderContext);
  203. //void setDrawBounds(bool enabled);
  204. //void setDrawSkeletons(bool enabled);
  205. //void setDrawCameras(bool enabled);
  206. //void setDrawLights(bool enabled);
  207. private:
  208. ShaderParameterSet parameterSet;
  209. const ShaderParameter* modelViewProjectionParam;
  210. ShaderLoader shaderLoader;
  211. Shader* unlitSolidShader;
  212. int aabbVertexCount;
  213. int aabbIndexCount;
  214. GLuint aabbVAO;
  215. GLuint aabbVBO;
  216. GLuint aabbIBO;
  217. };
  218. /**
  219. * Renders the user interface
  220. */
  221. class UIRenderPass: public RenderPass
  222. {
  223. public:
  224. UIRenderPass();
  225. virtual bool load(const RenderContext* renderContext);
  226. virtual void unload();
  227. virtual void render(RenderContext* renderContext);
  228. private:
  229. ShaderParameterSet parameterSet;
  230. const ShaderParameter* modelViewProjectionParam;
  231. const ShaderParameter* textureParam;
  232. const ShaderParameter* texcoordOffsetParam;
  233. const ShaderParameter* texcoordScaleParam;
  234. ShaderLoader shaderLoader;
  235. Shader* texturedUIShader;
  236. Shader* untexturedUIShader;
  237. };
  238. /**
  239. * Renders a vignette
  240. */
  241. class VignetteRenderPass: public RenderPass
  242. {
  243. public:
  244. VignetteRenderPass();
  245. virtual bool load(const RenderContext* renderContext);
  246. virtual void unload();
  247. virtual void render(RenderContext* renderContext);
  248. private:
  249. ShaderParameterSet parameterSet;
  250. const ShaderParameter* modelViewProjectionParam;
  251. const ShaderParameter* bayerTextureParam;
  252. ShaderLoader shaderLoader;
  253. Shader* shader;
  254. GLuint bayerTextureID;
  255. };
  256. /**
  257. * Renders a skybox
  258. */
  259. class SkyboxRenderPass: public RenderPass
  260. {
  261. public:
  262. SkyboxRenderPass();
  263. inline void setCubemap(Texture* cubemap) { this->cubemap = cubemap; }
  264. virtual bool load(const RenderContext* renderContext);
  265. virtual void unload();
  266. virtual void render(RenderContext* renderContext);
  267. private:
  268. ShaderParameterSet parameterSet;
  269. const ShaderParameter* matrixParam;
  270. const ShaderParameter* cubemapParam;
  271. ShaderLoader shaderLoader;
  272. Shader* shader;
  273. Texture* cubemap;
  274. int quadVertexCount;
  275. int quadIndexCount;
  276. GLuint quadVAO;
  277. GLuint quadVBO;
  278. GLuint quadIBO;
  279. };
  280. #endif // RENDER_PASSES_HPP