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

267 lines
6.8 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 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. * 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. ShaderParameterSet parameterSet;
  37. const ShaderParameter* modelViewProjectionParam;
  38. ShaderLoader shaderLoader;
  39. Shader* depthShader;
  40. };
  41. /**
  42. * Writes clipped edges to stencil buffer.
  43. */
  44. class ClippingRenderPass: public RenderPass
  45. {
  46. public:
  47. ClippingRenderPass();
  48. virtual bool load(const RenderContext* renderContext);
  49. virtual void unload();
  50. virtual void render(const RenderContext* renderContext);
  51. void setClippingPlane(const Plane& plane);
  52. private:
  53. ShaderParameterSet parameterSet;
  54. const ShaderParameter* modelParam;
  55. const ShaderParameter* modelViewProjectionParam;
  56. const ShaderParameter* clippingPlanesParam;
  57. ShaderLoader shaderLoader;
  58. Shader* shader;
  59. Vector4 clippingPlane;
  60. };
  61. /**
  62. * Renders soil profiles.
  63. *
  64. * A soil profile generally of five soil horizons: O, A, B, C, and R.
  65. *
  66. * Horizon O: Organic
  67. * Horizon A: Surface
  68. * Horizon B: Subsoil
  69. * Horizon C: Substratum
  70. * Horizon R: Bedrock
  71. *
  72. * In this render pass, only the O, A, B, and C horizons are used.
  73. */
  74. class SoilRenderPass: public RenderPass
  75. {
  76. public:
  77. SoilRenderPass();
  78. virtual bool load(const RenderContext* renderContext);
  79. virtual void unload();
  80. virtual void render(const RenderContext* renderContext);
  81. inline void setHorizonOTexture(Texture* texture) { horizonOTexture = texture; }
  82. inline void setHorizonATexture(Texture* texture) { horizonATexture = texture; }
  83. inline void setHorizonBTexture(Texture* texture) { horizonBTexture = texture; }
  84. inline void setHorizonCTexture(Texture* texture) { horizonCTexture = texture; }
  85. private:
  86. ShaderParameterSet parameterSet;
  87. const ShaderParameter* modelParam;
  88. const ShaderParameter* modelViewProjectionParam;
  89. const ShaderParameter* horizonTexturesParam;
  90. ShaderLoader shaderLoader;
  91. Shader* shader;
  92. Texture* horizonOTexture;
  93. Texture* horizonATexture;
  94. Texture* horizonBTexture;
  95. Texture* horizonCTexture;
  96. };
  97. /**
  98. * Renders scene geometry.
  99. */
  100. class LightingRenderPass: public RenderPass
  101. {
  102. public:
  103. LightingRenderPass();
  104. virtual bool load(const RenderContext* renderContext);
  105. virtual void unload();
  106. virtual void render(const RenderContext* renderContext);
  107. inline void setShadowMap(GLuint shadowMap) { this->shadowMap = shadowMap; }
  108. inline void setShadowCamera(const Camera* camera) { this->shadowCamera = camera; }
  109. private:
  110. bool loadShader(const RenderOperation& operation);
  111. ShaderParameterSet parameterSet;
  112. const ShaderParameter* modelParam;
  113. const ShaderParameter* modelViewParam;
  114. const ShaderParameter* modelViewProjectionParam;
  115. const ShaderParameter* normalModelViewParam;
  116. const ShaderParameter* normalModelParam;
  117. const ShaderParameter* cameraPositionParam;
  118. const ShaderParameter* directionalLightCountParam;
  119. const ShaderParameter* directionalLightColorsParam;
  120. const ShaderParameter* directionalLightDirectionsParam;
  121. const ShaderParameter* albedoOpacityMapParam;
  122. const ShaderParameter* metalnessRoughnessMapParam;
  123. const ShaderParameter* normalOcclusionMapParam;
  124. const ShaderParameter* diffuseCubemapParam;
  125. const ShaderParameter* specularCubemapParam;
  126. ShaderLoader shaderLoader;
  127. std::map<std::size_t, Shader*> shaderCache;
  128. Shader* lightingShader;
  129. Matrix4 biasMatrix;
  130. GLuint shadowMap;
  131. Texture* treeShadow;
  132. Texture* diffuseCubemap;
  133. Texture* specularCubemap;
  134. const Camera* shadowCamera;
  135. float time;
  136. };
  137. /**
  138. * Renders bounding boxes, skeletons
  139. */
  140. class DebugRenderPass: public RenderPass
  141. {
  142. public:
  143. DebugRenderPass();
  144. virtual bool load(const RenderContext* renderContext);
  145. virtual void unload();
  146. virtual void render(const RenderContext* renderContext);
  147. //void setDrawBounds(bool enabled);
  148. //void setDrawSkeletons(bool enabled);
  149. //void setDrawCameras(bool enabled);
  150. //void setDrawLights(bool enabled);
  151. private:
  152. ShaderParameterSet parameterSet;
  153. const ShaderParameter* modelViewProjectionParam;
  154. ShaderLoader shaderLoader;
  155. Shader* unlitSolidShader;
  156. int aabbVertexCount;
  157. int aabbIndexCount;
  158. GLuint aabbVAO;
  159. GLuint aabbVBO;
  160. GLuint aabbIBO;
  161. };
  162. /**
  163. * Renders the user interface
  164. */
  165. class UIRenderPass: public RenderPass
  166. {
  167. public:
  168. UIRenderPass();
  169. virtual bool load(const RenderContext* renderContext);
  170. virtual void unload();
  171. virtual void render(const RenderContext* renderContext);
  172. private:
  173. ShaderParameterSet parameterSet;
  174. const ShaderParameter* modelViewProjectionParam;
  175. const ShaderParameter* textureParam;
  176. const ShaderParameter* texcoordOffsetParam;
  177. const ShaderParameter* texcoordScaleParam;
  178. ShaderLoader shaderLoader;
  179. Shader* texturedUIShader;
  180. Shader* untexturedUIShader;
  181. };
  182. /**
  183. * Renders a vignette
  184. */
  185. class VignetteRenderPass: public RenderPass
  186. {
  187. public:
  188. VignetteRenderPass();
  189. virtual bool load(const RenderContext* renderContext);
  190. virtual void unload();
  191. virtual void render(const RenderContext* renderContext);
  192. private:
  193. ShaderParameterSet parameterSet;
  194. const ShaderParameter* modelViewProjectionParam;
  195. const ShaderParameter* bayerTextureParam;
  196. ShaderLoader shaderLoader;
  197. Shader* shader;
  198. GLuint bayerTextureID;
  199. };
  200. /**
  201. * Renders a skybox
  202. */
  203. class SkyboxRenderPass: public RenderPass
  204. {
  205. public:
  206. SkyboxRenderPass();
  207. inline void setCubemap(Texture* cubemap) { this->cubemap = cubemap; }
  208. virtual bool load(const RenderContext* renderContext);
  209. virtual void unload();
  210. virtual void render(const RenderContext* renderContext);
  211. private:
  212. ShaderParameterSet parameterSet;
  213. const ShaderParameter* matrixParam;
  214. const ShaderParameter* cubemapParam;
  215. ShaderLoader shaderLoader;
  216. Shader* shader;
  217. Texture* cubemap;
  218. int quadVertexCount;
  219. int quadIndexCount;
  220. GLuint quadVAO;
  221. GLuint quadVBO;
  222. GLuint quadIBO;
  223. };
  224. #endif // RENDER_PASSES_HPP